Skip to content

Commit

Permalink
fix: Simplified the AST for new expressions
Browse files Browse the repository at this point in the history
  • Loading branch information
robertoraggi committed Oct 7, 2023
1 parent 6d3e873 commit 422729a
Show file tree
Hide file tree
Showing 28 changed files with 666 additions and 1,105 deletions.
134 changes: 39 additions & 95 deletions packages/cxx-frontend/src/AST.ts
Original file line number Diff line number Diff line change
Expand Up @@ -648,94 +648,6 @@ export class BaseClauseAST extends AST {
}
}

/**
* NewDeclaratorAST node.
*/
export class NewDeclaratorAST extends AST {
/**
* Traverse this node using the given visitor.
* @param visitor the visitor.
* @param context the context.
* @returns the result of the visit.
*/
accept<Context, Result>(
visitor: ASTVisitor<Context, Result>,
context: Context,
): Result {
return visitor.visitNewDeclarator(this, context);
}

/**
* Returns the ptrOpList of this node
*/
*getPtrOpList(): Generator<PtrOperatorAST | undefined> {
for (
let it = cxx.getASTSlot(this.getHandle(), 0);
it;
it = cxx.getListNext(it)
) {
yield AST.from<PtrOperatorAST>(cxx.getListValue(it), this.parser);
}
}

/**
* Returns the declaratorChunkList of this node
*/
*getDeclaratorChunkList(): Generator<ArrayDeclaratorChunkAST | undefined> {
for (
let it = cxx.getASTSlot(this.getHandle(), 1);
it;
it = cxx.getListNext(it)
) {
yield AST.from<ArrayDeclaratorChunkAST>(
cxx.getListValue(it),
this.parser,
);
}
}
}

/**
* NewTypeIdAST node.
*/
export class NewTypeIdAST extends AST {
/**
* Traverse this node using the given visitor.
* @param visitor the visitor.
* @param context the context.
* @returns the result of the visit.
*/
accept<Context, Result>(
visitor: ASTVisitor<Context, Result>,
context: Context,
): Result {
return visitor.visitNewTypeId(this, context);
}

/**
* Returns the typeSpecifierList of this node
*/
*getTypeSpecifierList(): Generator<SpecifierAST | undefined> {
for (
let it = cxx.getASTSlot(this.getHandle(), 0);
it;
it = cxx.getListNext(it)
) {
yield AST.from<SpecifierAST>(cxx.getListValue(it), this.parser);
}
}

/**
* Returns the newDeclarator of this node
*/
getNewDeclarator(): NewDeclaratorAST | undefined {
return AST.from<NewDeclaratorAST>(
cxx.getASTSlot(this.getHandle(), 1),
this.parser,
);
}
}

/**
* RequiresClauseAST node.
*/
Expand Down Expand Up @@ -4149,21 +4061,48 @@ export class NewExpressionAST extends ExpressionAST {
}

