Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 | 3x 3x 3x 31x 31x 43x 3x 3x 3x 3x 4x 4x 10x 10x 10x 10x 3x 3x 10x 10x 31x 3x 3x 3x 3x 3x 3x 3x 24x 3x 3x 3x 3x 3x 3x 3x 3x 7x 3x 4x 4x 4x 4x 4x 4x 4x 9x 4x 10x 10x 10x 10x 10x 2x 10x 10x 10x 10x 10x 10x 10x 3x 3x 3x 3x 3x 3x 3x 3x 3x 10x 10x 10x 31x 31x 31x 31x | /**
* Parse C-Next source and extract symbols for IDE features
* ADR-055 Phase 7: Direct TSymbol → ISymbolInfo conversion (no ISymbol intermediate)
*/
import CNextSourceParser from "../transpiler/logic/parser/CNextSourceParser";
import CNextResolver from "../transpiler/logic/symbols/cnext/index";
import SymbolNameUtils from "../transpiler/logic/symbols/cnext/utils/SymbolNameUtils";
import TypeResolver from "../utils/TypeResolver";
import ISymbolInfo from "./types/ISymbolInfo";
import IParseWithSymbolsResult from "./types/IParseWithSymbolsResult";
import TSymbol from "../transpiler/types/symbols/TSymbol";
import SymbolPathUtils from "./utils/SymbolPathUtils";
// Re-export helpers for use in this module
const buildScopePath = SymbolPathUtils.buildScopePath;
const getDotPathId = SymbolPathUtils.getDotPathId;
const getParentId = SymbolPathUtils.getParentId;
/**
* ADR-055 Phase 7: Convert TSymbol directly to ISymbolInfo array.
* Expands compound symbols (bitmaps, enums, structs, registers) into multiple ISymbolInfo entries.
*/
function convertTSymbolsToISymbolInfo(symbols: TSymbol[]): ISymbolInfo[] {
const result: ISymbolInfo[] = [];
for (const symbol of symbols) {
switch (symbol.kind) {
case "bitmap":
result.push(...convertBitmap(symbol));
break;
case "enum":
result.push(...convertEnum(symbol));
break;
case "struct":
result.push(...convertStruct(symbol));
break;
case "function":
result.push(...convertFunction(symbol));
break;
case "variable":
result.push(convertVariable(symbol));
break;
case "register":
result.push(...convertRegister(symbol));
break;
case "scope":
result.push(convertScope(symbol));
break;
}
}
return result;
}
function convertBitmap(
bitmap: import("../transpiler/types/symbols/IBitmapSymbol").default,
): ISymbolInfo[] {
const result: ISymbolInfo[] = [];
const cName = SymbolNameUtils.getTranspiledCName(bitmap);
const parent = bitmap.scope.name || undefined;
const bitmapId = getDotPathId(bitmap);
const bitmapParentId = getParentId(bitmap.scope);
result.push({
name: bitmap.name,
fullName: cName,
kind: "bitmap",
type: bitmap.backingType,
parent,
id: bitmapId,
parentId: bitmapParentId,
line: bitmap.sourceLine,
});
// Add bitmap fields
for (const [fieldName, fieldInfo] of bitmap.fields) {
result.push({
name: fieldName,
fullName: `${cName}.${fieldName}`,
kind: "bitmapField",
parent: cName,
id: `${bitmapId}.${fieldName}`,
parentId: bitmapId,
line: bitmap.sourceLine,
size: fieldInfo.width,
});
}
return result;
}
function convertEnum(
enumSym: import("../transpiler/types/symbols/IEnumSymbol").default,
): ISymbolInfo[] {
const result: ISymbolInfo[] = [];
const cName = SymbolNameUtils.getTranspiledCName(enumSym);
const parent = enumSym.scope.name || undefined;
const enumId = getDotPathId(enumSym);
const enumParentId = getParentId(enumSym.scope);
result.push({
name: enumSym.name,
fullName: cName,
kind: "enum",
parent,
id: enumId,
parentId: enumParentId,
line: enumSym.sourceLine,
});
// Add enum members
for (const [memberName] of enumSym.members) {
result.push({
name: memberName,
fullName: `${cName}_${memberName}`,
kind: "enumMember",
parent: cName,
id: `${enumId}.${memberName}`,
parentId: enumId,
line: enumSym.sourceLine,
});
}
return result;
}
function convertStruct(
struct: import("../transpiler/types/symbols/IStructSymbol").default,
): ISymbolInfo[] {
const result: ISymbolInfo[] = [];
const cName = SymbolNameUtils.getTranspiledCName(struct);
const parent = struct.scope.name || undefined;
const structId = getDotPathId(struct);
const structParentId = getParentId(struct.scope);
result.push({
name: struct.name,
fullName: cName,
kind: "struct",
parent,
id: structId,
parentId: structParentId,
line: struct.sourceLine,
});
// Add struct fields
for (const [fieldName, fieldInfo] of struct.fields) {
result.push({
name: fieldName,
fullName: `${cName}.${fieldName}`,
kind: "field",
type: TypeResolver.getTypeName(fieldInfo.type),
parent: cName,
id: `${structId}.${fieldName}`,
parentId: structId,
line: struct.sourceLine,
});
}
return result;
}
function convertFunction(
func: import("../transpiler/types/symbols/IFunctionSymbol").default,
): ISymbolInfo[] {
const result: ISymbolInfo[] = [];
const cName = SymbolNameUtils.getTranspiledCName(func);
const parent = func.scope.name || undefined;
const returnType = TypeResolver.getTypeName(func.returnType);
// Build signature
const paramTypes = func.parameters.map((p) =>
TypeResolver.getTypeName(p.type),
);
const signature = `${returnType} ${cName}(${paramTypes.join(", ")})`;
result.push({
name: func.name,
fullName: cName,
kind: "function",
type: returnType,
parent,
id: getDotPathId(func),
parentId: getParentId(func.scope),
signature,
accessModifier: func.isExported ? "public" : "private",
line: func.sourceLine,
});
return result;
}
function convertVariable(
variable: import("../transpiler/types/symbols/IVariableSymbol").default,
): ISymbolInfo {
const cName = SymbolNameUtils.getTranspiledCName(variable);
const parent = variable.scope.name || undefined;
const typeStr = TypeResolver.getTypeName(variable.type);
return {
name: variable.name,
fullName: cName,
kind: "variable",
type: typeStr,
parent,
id: getDotPathId(variable),
parentId: getParentId(variable.scope),
line: variable.sourceLine,
};
}
function convertRegister(
register: import("../transpiler/types/symbols/IRegisterSymbol").default,
): ISymbolInfo[] {
const result: ISymbolInfo[] = [];
const cName = SymbolNameUtils.getTranspiledCName(register);
const parent = register.scope.name || undefined;
const registerId = getDotPathId(register);
const registerParentId = getParentId(register.scope);
result.push({
name: register.name,
fullName: cName,
kind: "register",
parent,
id: registerId,
parentId: registerParentId,
line: register.sourceLine,
});
// Add register members
for (const [memberName, memberInfo] of register.members) {
result.push({
name: memberName,
fullName: `${cName}.${memberName}`,
kind: "registerMember",
parent: cName,
id: `${registerId}.${memberName}`,
parentId: registerId,
accessModifier: memberInfo.access,
line: register.sourceLine,
});
}
return result;
}
function convertScope(
scope: import("../transpiler/types/symbols/IScopeSymbol").default,
): ISymbolInfo {
const scopeId = buildScopePath(scope);
const scopeParentId =
scope.parent && scope.parent.name !== ""
? buildScopePath(scope.parent)
: undefined;
return {
name: scope.name,
fullName: scope.name,
kind: "namespace",
id: scopeId,
parentId: scopeParentId,
line: scope.sourceLine,
};
}
/**
* Parse C-Next source and extract symbols for IDE features
*
* Unlike transpile(), this function attempts to extract symbols even when
* there are parse errors, making it suitable for autocomplete during typing.
*
* @param source - C-Next source code string
* @returns Parse result with symbols
*
* @example
* ```typescript
* import parseWithSymbols from './lib/parseWithSymbols';
*
* const result = parseWithSymbols(source);
* // Find namespace members for autocomplete
* const ledMembers = result.symbols.filter(s => s.parent === 'LED');
* ```
*/
function parseWithSymbols(source: string): IParseWithSymbolsResult {
// Parse C-Next source
const { tree, errors } = CNextSourceParser.parse(source);
// ADR-055 Phase 7: Direct TSymbol → ISymbolInfo conversion (no ISymbol intermediate)
const tSymbols = CNextResolver.resolve(tree, "<source>");
const symbols = convertTSymbolsToISymbolInfo(tSymbols);
return {
success: errors.length === 0,
errors,
symbols,
};
}
export default parseWithSymbols;
|