Skip to content

Commit 2240472

Browse files
committed
AST and initial parsing for generic selection expressions
No type checking yet, just parsing and AST generation. Related to #563
1 parent be6d91c commit 2240472

35 files changed

+1875
-766
lines changed

packages/cxx-frontend/src/AST.ts

Lines changed: 173 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ export abstract class ExceptionDeclarationAST extends AST {}
158158
export abstract class ExceptionSpecifierAST extends AST {}
159159
export abstract class ExpressionAST extends AST {}
160160
export abstract class FunctionBodyAST extends AST {}
161+
export abstract class GenericAssociationAST extends AST {}
161162
export abstract class LambdaCaptureAST extends AST {}
162163
export abstract class MemInitializerAST extends AST {}
163164
export abstract class NestedNameSpecifierAST extends AST {}
@@ -3932,6 +3933,88 @@ export class ThisExpressionAST extends ExpressionAST {
39323933
}
39333934
}
39343935

3936+
/**
3937+
* GenericSelectionExpressionAST node.
3938+
*/
3939+
export class GenericSelectionExpressionAST extends ExpressionAST {
3940+
/**
3941+
* Traverse this node using the given visitor.
3942+
* @param visitor the visitor.
3943+
* @param context the context.
3944+
* @returns the result of the visit.
3945+
*/
3946+
accept<Context, Result>(
3947+
visitor: ASTVisitor<Context, Result>,
3948+
context: Context,
3949+
): Result {
3950+
return visitor.visitGenericSelectionExpression(this, context);
3951+
}
3952+
3953+
/**
3954+
* Returns the location of the generic token in this node
3955+
*/
3956+
getGenericToken(): Token | undefined {
3957+
return Token.from(cxx.getASTSlot(this.getHandle(), 0), this.parser);
3958+
}
3959+
3960+
/**
3961+
* Returns the location of the lparen token in this node
3962+
*/
3963+
getLparenToken(): Token | undefined {
3964+
return Token.from(cxx.getASTSlot(this.getHandle(), 1), this.parser);
3965+
}
3966+
3967+
/**
3968+
* Returns the expression of this node
3969+
*/
3970+
getExpression(): ExpressionAST | undefined {
3971+
return AST.from<ExpressionAST>(
3972+
cxx.getASTSlot(this.getHandle(), 2),
3973+
this.parser,
3974+
);
3975+
}
3976+
3977+
/**
3978+
* Returns the location of the comma token in this node
3979+
*/
3980+
getCommaToken(): Token | undefined {
3981+
return Token.from(cxx.getASTSlot(this.getHandle(), 3), this.parser);
3982+
}
3983+
3984+
/**
3985+
* Returns the genericAssociationList of this node
3986+
*/
3987+
getGenericAssociationList(): Iterable<GenericAssociationAST | undefined> {
3988+
let it = cxx.getASTSlot(this.getHandle(), 0);
3989+
let value: GenericAssociationAST | undefined;
3990+
let done = false;
3991+
const p = this.parser;
3992+
function advance() {
3993+
done = it === 0;
3994+
if (done) return;
3995+
const ast = cxx.getListValue(it);
3996+
value = AST.from<GenericAssociationAST>(ast, p);
3997+
it = cxx.getListNext(it);
3998+
}
3999+
function next() {
4000+
advance();
4001+
return { done, value };
4002+
}
4003+
return {
4004+
[Symbol.iterator]() {
4005+
return { next };
4006+
},
4007+
};
4008+
}
4009+
4010+
/**
4011+
* Returns the location of the rparen token in this node
4012+
*/
4013+
getRparenToken(): Token | undefined {
4014+
return Token.from(cxx.getASTSlot(this.getHandle(), 5), this.parser);
4015+
}
4016+
}
4017+
39354018
/**
39364019
* NestedStatementExpressionAST node.
39374020
*/
@@ -6814,6 +6897,93 @@ export class ParenInitializerAST extends ExpressionAST {
68146897
}
68156898
}
68166899