/**
* Returns the typeId of this node
* Returns the location of the lparen token in this node
*/
getTypeId(): NewTypeIdAST | undefined {
return AST.from<NewTypeIdAST>(
cxx.getASTSlot(this.getHandle(), 3),
getLparenToken(): Token | undefined {
return Token.from(cxx.getASTSlot(this.getHandle(), 3), this.parser);
}

/**
* Returns the typeSpecifierList of this node
*/
*getTypeSpecifierList(): Generator<SpecifierAST | undefined> {
for (
let it = cxx.getASTSlot(this.getHandle(), 4);
it;
it = cxx.getListNext(it)
) {
yield AST.from<SpecifierAST>(cxx.getListValue(it), this.parser);
}
}

/**
* Returns the declarator of this node
*/
getDeclarator(): DeclaratorAST | undefined {
return AST.from<DeclaratorAST>(
cxx.getASTSlot(this.getHandle(), 5),
this.parser,
);
}

/**
* Returns the location of the rparen token in this node
*/
getRparenToken(): Token | undefined {
return Token.from(cxx.getASTSlot(this.getHandle(), 6), this.parser);
}

/**
* Returns the newInitalizer of this node
*/
getNewInitalizer(): NewInitializerAST | undefined {
return AST.from<NewInitializerAST>(
cxx.getASTSlot(this.getHandle(), 4),
cxx.getASTSlot(this.getHandle(), 7),
this.parser,
);
}
Expand Down Expand Up @@ -8615,6 +8554,13 @@ export class TypenameTypeParameterAST extends TemplateParameterAST {
const slot = cxx.getASTSlot(this.getHandle(), 5);
return cxx.getIdentifierValue(slot);
}

/**
* Returns the isPack attribute of this node
*/
getIsPack(): boolean {
return cxx.getASTSlot(this.getHandle(), 6) !== 0;
}
}

/**
Expand Down Expand Up @@ -11141,8 +11087,6 @@ const AST_CONSTRUCTORS: Array<
InitDeclaratorAST,
BaseSpecifierAST,
BaseClauseAST,
NewDeclaratorAST,
NewTypeIdAST,
RequiresClauseAST,
ParameterDeclarationClauseAST,
ParametersAndQualifiersAST,
Expand Down
2 changes: 0 additions & 2 deletions packages/cxx-frontend/src/ASTKind.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ export enum ASTKind {
InitDeclarator,
BaseSpecifier,
BaseClause,
NewDeclarator,
NewTypeId,
RequiresClause,
ParameterDeclarationClause,
ParametersAndQualifiers,
Expand Down
165 changes: 82 additions & 83 deletions packages/cxx-frontend/src/ASTSlot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,87 +165,86 @@ export enum ASTSlot {
namespaceLoc = 143,
nestedNameSpecifier = 144,
nestedNamespaceSpecifierList = 145,
newDeclarator = 146,
newInitalizer = 147,
newLoc = 148,
newPlacement = 149,
noexceptLoc = 150,
op = 151,
opLoc = 152,
openLoc = 153,
operatorFunctionId = 154,
operatorLoc = 155,
outputOperandList = 156,
parameterDeclarationClause = 157,
parameterDeclarationList = 158,
parametersAndQualifiers = 159,
privateLoc = 160,
privateModuleFragment = 161,
ptrOpList = 162,
qualifier = 163,
qualifierLoc = 164,
questionLoc = 165,
rangeDeclaration = 166,
rangeInitializer = 167,
rbraceLoc = 168,
rbracket2Loc = 169,
rbracketLoc = 170,
refLoc = 171,
refOp = 172,
refQualifierLoc = 173,
requirementBody = 174,
requirementList = 175,
requiresClause = 176,
requiresLoc = 177,
restrictLoc = 178,
returnLoc = 179,
rightExpression = 180,
rparen2Loc = 181,
rparenLoc = 182,
scopeLoc = 183,
semicolonLoc = 184,
sizeExpression = 185,
sizeofLoc = 186,
specifier = 187,
specifierLoc = 188,
starLoc = 189,
statement = 190,
statementList = 191,
staticAssertLoc = 192,
staticLoc = 193,
stringLiteral = 194,
stringliteralLoc = 195,
switchLoc = 196,
symbolicName = 197,
symbolicNameLoc = 198,
templateArgumentList = 199,
templateId = 200,
templateLoc = 201,
templateParameterList = 202,
thisLoc = 203,
threadLoc = 204,
threadLocalLoc = 205,
throwLoc = 206,
tildeLoc = 207,
trailingReturnType = 208,
tryLoc = 209,
typeConstraint = 210,
typeId = 211,
typeIdList = 212,
typeSpecifier = 213,
typeSpecifierList = 214,
typeTraits = 215,
typeTraitsLoc = 216,
typedefLoc = 217,
typeidLoc = 218,
typenameLoc = 219,
underlyingTypeLoc = 220,
unqualifiedId = 221,
usingDeclaratorList = 222,
usingLoc = 223,
virtualLoc = 224,
voidLoc = 225,
volatileLoc = 226,
whileLoc = 227,
yieldLoc = 228,
newInitalizer = 146,
newLoc = 147,
newPlacement = 148,
noexceptLoc = 149,
op = 150,
opLoc = 151,
openLoc = 152,
operatorFunctionId = 153,
operatorLoc = 154,
outputOperandList = 155,
parameterDeclarationClause = 156,
parameterDeclarationList = 157,
parametersAndQualifiers = 158,
privateLoc = 159,
privateModuleFragment = 160,
ptrOpList = 161,
qualifier = 162,
qualifierLoc = 163,
questionLoc = 164,
rangeDeclaration = 165,
rangeInitializer = 166,
rbraceLoc = 167,
rbracket2Loc = 168,
rbracketLoc = 169,
refLoc = 170,
refOp = 171,
refQualifierLoc = 172,
requirementBody = 173,
requirementList = 174,
requiresClause = 175,
requiresLoc = 176,
restrictLoc = 177,
returnLoc = 178,
rightExpression = 179,
rparen2Loc = 180,
rparenLoc = 181,
scopeLoc = 182,
semicolonLoc = 183,
sizeExpression = 184,
sizeofLoc = 185,
specifier = 186,
specifierLoc = 187,
starLoc = 188,
statement = 189,
statementList = 190,
staticAssertLoc = 191,
staticLoc = 192,
stringLiteral = 193,
stringliteralLoc = 194,
switchLoc = 195,
symbolicName = 196,
symbolicNameLoc = 197,
templateArgumentList = 198,
templateId = 199,
templateLoc = 200,
templateParameterList = 201,
thisLoc = 202,
threadLoc = 203,
threadLocalLoc = 204,
throwLoc = 205,
tildeLoc = 206,
trailingReturnType = 207,
tryLoc = 208,
typeConstraint = 209,
typeId = 210,
typeIdList = 211,
typeSpecifier = 212,
typeSpecifierList = 213,
typeTraits = 214,
typeTraitsLoc = 215,
typedefLoc = 216,
typeidLoc = 217,
typenameLoc = 218,
underlyingTypeLoc = 219,
unqualifiedId = 220,
usingDeclaratorList = 221,
usingLoc = 222,
virtualLoc = 223,
voidLoc = 224,
volatileLoc = 225,
whileLoc = 226,
yieldLoc = 227,
}
21 changes: 0 additions & 21 deletions packages/cxx-frontend/src/ASTVisitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,27 +118,6 @@ export abstract class ASTVisitor<Context, Result> {
*/
abstract visitBaseClause(node: ast.BaseClauseAST, context: Context): Result;

/**
* Visit NewDeclarator node.
*
* @param node The node to visit.
* @param context The context.
* @returns The result of the visit.
*/
abstract visitNewDeclarator(
node: ast.NewDeclaratorAST,
context: Context,
): Result;

/**
* Visit NewTypeId node.
*
* @param node The node to visit.
* @param context The context.
* @returns The result of the visit.
*/
abstract visitNewTypeId(node: ast.NewTypeIdAST, context: Context): Result;

/**
* Visit RequiresClause node.
*
Expand Down

0 comments on commit 422729a

Please sign in to comment.