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 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 | 3x 38x 38x 50x 5x 5x 5x 5x 5x 5x 11x 11x 10x 10x 4x 4x 10x 10x 38x 5x 5x 5x 5x 5x 5x 5x 34x 5x 5x 5x 5x 5x 5x 5x 5x 11x 5x 5x 5x 5x 5x 5x 5x 5x 12x 5x 11x 11x 11x 11x 11x 2x 11x 11x 11x 10x 10x 10x 10x 4x 4x 4x 4x 4x 4x 4x 6x 4x 10x 10x 10x 38x 38x 38x 2x 38x 38x | /**
* Parse C-Next source and extract symbols for IDE features
* ADR-055 Phase 7: Direct TSymbol → ISymbolInfo conversion (no ISymbol intermediate)
*/
import SymbolRegistry from "../PARSE/3-Declare/SymbolRegistry";
import CNextSourceParser from "../PARSE/2-Parse/CNextSourceParser";
import CNextResolver from "../PARSE/3-Declare/cnext/index";
import DeferredTypes from "../PARSE/4-Resolve/DeferredTypes";
import ScopeUtils from "../utils/ScopeUtils";
import TypeResolver from "../utils/TypeResolver";
import ISymbolInfo from "./types/ISymbolInfo";
import IParseWithSymbolsResult from "./types/IParseWithSymbolsResult";
import TSymbol from "../types/symbols/TSymbol";
import SymbolPathUtils from "./utils/SymbolPathUtils";
// Re-export helpers for use in this module
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: readonly 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("../types/symbols/IBitmapSymbol").default,
): ISymbolInfo[] {
const result: ISymbolInfo[] = [];
const cName = ScopeUtils.getTranspiledCName(bitmap);
const parent = ScopeUtils.leafOf(bitmap.scopePath) || undefined;
const bitmapId = bitmap.cnxScopedName;
const bitmapParentId = getParentId(bitmap.scopePath);
result.push({
name: bitmap.name,
fullName: cName,
kind: "bitmap",
type: bitmap.backingType,
parent,
id: bitmapId,
parentId: bitmapParentId,
line: bitmap.span.line,
});
// 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,
// #1318: the MEMBER's line, not its parent's. Members carry their own
// span now, so reporting the parent's was the consumer ignoring data
// it already had -- the same defect fixed for enum members above.
line: fieldInfo.span.line,
size: fieldInfo.width,
});
}
return result;
}
function convertEnum(
enumSym: import("../types/symbols/IEnumSymbol").default,
): ISymbolInfo[] {
const result: ISymbolInfo[] = [];
const cName = ScopeUtils.getTranspiledCName(enumSym);
const parent = ScopeUtils.leafOf(enumSym.scopePath) || undefined;
const enumId = enumSym.cnxScopedName;
const enumParentId = getParentId(enumSym.scopePath);
result.push({
name: enumSym.name,
fullName: cName,
kind: "enum",
parent,
id: enumId,
parentId: enumParentId,
line: enumSym.span.line,
});
// Add enum members
for (const [memberName, member] of enumSym.members) {
result.push({
name: memberName,
// #1318/#1285: read from the symbol that carries it. This rebuilt the
// qualified name by hand and reported `enumSym`'s line for EVERY member,
// so an IDE jumping to `EColor.BLUE` landed on `enum EColor`.
fullName: member.fullyQualifiedCName,
kind: "enumMember",
parent: cName,
id: `${enumId}.${memberName}`,
parentId: enumId,
line: member.span.line,
});
}
return result;
}
function convertStruct(
struct: import("../types/symbols/IStructSymbol").default,
): ISymbolInfo[] {
const result: ISymbolInfo[] = [];
const cName = ScopeUtils.getTranspiledCName(struct);
const parent = ScopeUtils.leafOf(struct.scopePath) || undefined;
const structId = struct.cnxScopedName;
const structParentId = getParentId(struct.scopePath);
result.push({
name: struct.name,
fullName: cName,
kind: "struct",
parent,
id: structId,
parentId: structParentId,
line: struct.span.line,
});
// 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,
// #1318: the MEMBER's line, not its parent's. Members carry their own
// span now, so reporting the parent's was the consumer ignoring data
// it already had -- the same defect fixed for enum members above.
line: fieldInfo.span.line,
});
}
return result;
}
function convertFunction(
func: import("../types/symbols/IFunctionSymbol").default,
): ISymbolInfo[] {
const result: ISymbolInfo[] = [];
const cName = ScopeUtils.getTranspiledCName(func);
const parent = ScopeUtils.leafOf(func.scopePath) || 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: func.cnxScopedName,
parentId: getParentId(func.scopePath),
signature,
accessModifier: func.visibility,
line: func.span.line,
});
return result;
}
function convertVariable(
variable: import("../types/symbols/IVariableSymbol").default,
): ISymbolInfo {
const cName = ScopeUtils.getTranspiledCName(variable);
const parent = ScopeUtils.leafOf(variable.scopePath) || undefined;
const typeStr = TypeResolver.getTypeName(variable.type);
return {
name: variable.name,
fullName: cName,
kind: "variable",
type: typeStr,
parent,
id: variable.cnxScopedName,
parentId: getParentId(variable.scopePath),
line: variable.span.line,
};
}
function convertRegister(
register: import("../types/symbols/IRegisterSymbol").default,
): ISymbolInfo[] {
const result: ISymbolInfo[] = [];
const cName = ScopeUtils.getTranspiledCName(register);
const parent = ScopeUtils.leafOf(register.scopePath) || undefined;
const registerId = register.cnxScopedName;
const registerParentId = getParentId(register.scopePath);
result.push({
name: register.name,
fullName: cName,
kind: "register",
parent,
id: registerId,
parentId: registerParentId,
line: register.span.line,
});
// 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,
// #1318: the MEMBER's line, not its parent's. Members carry their own
// span now, so reporting the parent's was the consumer ignoring data
// it already had -- the same defect fixed for enum members above.
accessModifier: memberInfo.access,
line: memberInfo.span.line,
});
}
return result;
}
function convertScope(
scope: import("../types/symbols/IScopeSymbol").default,
): ISymbolInfo {
const scopeId = ScopeUtils.pathOf(scope);
const scopeParentId = getParentId(scope.scopePath);
return {
name: scope.name,
fullName: scope.name,
kind: "namespace",
id: scopeId,
parentId: scopeParentId,
line: scope.span.line,
};
}
/**
* 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, parseErrors: errors } = CNextSourceParser.parse(source);
// ADR-055 Phase 7: Direct TSymbol → ISymbolInfo conversion (no ISymbol intermediate)
//
// #1472: both passes, because this API has the same obligation the pipeline
// does. 1.3 Declare defers a bare type name it cannot settle, and reading one
// of those as a type name throws -- so a caller that ran Declare alone would
// get an internal error on any scope that names a type bare. This entry point
// takes a single source with no include context, so the program IS this file
// and its own declared scope types are the whole-program set.
// #1378, closed by construction (#1452 box 3): this path never reset the
// global registry, so scopes from a previously parsed source leaked into the
// next call. There is no global to reset now -- each call gets its own.
const declared = CNextResolver.resolve(
tree,
"<source>",
new SymbolRegistry(),
);
// No header reaches this API, so no typedef here can be opaque (ADR-030,
// #1722): opacity is decided over the headers a program includes.
const tSymbols = DeferredTypes.settle(
declared.symbols,
(qualifiedName) => declared.declaredScopeTypes.has(qualifiedName),
() => false,
);
const symbols = convertTSymbolsToISymbolInfo(tSymbols);
return {
success: errors.length === 0,
// A fresh ARRAY, so a caller who sorts or splices what it is handed does
// not reach into 1.2's artifact. The elements are still shared -- this is
// not a deep copy and does not make the errors detached, so do not stamp
// fields onto them in place (#1445).
errors: [...errors],
symbols,
};
}
export default parseWithSymbols;
|