Skip to content

Commit 5a9a8e4

Browse files
committed
Add subscript designators
1 parent f6de927 commit 5a9a8e4

23 files changed

+1455
-956
lines changed

packages/cxx-frontend/src/AST.ts

Lines changed: 108 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ export abstract class AttributeTokenAST extends AST {}
152152
export abstract class CoreDeclaratorAST extends AST {}
153153
export abstract class DeclarationAST extends AST {}
154154
export abstract class DeclaratorChunkAST extends AST {}
155+
export abstract class DesignatorAST extends AST {}
155156
export abstract class ExceptionDeclarationAST extends AST {}
156157
export abstract class ExceptionSpecifierAST extends AST {}
157158
export abstract class ExpressionAST extends AST {}
@@ -6411,33 +6412,37 @@ export class DesignatedInitializerClauseAST extends ExpressionAST {
64116412
}
64126413

64136414
/**
6414-
* Returns the location of the dot token in this node
6415-
*/
6416-
getDotToken(): Token | undefined {
6417-
return Token.from(cxx.getASTSlot(this.getHandle(), 0), this.parser);
6418-
}
6419-
6420-
/**
6421-
* Returns the location of the identifier token in this node
6422-
*/
6423-
getIdentifierToken(): Token | undefined {
6424-
return Token.from(cxx.getASTSlot(this.getHandle(), 1), this.parser);
6425-
}
6426-
6427-
/**
6428-
* Returns the identifier attribute of this node
6415+
* Returns the designatorList of this node
64296416
*/
6430-
getIdentifier(): string | undefined {
6431-
const slot = cxx.getASTSlot(this.getHandle(), 2);
6432-
return cxx.getIdentifierValue(slot);
6417+
getDesignatorList(): Iterable<DesignatorAST | undefined> {
6418+
let it = cxx.getASTSlot(this.getHandle(), 0);
6419+
let value: DesignatorAST | undefined;
6420+
let done = false;
6421+
const p = this.parser;
6422+
function advance() {
6423+
done = it === 0;
6424+
if (done) return;
6425+
const ast = cxx.getListValue(it);
6426+
value = AST.from<DesignatorAST>(ast, p);
6427+
it = cxx.getListNext(it);
6428+
}
6429+
function next() {
6430+
advance();
6431+
return { done, value };
6432+
}
6433+
return {
6434+
[Symbol.iterator]() {
6435+
return { next };
6436+
},
6437+
};
64336438
}
64346439

64356440
/**
64366441
* Returns the initializer of this node
64376442
*/
64386443
getInitializer(): ExpressionAST | undefined {
64396444
return AST.from<ExpressionAST>(
6440-
cxx.getASTSlot(this.getHandle(), 3),
6445+
cxx.getASTSlot(this.getHandle(), 1),
64416446
this.parser,
64426447
);
64436448
}
@@ -6756,6 +6761,88 @@ export class ParenInitializerAST extends ExpressionAST {
67566761
}
67576762
}
67586763

6764+
/**
6765+
* DotDesignatorAST node.
6766+
*/
6767+
export class DotDesignatorAST extends DesignatorAST {
6768+
/**
6769+
* Traverse this node using the given visitor.
6770+
* @param visitor the visitor.
6771+
* @param context the context.
6772+
* @returns the result of the visit.
6773+
*/
6774+
accept<Context, Result>(
6775+
visitor: ASTVisitor<Context, Result>,
6776+
context: Context,
6777+
): Result {
6778+
return visitor.visitDotDesignator(this, context);
6779+
}
6780+
6781+
/**
6782+
* Returns the location of the dot token in this node
6783+
*/
6784+
getDotToken(): Token | undefined {
6785+
return Token.from(cxx.getASTSlot(this.getHandle(), 0), this.parser);
6786+
}
6787+
6788+
/**
6789+
* Returns the location of the identifier token in this node
6790+
*/
6791+
getIdentifierToken(): Token | undefined {
6792+
return Token.from(cxx.getASTSlot(this.getHandle(), 1), this.parser);
6793+
}
6794+
6795+
/**
6796+
* Returns the identifier attribute of this node
6797+
*/
6798+
getIdentifier(): string | undefined {
6799+
const slot = cxx.getASTSlot(this.getHandle(), 2);
6800+
return cxx.getIdentifierValue(slot);
6801+
}
6802+
}
6803+
6804+
/**
6805+
* SubscriptDesignatorAST node.
6806+
*/
6807+
export class SubscriptDesignatorAST extends DesignatorAST {
6808+
/**
6809+
* Traverse this node using the given visitor.
6810+
* @param visitor the visitor.
6811+
* @param context the context.
6812+
* @returns the result of the visit.
6813+
*/
6814+
accept<Context, Result>(
6815+
visitor: ASTVisitor<Context, Result>,
6816+
context: Context,
6817+
): Result {
6818+
return visitor.visitSubscriptDesignator(this, context);
6819+
}
6820+
6821+
/**
6822+
* Returns the location of the lbracket token in this node
6823+
*/
6824+
getLbracketToken(): Token | undefined {
6825+
return Token.from(cxx.getASTSlot(this.getHandle(), 0), this.parser);
6826+
}
6827+
6828+
/**
6829+
* Returns the expression of this node
6830+
*/
6831+
getExpression(): ExpressionAST | undefined {
6832+
return AST.from<ExpressionAST>(
6833+
cxx.getASTSlot(this.getHandle(), 1),
6834+
this.parser,
6835+
);
6836+
}
6837+
6838+
/**
6839+
* Returns the location of the rbracket token in this node
6840+
*/
6841+
getRbracketToken(): Token | undefined {
6842+
return Token.from(cxx.getASTSlot(this.getHandle(), 2), this.parser);
6843+
}
6844+
}
6845+
67596846
/**
67606847
* SplicerAST node.
67616848
*/
@@ -12890,6 +12977,8 @@ const AST_CONSTRUCTORS: Array<
1289012977
EqualInitializerAST,
1289112978
BracedInitListAST,
1289212979
ParenInitializerAST,
12980+
DotDesignatorAST,
12981+
SubscriptDesignatorAST,
1289312982
SplicerAST,
1289412983
GlobalModuleFragmentAST,
1289512984
PrivateModuleFragmentAST,

packages/cxx-frontend/src/ASTKind.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,10 @@ export enum ASTKind {
136136
BracedInitList,
137137
ParenInitializer,
138138

139+
// DesignatorAST
140+
DotDesignator,
141+
SubscriptDesignator,
142+
139143
// AST
140144
Splicer,
141145
GlobalModuleFragment,

0 commit comments

Comments
 (0)