Skip to content

Commit

Permalink
fix: Simplified the AST of lambda expressions
Browse files Browse the repository at this point in the history
  • Loading branch information
robertoraggi committed Oct 7, 2023
1 parent 422729a commit 56b1072
Show file tree
Hide file tree
Showing 29 changed files with 1,013 additions and 1,364 deletions.
280 changes: 111 additions & 169 deletions packages/cxx-frontend/src/AST.ts
Original file line number Diff line number Diff line change
Expand Up @@ -825,58 +825,6 @@ export class ParametersAndQualifiersAST extends AST {
}
}

/**
* LambdaIntroducerAST node.
*/
export class LambdaIntroducerAST 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.visitLambdaIntroducer(this, context);
}

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

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

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

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

/**
* LambdaSpecifierAST node.
*/
Expand Down Expand Up @@ -909,104 +857,6 @@ export class LambdaSpecifierAST extends AST {
}
}

/**
* LambdaDeclaratorAST node.
*/
export class LambdaDeclaratorAST 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.visitLambdaDeclarator(this, context);
}

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

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

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

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

/**
* Returns the exceptionSpecifier of this node
*/
getExceptionSpecifier(): ExceptionSpecifierAST | undefined {
return AST.from<ExceptionSpecifierAST>(
cxx.getASTSlot(this.getHandle(), 4),
this.parser,
);
}

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

/**
* Returns the trailingReturnType of this node
*/
getTrailingReturnType(): TrailingReturnTypeAST | undefined {
return AST.from<TrailingReturnTypeAST>(
cxx.getASTSlot(this.getHandle(), 6),
this.parser,
);
}

/**
* Returns the requiresClause of this node
*/
getRequiresClause(): RequiresClauseAST | undefined {
return AST.from<RequiresClauseAST>(
cxx.getASTSlot(this.getHandle(), 7),
this.parser,
);
}
}

/**
* TrailingReturnTypeAST node.
*/
Expand Down Expand Up @@ -2777,28 +2627,52 @@ export class LambdaExpressionAST extends ExpressionAST {
}

/**
* Returns the lambdaIntroducer of this node
* Returns the location of the lbracket token in this node
*/
getLbracketToken(): Token | undefined {
return Token.from(cxx.getASTSlot(this.getHandle(), 0), this.parser);
}

/**
* Returns the location of the captureDefault token in this node
*/
getLambdaIntroducer(): LambdaIntroducerAST | undefined {
return AST.from<LambdaIntroducerAST>(
cxx.getASTSlot(this.getHandle(), 0),
this.parser,
);
getCaptureDefaultToken(): Token | undefined {
return Token.from(cxx.getASTSlot(this.getHandle(), 1), this.parser);
}

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

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

/**
* Returns the location of the less token in this node
*/
getLessToken(): Token | undefined {
return Token.from(cxx.getASTSlot(this.getHandle(), 1), this.parser);
return Token.from(cxx.getASTSlot(this.getHandle(), 4), this.parser);
}

/**
* Returns the templateParameterList of this node
*/
*getTemplateParameterList(): Generator<TemplateParameterAST | undefined> {
for (
let it = cxx.getASTSlot(this.getHandle(), 2);
let it = cxx.getASTSlot(this.getHandle(), 5);
it;
it = cxx.getListNext(it)
) {
Expand All @@ -2810,25 +2684,95 @@ export class LambdaExpressionAST extends ExpressionAST {
* Returns the location of the greater token in this node
*/
getGreaterToken(): Token | undefined {
return Token.from(cxx.getASTSlot(this.getHandle(), 3), this.parser);
return Token.from(cxx.getASTSlot(this.getHandle(), 6), this.parser);
}

/**
* Returns the requiresClause of this node
* Returns the templateRequiresClause of this node
*/
getRequiresClause(): RequiresClauseAST | undefined {
getTemplateRequiresClause(): RequiresClauseAST | undefined {
return AST.from<RequiresClauseAST>(
cxx.getASTSlot(this.getHandle(), 4),
cxx.getASTSlot(this.getHandle(), 7),
this.parser,
);
}

/**
* Returns the lambdaDeclarator of this node
* Returns the location of the lparen token in this node
*/
getLambdaDeclarator(): LambdaDeclaratorAST | undefined {
return AST.from<LambdaDeclaratorAST>(
cxx.getASTSlot(this.getHandle(), 5),
getLparenToken(): Token | undefined {
return Token.from(cxx.getASTSlot(this.getHandle(), 8), this.parser);
}

/**
* Returns the parameterDeclarationClause of this node
*/
getParameterDeclarationClause(): ParameterDeclarationClauseAST | undefined {
return AST.from<ParameterDeclarationClauseAST>(
cxx.getASTSlot(this.getHandle(), 9),
this.parser,
);
}

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

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

/**
* Returns the exceptionSpecifier of this node
*/
getExceptionSpecifier(): ExceptionSpecifierAST | undefined {
return AST.from<ExceptionSpecifierAST>(
cxx.getASTSlot(this.getHandle(), 12),
this.parser,
);
}

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

/**
* Returns the trailingReturnType of this node
*/
getTrailingReturnType(): TrailingReturnTypeAST | undefined {
return AST.from<TrailingReturnTypeAST>(
cxx.getASTSlot(this.getHandle(), 14),
this.parser,
);
}

/**
* Returns the requiresClause of this node
*/
getRequiresClause(): RequiresClauseAST | undefined {
return AST.from<RequiresClauseAST>(
cxx.getASTSlot(this.getHandle(), 15),
this.parser,
);
}
Expand All @@ -2838,7 +2782,7 @@ export class LambdaExpressionAST extends ExpressionAST {
*/
getStatement(): CompoundStatementAST | undefined {
return AST.from<CompoundStatementAST>(
cxx.getASTSlot(this.getHandle(), 6),
cxx.getASTSlot(this.getHandle(), 16),
this.parser,
);
}
Expand Down Expand Up @@ -11090,9 +11034,7 @@ const AST_CONSTRUCTORS: Array<
RequiresClauseAST,
ParameterDeclarationClauseAST,
ParametersAndQualifiersAST,
LambdaIntroducerAST,
LambdaSpecifierAST,
LambdaDeclaratorAST,
TrailingReturnTypeAST,
CtorInitializerAST,
RequirementBodyAST,
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 @@ -32,9 +32,7 @@ export enum ASTKind {
RequiresClause,
ParameterDeclarationClause,
ParametersAndQualifiers,
LambdaIntroducer,
LambdaSpecifier,
LambdaDeclarator,
TrailingReturnType,
CtorInitializer,
RequirementBody,
Expand Down
Loading

0 comments on commit 56b1072

Please sign in to comment.