Skip to content

Commit 422729a

Browse files
committed
fix: Simplified the AST for new expressions
1 parent 6d3e873 commit 422729a

28 files changed

+666
-1105
lines changed

packages/cxx-frontend/src/AST.ts

+39-95
Original file line numberDiff line numberDiff line change
@@ -648,94 +648,6 @@ export class BaseClauseAST extends AST {
648648
}
649649
}
650650

651-
/**
652-
* NewDeclaratorAST node.
653-
*/
654-
export class NewDeclaratorAST extends AST {
655-
/**
656-
* Traverse this node using the given visitor.
657-
* @param visitor the visitor.
658-
* @param context the context.
659-
* @returns the result of the visit.
660-
*/
661-
accept<Context, Result>(
662-
visitor: ASTVisitor<Context, Result>,
663-
context: Context,
664-
): Result {
665-
return visitor.visitNewDeclarator(this, context);
666-
}
667-
668-
/**
669-
* Returns the ptrOpList of this node
670-
*/
671-
*getPtrOpList(): Generator<PtrOperatorAST | undefined> {
672-
for (
673-
let it = cxx.getASTSlot(this.getHandle(), 0);
674-
it;
675-
it = cxx.getListNext(it)
676-
) {
677-
yield AST.from<PtrOperatorAST>(cxx.getListValue(it), this.parser);
678-
}
679-
}
680-
681-
/**
682-
* Returns the declaratorChunkList of this node
683-
*/
684-
*getDeclaratorChunkList(): Generator<ArrayDeclaratorChunkAST | undefined> {
685-
for (
686-
let it = cxx.getASTSlot(this.getHandle(), 1);
687-
it;
688-
it = cxx.getListNext(it)
689-
) {
690-
yield AST.from<ArrayDeclaratorChunkAST>(
691-
cxx.getListValue(it),
692-
this.parser,
693-
);
694-
}
695-
}
696-
}
697-
698-
/**
699-
* NewTypeIdAST node.
700-
*/
701-
export class NewTypeIdAST extends AST {
702-
/**
703-
* Traverse this node using the given visitor.
704-
* @param visitor the visitor.
705-
* @param context the context.
706-
* @returns the result of the visit.
707-
*/
708-
accept<Context, Result>(
709-
visitor: ASTVisitor<Context, Result>,
710-
context: Context,
711-
): Result {
712-
return visitor.visitNewTypeId(this, context);
713-
}
714-
715-
/**
716-
* Returns the typeSpecifierList of this node
717-
*/
718-
*getTypeSpecifierList(): Generator<SpecifierAST | undefined> {
719-
for (
720-
let it = cxx.getASTSlot(this.getHandle(), 0);
721-
it;
722-
it = cxx.getListNext(it)
723-
) {
724-
yield AST.from<SpecifierAST>(cxx.getListValue(it), this.parser);
725-
}
726-
}
727-
728-
/**
729-
* Returns the newDeclarator of this node
730-
*/
731-
getNewDeclarator(): NewDeclaratorAST | undefined {
732-
return AST.from<NewDeclaratorAST>(
733-
cxx.getASTSlot(this.getHandle(), 1),
734-
this.parser,
735-
);
736-
}
737-
}
738-
739651
/**
740652
* RequiresClauseAST node.
741653
*/
@@ -4149,21 +4061,48 @@ export class NewExpressionAST extends ExpressionAST {
41494061
}
41504062

