Skip to content

Commit 658afb7

Browse files
committed
fix: Expose the AST attributes to the JS API
1 parent 51d0e8f commit 658afb7

File tree

8 files changed

+395
-40
lines changed

8 files changed

+395
-40
lines changed

Diff for: packages/cxx-frontend/src/AST.ts

+141-2
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,10 @@ export class EnumeratorAST extends AST {
191191
getExpression(): ExpressionAST | undefined {
192192
return AST.from<ExpressionAST>(cxx.getASTSlot(this.getHandle(), 3), this.parser);
193193
}
194+
getIdentifier(): string | undefined {
195+
const slot = cxx.getASTSlot(this.getHandle(), 4);
196+
return cxx.getIdentifierValue(slot);
197+
}
194198
}
195199

196200
export class DeclaratorAST extends AST {
@@ -239,6 +243,9 @@ export class BaseSpecifierAST extends AST {
239243
getName(): NameAST | undefined {
240244
return AST.from<NameAST>(cxx.getASTSlot(this.getHandle(), 1), this.parser);
241245
}
246+
getIsVirtual(): boolean {
247+
return cxx.getASTSlot(this.getHandle(), 2) !== 0;
248+
}
242249
}
243250

244251
export class BaseClauseAST extends AST {
@@ -312,6 +319,9 @@ export class ParameterDeclarationClauseAST extends AST {
312319
getEllipsisToken(): Token | undefined {
313320
return Token.from(cxx.getASTSlot(this.getHandle(), 2), this.parser);
314321
}
322+
getIsVariadic(): boolean {
323+
return cxx.getASTSlot(this.getHandle(), 3) !== 0;
324+
}
315325
}
316326

317327
export class ParametersAndQualifiersAST extends AST {
@@ -605,6 +615,10 @@ export class DesignatorAST extends AST {
605615
getIdentifierToken(): Token | undefined {
606616
return Token.from(cxx.getASTSlot(this.getHandle(), 1), this.parser);
607617
}
618+
getIdentifier(): string | undefined {
619+
const slot = cxx.getASTSlot(this.getHandle(), 2);
620+
return cxx.getIdentifierValue(slot);
621+
}
608622
}
609623

610624
export class NewPlacementAST extends AST {
@@ -697,6 +711,10 @@ export class CharLiteralExpressionAST extends ExpressionAST {
697711
getLiteralToken(): Token | undefined {
698712
return Token.from(cxx.getASTSlot(this.getHandle(), 0), this.parser);
699713
}
714+
getLiteral(): string | undefined {
715+
const slot = cxx.getASTSlot(this.getHandle(), 1);
716+
return cxx.getLiteralValue(slot);
717+
}
700718
}
701719

702720
export class BoolLiteralExpressionAST extends ExpressionAST {
@@ -706,6 +724,9 @@ export class BoolLiteralExpressionAST extends ExpressionAST {
706724
getLiteralToken(): Token | undefined {
707725
return Token.from(cxx.getASTSlot(this.getHandle(), 0), this.parser);
708726
}
727+
getIsTrue(): boolean {
728+
return cxx.getASTSlot(this.getHandle(), 1) !== 0;
729+
}
709730
}
710731

711732
export class IntLiteralExpressionAST extends ExpressionAST {
@@ -715,6 +736,10 @@ export class IntLiteralExpressionAST extends ExpressionAST {
715736
getLiteralToken(): Token | undefined {
716737
return Token.from(cxx.getASTSlot(this.getHandle(), 0), this.parser);
717738
}
739+
getLiteral(): string | undefined {
740+
const slot = cxx.getASTSlot(this.getHandle(), 1);
741+
return cxx.getLiteralValue(slot);
742+
}
718743
}
719744

720745
export class FloatLiteralExpressionAST extends ExpressionAST {
@@ -724,6 +749,10 @@ export class FloatLiteralExpressionAST extends ExpressionAST {
724749
getLiteralToken(): Token | undefined {
725750
return Token.from(cxx.getASTSlot(this.getHandle(), 0), this.parser);
726751
}
752+
getLiteral(): string | undefined {
753+
const slot = cxx.getASTSlot(this.getHandle(), 1);
754+
return cxx.getLiteralValue(slot);
755+
}
727756
}
728757

729758
export class NullptrLiteralExpressionAST extends ExpressionAST {
@@ -742,6 +771,10 @@ export class StringLiteralExpressionAST extends ExpressionAST {
742771
getLiteralToken(): Token | undefined {
743772
return Token.from(cxx.getASTSlot(this.getHandle(), 0), this.parser);
744773
}
774+
getLiteral(): string | undefined {
775+
const slot = cxx.getASTSlot(this.getHandle(), 1);
776+
return cxx.getLiteralValue(slot);
777+
}
745778
}
746779

747780
export class UserDefinedStringLiteralExpressionAST extends ExpressionAST {
@@ -751,6 +784,10 @@ export class UserDefinedStringLiteralExpressionAST extends ExpressionAST {
751784
getLiteralToken(): Token | undefined {
752785
return Token.from(cxx.getASTSlot(this.getHandle(), 0), this.parser);
753786
}
787+
getLiteral(): string | undefined {
788+
const slot = cxx.getASTSlot(this.getHandle(), 1);
789+
return cxx.getLiteralValue(slot);
790+
}
754791
}
755792

756793
export class IdExpressionAST extends ExpressionAST {
@@ -945,6 +982,10 @@ export class SizeofPackExpressionAST extends ExpressionAST {
945982
getRparenToken(): Token | undefined {
946983
return Token.from(cxx.getASTSlot(this.getHandle(), 4), this.parser);
947984
}
985+
getIdentifier(): string | undefined {
986+
const slot = cxx.getASTSlot(this.getHandle(), 5);
987+
return cxx.getIdentifierValue(slot);
988+
}
948989
}
949990

950991
export class TypeidExpressionAST extends ExpressionAST {
@@ -1542,6 +1583,10 @@ export class SimpleLambdaCaptureAST extends LambdaCaptureAST {
15421583
getEllipsisToken(): Token | undefined {
15431584
return Token.from(cxx.getASTSlot(this.getHandle(), 1), this.parser);
15441585
}
1586+
getIdentifier(): string | undefined {
1587+
const slot = cxx.getASTSlot(this.getHandle(), 2);
1588+
return cxx.getIdentifierValue(slot);
1589+
}
15451590
}
15461591

15471592
export class RefLambdaCaptureAST extends LambdaCaptureAST {
@@ -1557,6 +1602,10 @@ export class RefLambdaCaptureAST extends LambdaCaptureAST {
15571602
getEllipsisToken(): Token | undefined {
15581603
return Token.from(cxx.getASTSlot(this.getHandle(), 2), this.parser);
15591604
}
1605+
getIdentifier(): string | undefined {
1606+
const slot = cxx.getASTSlot(this.getHandle(), 3);
1607+
return cxx.getIdentifierValue(slot);
1608+
}
15601609
}
15611610

15621611
export class RefInitLambdaCaptureAST extends LambdaCaptureAST {
@@ -1575,6 +1624,10 @@ export class RefInitLambdaCaptureAST extends LambdaCaptureAST {
15751624
getInitializer(): ExpressionAST | undefined {
15761625
return AST.from<ExpressionAST>(cxx.getASTSlot(this.getHandle(), 3), this.parser);
15771626
}
1627+
getIdentifier(): string | undefined {
1628+
const slot = cxx.getASTSlot(this.getHandle(), 4);
1629+
return cxx.getIdentifierValue(slot);
1630+
}
15781631
}
15791632

15801633
export class InitLambdaCaptureAST extends LambdaCaptureAST {
@@ -1590,6 +1643,10 @@ export class InitLambdaCaptureAST extends LambdaCaptureAST {
15901643
getInitializer(): ExpressionAST | undefined {
15911644
return AST.from<ExpressionAST>(cxx.getASTSlot(this.getHandle(), 2), this.parser);
15921645
}
1646+
getIdentifier(): string | undefined {
1647+
const slot = cxx.getASTSlot(this.getHandle(), 3);
1648+
return cxx.getIdentifierValue(slot);
1649+
}
15931650
}
15941651

15951652
export class NewParenInitializerAST extends NewInitializerAST {
@@ -1752,6 +1809,10 @@ export class LabeledStatementAST extends StatementAST {
17521809
getStatement(): StatementAST | undefined {
17531810
return AST.from<StatementAST>(cxx.getASTSlot(this.getHandle(), 2), this.parser);
17541811
}
1812+
getIdentifier(): string | undefined {
1813+
const slot = cxx.getASTSlot(this.getHandle(), 3);
1814+
return cxx.getIdentifierValue(slot);
1815+
}
17551816
}
17561817

17571818
export class CaseStatementAST extends StatementAST {
@@ -2030,6 +2091,10 @@ export class GotoStatementAST extends StatementAST {
20302091
getSemicolonToken(): Token | undefined {
20312092
return Token.from(cxx.getASTSlot(this.getHandle(), 2), this.parser);
20322093
}
2094+
getIdentifier(): string | undefined {
2095+
const slot = cxx.getASTSlot(this.getHandle(), 3);
2096+
return cxx.getIdentifierValue(slot);
2097+
}
20332098
}
20342099

20352100
export class CoroutineReturnStatementAST extends StatementAST {
@@ -2161,6 +2226,10 @@ export class AliasDeclarationAST extends DeclarationAST {
21612226
getSemicolonToken(): Token | undefined {
21622227
return Token.from(cxx.getASTSlot(this.getHandle(), 5), this.parser);
21632228
}
2229+
getIdentifier(): string | undefined {
2230+
const slot = cxx.getASTSlot(this.getHandle(), 6);
2231+
return cxx.getIdentifierValue(slot);
2232+
}
21642233
}
21652234

21662235
export class SimpleDeclarationAST extends DeclarationAST {
@@ -2245,11 +2314,15 @@ export class StaticAssertDeclarationAST extends DeclarationAST {
22452314
getLiteralToken(): Token | undefined {
22462315
return Token.from(cxx.getASTSlot(this.getHandle(), 4), this.parser);
22472316
}
2317+
getLiteral(): string | undefined {
2318+
const slot = cxx.getASTSlot(this.getHandle(), 5);
2319+
return cxx.getLiteralValue(slot);
2320+
}
22482321
getRparenToken(): Token | undefined {
2249-
return Token.from(cxx.getASTSlot(this.getHandle(), 5), this.parser);
2322+
return Token.from(cxx.getASTSlot(this.getHandle(), 6), this.parser);
22502323
}
22512324
getSemicolonToken(): Token | undefined {
2252-
return Token.from(cxx.getASTSlot(this.getHandle(), 6), this.parser);
2325+
return Token.from(cxx.getASTSlot(this.getHandle(), 7), this.parser);
22532326
}
22542327
}
22552328

@@ -2318,6 +2391,13 @@ export class NestedNamespaceSpecifierAST extends DeclarationAST {
23182391
getScopeToken(): Token | undefined {
23192392
return Token.from(cxx.getASTSlot(this.getHandle(), 2), this.parser);
23202393
}
2394+
getNamespaceName(): string | undefined {
2395+
const slot = cxx.getASTSlot(this.getHandle(), 3);
2396+
return cxx.getIdentifierValue(slot);
2397+
}
2398+
getIsInline(): boolean {
2399+
return cxx.getASTSlot(this.getHandle(), 4) !== 0;
2400+
}
23212401
}
23222402

23232403
export class NamespaceDefinitionAST extends DeclarationAST {
@@ -2359,6 +2439,13 @@ export class NamespaceDefinitionAST extends DeclarationAST {
23592439
getRbraceToken(): Token | undefined {
23602440
return Token.from(cxx.getASTSlot(this.getHandle(), 8), this.parser);
23612441
}
2442+
getNamespaceName(): string | undefined {
2443+
const slot = cxx.getASTSlot(this.getHandle(), 9);
2444+
return cxx.getIdentifierValue(slot);
2445+
}
2446+
getIsInline(): boolean {
2447+
return cxx.getASTSlot(this.getHandle(), 10) !== 0;
2448+
}
23622449
}
23632450

23642451
export class NamespaceAliasDefinitionAST extends DeclarationAST {
@@ -2383,6 +2470,10 @@ export class NamespaceAliasDefinitionAST extends DeclarationAST {
23832470
getSemicolonToken(): Token | undefined {
23842471
return Token.from(cxx.getASTSlot(this.getHandle(), 5), this.parser);
23852472
}
2473+
getIdentifier(): string | undefined {
2474+
const slot = cxx.getASTSlot(this.getHandle(), 6);
2475+
return cxx.getIdentifierValue(slot);
2476+
}
23862477
}
23872478

23882479
export class UsingDirectiveAST extends DeclarationAST {
@@ -2467,6 +2558,10 @@ export class AsmDeclarationAST extends DeclarationAST {
24672558
getSemicolonToken(): Token | undefined {
24682559
return Token.from(cxx.getASTSlot(this.getHandle(), 5), this.parser);
24692560
}
2561+
getLiteral(): string | undefined {
2562+
const slot = cxx.getASTSlot(this.getHandle(), 6);
2563+
return cxx.getLiteralValue(slot);
2564+
}
24702565
}
24712566

24722567
export class ExportDeclarationAST extends DeclarationAST {
@@ -2566,6 +2661,10 @@ export class TypenameTypeParameterAST extends DeclarationAST {
25662661
getTypeId(): TypeIdAST | undefined {
25672662
return AST.from<TypeIdAST>(cxx.getASTSlot(this.getHandle(), 4), this.parser);
25682663
}
2664+
getIdentifier(): string | undefined {
2665+
const slot = cxx.getASTSlot(this.getHandle(), 5);
2666+
return cxx.getIdentifierValue(slot);
2667+
}
25692668
}
25702669

25712670
export class TemplateTypeParameterAST extends DeclarationAST {
@@ -2601,6 +2700,10 @@ export class TemplateTypeParameterAST extends DeclarationAST {
26012700
getName(): NameAST | undefined {
26022701
return AST.from<NameAST>(cxx.getASTSlot(this.getHandle(), 8), this.parser);
26032702
}
2703+
getIdentifier(): string | undefined {
2704+
const slot = cxx.getASTSlot(this.getHandle(), 9);
2705+
return cxx.getIdentifierValue(slot);
2706+
}
26042707
}
26052708

26062709
export class TemplatePackTypeParameterAST extends DeclarationAST {
@@ -2630,6 +2733,10 @@ export class TemplatePackTypeParameterAST extends DeclarationAST {
26302733
getIdentifierToken(): Token | undefined {
26312734
return Token.from(cxx.getASTSlot(this.getHandle(), 6), this.parser);
26322735
}
2736+
getIdentifier(): string | undefined {
2737+
const slot = cxx.getASTSlot(this.getHandle(), 7);
2738+
return cxx.getIdentifierValue(slot);
2739+
}
26332740
}
26342741

26352742
export class DeductionGuideAST extends DeclarationAST {
@@ -2660,6 +2767,10 @@ export class DeductionGuideAST extends DeclarationAST {
26602767
getSemicolonToken(): Token | undefined {
26612768
return Token.from(cxx.getASTSlot(this.getHandle(), 7), this.parser);
26622769
}
2770+
getIdentifier(): string | undefined {
2771+
const slot = cxx.getASTSlot(this.getHandle(), 8);
2772+
return cxx.getIdentifierValue(slot);
2773+
}
26632774
}
26642775

26652776
export class ExplicitInstantiationAST extends DeclarationAST {
@@ -2723,6 +2834,10 @@ export class LinkageSpecificationAST extends DeclarationAST {
27232834
getRbraceToken(): Token | undefined {
27242835
return Token.from(cxx.getASTSlot(this.getHandle(), 4), this.parser);
27252836
}
2837+
getStringLiteral(): string | undefined {
2838+
const slot = cxx.getASTSlot(this.getHandle(), 5);
2839+
return cxx.getLiteralValue(slot);
2840+
}
27262841
}
27272842

27282843
export class SimpleNameAST extends NameAST {
@@ -2732,6 +2847,10 @@ export class SimpleNameAST extends NameAST {
27322847
getIdentifierToken(): Token | undefined {
27332848
return Token.from(cxx.getASTSlot(this.getHandle(), 0), this.parser);
27342849
}
2850+
getIdentifier(): string | undefined {
2851+
const slot = cxx.getASTSlot(this.getHandle(), 1);
2852+
return cxx.getIdentifierValue(slot);
2853+
}
27352854
}
27362855

27372856
export class DestructorNameAST extends NameAST {
@@ -3212,6 +3331,9 @@ export class ClassSpecifierAST extends SpecifierAST {
32123331
getRbraceToken(): Token | undefined {
32133332
return Token.from(cxx.getASTSlot(this.getHandle(), 7), this.parser);
32143333
}
3334+
getIsFinal(): boolean {
3335+
return cxx.getASTSlot(this.getHandle(), 8) !== 0;
3336+
}
32153337
}
32163338

32173339
export class TypenameSpecifierAST extends SpecifierAST {
@@ -3242,6 +3364,10 @@ export class BitfieldDeclaratorAST extends CoreDeclaratorAST {
32423364
getSizeExpression(): ExpressionAST | undefined {
32433365
return AST.from<ExpressionAST>(cxx.getASTSlot(this.getHandle(), 2), this.parser);
32443366
}
3367+
getIdentifier(): string | undefined {
3368+
const slot = cxx.getASTSlot(this.getHandle(), 3);
3369+
return cxx.getIdentifierValue(slot);
3370+
}
32453371
}
32463372

32473373
export class ParameterPackAST extends CoreDeclaratorAST {
@@ -3350,6 +3476,15 @@ export class FunctionDeclaratorAST extends DeclaratorModifierAST {
33503476
getTrailingReturnType(): TrailingReturnTypeAST | undefined {
33513477
return AST.from<TrailingReturnTypeAST>(cxx.getASTSlot(this.getHandle(), 1), this.parser);
33523478
}
3479+
getIsFinal(): boolean {
3480+
return cxx.getASTSlot(this.getHandle(), 2) !== 0;
3481+
}
3482+
getIsOverride(): boolean {
3483+
return cxx.getASTSlot(this.getHandle(), 3) !== 0;
3484+
}
3485+
getIsPure(): boolean {
3486+
return cxx.getASTSlot(this.getHandle(), 4) !== 0;
3487+
}
33533488
}
33543489

33553490
export class ArrayDeclaratorAST extends DeclaratorModifierAST {
@@ -3456,6 +3591,10 @@ export class AsmAttributeAST extends AttributeSpecifierAST {
34563591
getRparenToken(): Token | undefined {
34573592
return Token.from(cxx.getASTSlot(this.getHandle(), 3), this.parser);
34583593
}
3594+
getLiteral(): string | undefined {
3595+
const slot = cxx.getASTSlot(this.getHandle(), 4);
3596+
return cxx.getLiteralValue(slot);
3597+
}
34593598
}
34603599

34613600
export class ScopedAttributeTokenAST extends AttributeTokenAST {

Diff for: packages/cxx-frontend/src/cxx.ts

+2
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,8 @@ export interface CXX {
106106
getTokenLocation(handle: number, unitHandle: number): SourceLocation;
107107
getStartLocation(handle: number, unitHandle: number): SourceLocation;
108108
getEndLocation(handle: number, unitHandle: number): SourceLocation;
109+
getLiteralValue(handle: number): string | undefined;
110+
getIdentifierValue(handle: number): string | undefined;
109111
}
110112

111113
export let cxx!: CXX

0 commit comments

Comments
 (0)