6900+
/**
6901+
* DefaultGenericAssociationAST node.
6902+
*/
6903+
export class DefaultGenericAssociationAST extends GenericAssociationAST {
6904+
/**
6905+
* Traverse this node using the given visitor.
6906+
* @param visitor the visitor.
6907+
* @param context the context.
6908+
* @returns the result of the visit.
6909+
*/
6910+
accept<Context, Result>(
6911+
visitor: ASTVisitor<Context, Result>,
6912+
context: Context,
6913+
): Result {
6914+
return visitor.visitDefaultGenericAssociation(this, context);
6915+
}
6916+
6917+
/**
6918+
* Returns the location of the default token in this node
6919+
*/
6920+
getDefaultToken(): Token | undefined {
6921+
return Token.from(cxx.getASTSlot(this.getHandle(), 0), this.parser);
6922+
}
6923+
6924+
/**
6925+
* Returns the location of the colon token in this node
6926+
*/
6927+
getColonToken(): Token | undefined {
6928+
return Token.from(cxx.getASTSlot(this.getHandle(), 1), this.parser);
6929+
}
6930+
6931+
/**
6932+
* Returns the expression of this node
6933+
*/
6934+
getExpression(): ExpressionAST | undefined {
6935+
return AST.from<ExpressionAST>(
6936+
cxx.getASTSlot(this.getHandle(), 2),
6937+
this.parser,
6938+
);
6939+
}
6940+
}
6941+
6942+
/**
6943+
* TypeGenericAssociationAST node.
6944+
*/
6945+
export class TypeGenericAssociationAST extends GenericAssociationAST {
6946+
/**
6947+
* Traverse this node using the given visitor.
6948+
* @param visitor the visitor.
6949+
* @param context the context.
6950+
* @returns the result of the visit.
6951+
*/
6952+
accept<Context, Result>(
6953+
visitor: ASTVisitor<Context, Result>,
6954+
context: Context,
6955+
): Result {
6956+
return visitor.visitTypeGenericAssociation(this, context);
6957+
}
6958+
6959+
/**
6960+
* Returns the typeId of this node
6961+
*/
6962+
getTypeId(): TypeIdAST | undefined {
6963+
return AST.from<TypeIdAST>(
6964+
cxx.getASTSlot(this.getHandle(), 0),
6965+
this.parser,
6966+
);
6967+
}
6968+
6969+
/**
6970+
* Returns the location of the colon token in this node
6971+
*/
6972+
getColonToken(): Token | undefined {
6973+
return Token.from(cxx.getASTSlot(this.getHandle(), 1), this.parser);
6974+
}
6975+
6976+
/**
6977+
* Returns the expression of this node
6978+
*/
6979+
getExpression(): ExpressionAST | undefined {
6980+
return AST.from<ExpressionAST>(
6981+
cxx.getASTSlot(this.getHandle(), 2),
6982+
this.parser,
6983+
);
6984+
}
6985+
}
6986+
68176987
/**
68186988
* DotDesignatorAST node.
68196989
*/
@@ -13082,6 +13252,7 @@ const AST_CONSTRUCTORS: Array<
1308213252
UserDefinedStringLiteralExpressionAST,
1308313253
ObjectLiteralExpressionAST,
1308413254
ThisExpressionAST,
13255+
GenericSelectionExpressionAST,
1308513256
NestedStatementExpressionAST,
1308613257
NestedExpressionAST,
1308713258
IdExpressionAST,
@@ -13132,6 +13303,8 @@ const AST_CONSTRUCTORS: Array<
1313213303
EqualInitializerAST,
1313313304
BracedInitListAST,
1313413305
ParenInitializerAST,
13306+
DefaultGenericAssociationAST,
13307+
TypeGenericAssociationAST,
1313513308
DotDesignatorAST,
1313613309
SubscriptDesignatorAST,
1313713310
SplicerAST,

packages/cxx-frontend/src/ASTKind.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ export enum ASTKind {
8787
UserDefinedStringLiteralExpression,
8888
ObjectLiteralExpression,
8989
ThisExpression,
90+
GenericSelectionExpression,
9091
NestedStatementExpression,
9192
NestedExpression,
9293
IdExpression,
@@ -138,6 +139,10 @@ export enum ASTKind {
138139
BracedInitList,
139140
ParenInitializer,
140141

142+
// GenericAssociationAST
143+
DefaultGenericAssociation,
144+
TypeGenericAssociation,
145+
141146
// DesignatorAST
142147
DotDesignator,
143148
SubscriptDesignator,

0 commit comments

Comments
 (0)