41514063
/**
4152-
* Returns the typeId of this node
4064+
* Returns the location of the lparen token in this node
41534065
*/
4154-
getTypeId(): NewTypeIdAST | undefined {
4155-
return AST.from<NewTypeIdAST>(
4156-
cxx.getASTSlot(this.getHandle(), 3),
4066+
getLparenToken(): Token | undefined {
4067+
return Token.from(cxx.getASTSlot(this.getHandle(), 3), this.parser);
4068+
}
4069+
4070+
/**
4071+
* Returns the typeSpecifierList of this node
4072+
*/
4073+
*getTypeSpecifierList(): Generator<SpecifierAST | undefined> {
4074+
for (
4075+
let it = cxx.getASTSlot(this.getHandle(), 4);
4076+
it;
4077+
it = cxx.getListNext(it)
4078+
) {
4079+
yield AST.from<SpecifierAST>(cxx.getListValue(it), this.parser);
4080+
}
4081+
}
4082+
4083+
/**
4084+
* Returns the declarator of this node
4085+
*/
4086+
getDeclarator(): DeclaratorAST | undefined {
4087+
return AST.from<DeclaratorAST>(
4088+
cxx.getASTSlot(this.getHandle(), 5),
41574089
this.parser,
41584090
);
41594091
}
41604092

4093+
/**
4094+
* Returns the location of the rparen token in this node
4095+
*/
4096+
getRparenToken(): Token | undefined {
4097+
return Token.from(cxx.getASTSlot(this.getHandle(), 6), this.parser);
4098+
}
4099+
41614100
/**
41624101
* Returns the newInitalizer of this node
41634102
*/
41644103
getNewInitalizer(): NewInitializerAST | undefined {
41654104
return AST.from<NewInitializerAST>(
4166-
cxx.getASTSlot(this.getHandle(), 4),
4105+
cxx.getASTSlot(this.getHandle(), 7),
41674106
this.parser,
41684107
);
41694108
}
@@ -8615,6 +8554,13 @@ export class TypenameTypeParameterAST extends TemplateParameterAST {
86158554
const slot = cxx.getASTSlot(this.getHandle(), 5);
86168555
return cxx.getIdentifierValue(slot);
86178556
}
8557+
8558+
/**
8559+
* Returns the isPack attribute of this node
8560+
*/
8561+
getIsPack(): boolean {
8562+
return cxx.getASTSlot(this.getHandle(), 6) !== 0;
8563+
}
86188564
}
86198565

86208566
/**
@@ -11141,8 +11087,6 @@ const AST_CONSTRUCTORS: Array<
1114111087
InitDeclaratorAST,
1114211088
BaseSpecifierAST,
1114311089
BaseClauseAST,
11144-
NewDeclaratorAST,
11145-
NewTypeIdAST,
1114611090
RequiresClauseAST,
1114711091
ParameterDeclarationClauseAST,
1114811092
ParametersAndQualifiersAST,

packages/cxx-frontend/src/ASTKind.ts

-2
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@ export enum ASTKind {
2929
InitDeclarator,
3030
BaseSpecifier,
3131
BaseClause,
32-
NewDeclarator,
33-
NewTypeId,
3432
RequiresClause,
3533
ParameterDeclarationClause,
3634
ParametersAndQualifiers,

packages/cxx-frontend/src/ASTSlot.ts

+82-83
Original file line numberDiff line numberDiff line change
@@ -165,87 +165,86 @@ export enum ASTSlot {
165165
namespaceLoc = 143,
166166
nestedNameSpecifier = 144,
167167
nestedNamespaceSpecifierList = 145,
168-
newDeclarator = 146,
169-
newInitalizer = 147,
170-
newLoc = 148,
171-
newPlacement = 149,
172-
noexceptLoc = 150,
173-
op = 151,
174-
opLoc = 152,
175-
openLoc = 153,
176-
operatorFunctionId = 154,
177-
operatorLoc = 155,
178-
outputOperandList = 156,
179-
parameterDeclarationClause = 157,
180-
parameterDeclarationList = 158,
181-
parametersAndQualifiers = 159,
182-
privateLoc = 160,
183-
privateModuleFragment = 161,
184-
ptrOpList = 162,
185-
qualifier = 163,
186-
qualifierLoc = 164,
187-
questionLoc = 165,
188-
rangeDeclaration = 166,
189-
rangeInitializer = 167,
190-
rbraceLoc = 168,
191-
rbracket2Loc = 169,
192-
rbracketLoc = 170,
193-
refLoc = 171,
194-
refOp = 172,
195-
refQualifierLoc = 173,
196-
requirementBody = 174,
197-
requirementList = 175,
198-
requiresClause = 176,
199-
requiresLoc = 177,
200-
restrictLoc = 178,
201-
returnLoc = 179,
202-
rightExpression = 180,
203-
rparen2Loc = 181,
204-
rparenLoc = 182,
205-
scopeLoc = 183,
206-
semicolonLoc = 184,
207-
sizeExpression = 185,
208-
sizeofLoc = 186,
209-
specifier = 187,
210-
specifierLoc = 188,
211-
starLoc = 189,
212-
statement = 190,
213-
statementList = 191,
214-
staticAssertLoc = 192,
215-
staticLoc = 193,
216-
stringLiteral = 194,
217-
stringliteralLoc = 195,
218-
switchLoc = 196,
219-
symbolicName = 197,
220-
symbolicNameLoc = 198,
221-
templateArgumentList = 199,
222-
templateId = 200,
223-
templateLoc = 201,
224-
templateParameterList = 202,
225-
thisLoc = 203,
226-
threadLoc = 204,
227-
threadLocalLoc = 205,
228-
throwLoc = 206,
229-
tildeLoc = 207,
230-
trailingReturnType = 208,
231-
tryLoc = 209,
232-
typeConstraint = 210,
233-
typeId = 211,
234-
typeIdList = 212,
235-
typeSpecifier = 213,
236-
typeSpecifierList = 214,
237-
typeTraits = 215,
238-
typeTraitsLoc = 216,
239-
typedefLoc = 217,
240-
typeidLoc = 218,
241-
typenameLoc = 219,
242-
underlyingTypeLoc = 220,
243-
unqualifiedId = 221,
244-
usingDeclaratorList = 222,
245-
usingLoc = 223,
246-
virtualLoc = 224,
247-
voidLoc = 225,
248-
volatileLoc = 226,
249-
whileLoc = 227,
250-
yieldLoc = 228,
168+
newInitalizer = 146,
169+
newLoc = 147,
170+
newPlacement = 148,
171+
noexceptLoc = 149,
172+
op = 150,
173+
opLoc = 151,
174+
openLoc = 152,
175+
operatorFunctionId = 153,
176+
operatorLoc = 154,
177+
outputOperandList = 155,
178+
parameterDeclarationClause = 156,
179+
parameterDeclarationList = 157,
180+
parametersAndQualifiers = 158,
181+
privateLoc = 159,
182+
privateModuleFragment = 160,
183+
ptrOpList = 161,
184+
qualifier = 162,
185+
qualifierLoc = 163,
186+
questionLoc = 164,
187+
rangeDeclaration = 165,
188+
rangeInitializer = 166,
189+
rbraceLoc = 167,
190+
rbracket2Loc = 168,
191+
rbracketLoc = 169,
192+
refLoc = 170,
193+
refOp = 171,
194+
refQualifierLoc = 172,
195+
requirementBody = 173,
196+
requirementList = 174,
197+
requiresClause = 175,
198+
requiresLoc = 176,
199+
restrictLoc = 177,
200+
returnLoc = 178,
201+
rightExpression = 179,
202+
rparen2Loc = 180,
203+
rparenLoc = 181,
204+
scopeLoc = 182,
205+
semicolonLoc = 183,
206+
sizeExpression = 184,
207+
sizeofLoc = 185,
208+
specifier = 186,
209+
specifierLoc = 187,
210+
starLoc = 188,
211+
statement = 189,
212+
statementList = 190,
213+
staticAssertLoc = 191,
214+
staticLoc = 192,
215+
stringLiteral = 193,
216+
stringliteralLoc = 194,
217+
switchLoc = 195,
218+
symbolicName = 196,
219+
symbolicNameLoc = 197,
220+
templateArgumentList = 198,
221+
templateId = 199,
222+
templateLoc = 200,
223+
templateParameterList = 201,
224+
thisLoc = 202,
225+
threadLoc = 203,
226+
threadLocalLoc = 204,
227+
throwLoc = 205,
228+
tildeLoc = 206,
229+
trailingReturnType = 207,
230+
tryLoc = 208,
231+
typeConstraint = 209,
232+
typeId = 210,
233+
typeIdList = 211,
234+
typeSpecifier = 212,
235+
typeSpecifierList = 213,
236+
typeTraits = 214,
237+
typeTraitsLoc = 215,
238+
typedefLoc = 216,
239+
typeidLoc = 217,
240+
typenameLoc = 218,
241+
underlyingTypeLoc = 219,
242+
unqualifiedId = 220,
243+
usingDeclaratorList = 221,
244+
usingLoc = 222,
245+
virtualLoc = 223,
246+
voidLoc = 224,
247+
volatileLoc = 225,
248+
whileLoc = 226,
249+
yieldLoc = 227,
251250
}

packages/cxx-frontend/src/ASTVisitor.ts

-21
Original file line numberDiff line numberDiff line change
@@ -118,27 +118,6 @@ export abstract class ASTVisitor<Context, Result> {
118118
*/
119119
abstract visitBaseClause(node: ast.BaseClauseAST, context: Context): Result;
120120

121-
/**
122-
* Visit NewDeclarator node.
123-
*
124-
* @param node The node to visit.
125-
* @param context The context.
126-
* @returns The result of the visit.
127-
*/
128-
abstract visitNewDeclarator(
129-
node: ast.NewDeclaratorAST,
130-
context: Context,
131-
): Result;
132-
133-
/**
134-
* Visit NewTypeId node.
135-
*
136-
* @param node The node to visit.
137-
* @param context The context.
138-
* @returns The result of the visit.
139-
*/
140-
abstract visitNewTypeId(node: ast.NewTypeIdAST, context: Context): Result;
141-
142121
/**
143122
* Visit RequiresClause node.
144123
*

0 commit comments

Comments
 (0)