MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / typeOfText

Function typeOfText

src/resolution/pascal-scope.ts:1640–1658  ·  view source on GitHub ↗

* The class a written type names (through its aliases, see classNamed); for * an indexed value, the element of an array (`array of TFoo`, an alias of * one like `TFooDynArray = array of TFoo;`), of a generic collection * (`TObjectList `, a dictionary's value) or what a class's default * arr

(text: string, fromFile: string, indexed: boolean, context: ResolutionContext, depth = 0)

Source from the content-addressed store, hash-verified

1638 * array property gives.
1639 */
1640function typeOfText(text: string, fromFile: string, indexed: boolean, context: ResolutionContext, depth = 0): Node | null {
1641 // Delphi reaches a pointer's members through it (`F: ^TRec`).
1642 const t = text.trim().replace(/^\^\s*/, '');
1643 // The type's name, which a property's `read`/`write` may follow; a generic
1644 // instance's (`TList<TFoo>`) is no class the project declares by that name.
1645 const name = /^&?([A-Za-z_][\w.]*)(?![\w.]|\s*<)/.exec(t)?.[1];
1646 if (!indexed) return name ? classNamed(name, fromFile, context) : null;
1647 const element = /^(?:packed\s+)?array\s*(?:\[[^\]]*\]\s*)?of\s+&?([A-Za-z_][\w.]*)/i.exec(t)?.[1] ??
1648 /^[A-Za-z_][\w.]*\s*<\s*(?:[^<>]*,\s*)?&?([A-Za-z_][\w.]*)\s*>/.exec(t)?.[1];
1649 if (element) return classNamed(element, fromFile, context);
1650 if (!name || depth > 3) return null;
1651 for (const alias of typesNamed(name.split('.').pop()!.toLowerCase(), context)) {
1652 if (alias.kind !== 'type_alias') continue;
1653 const type = typeOfText(aliasedTypeText(alias, context), alias.filePath, true, context, depth + 1);
1654 if (type) return type;
1655 }
1656 const cls = classNamed(name, fromFile, context);
1657 return cls ? defaultPropertyType(cls, context) : null;
1658}
1659
1660/** What a class's default array property gives (`property Items[I: Integer]: TFoo …; default;`), or null. */
1661function defaultPropertyType(cls: Node, context: ResolutionContext): Node | null {

Callers 2

typeOfLinksFunction · 0.85
valueTypeOfFunction · 0.85

Calls 5

typesNamedFunction · 0.85
aliasedTypeTextFunction · 0.85
defaultPropertyTypeFunction · 0.85
classNamedFunction · 0.70
execMethod · 0.65

Tested by

no test coverage detected