Skip to content

Commit 303a0a7

Browse files
committed
fix: Add support for gcc-like inline asm declarations
1 parent 184e1dd commit 303a0a7

28 files changed

+2494
-1016
lines changed

packages/cxx-frontend/src/AST.ts

+259-6
Original file line numberDiff line numberDiff line change
@@ -7520,6 +7520,190 @@ export class UsingEnumDeclarationAST extends DeclarationAST {
75207520
}
75217521
}
75227522

7523+
/**
7524+
* AsmOperandAST node.
7525+
*/
7526+
export class AsmOperandAST extends DeclarationAST {
7527+
/**
7528+
* Traverse this node using the given visitor.
7529+
* @param visitor the visitor.
7530+
* @param context the context.
7531+
* @returns the result of the visit.
7532+
*/
7533+
accept<Context, Result>(
7534+
visitor: ASTVisitor<Context, Result>,
7535+
context: Context,
7536+
): Result {
7537+
return visitor.visitAsmOperand(this, context);
7538+
}
7539+
7540+
/**
7541+
* Returns the location of the lbracket token in this node
7542+
*/
7543+
getLbracketToken(): Token | undefined {
7544+
return Token.from(cxx.getASTSlot(this.getHandle(), 0), this.parser);
7545+
}
7546+
7547+
/**
7548+
* Returns the location of the symbolicName token in this node
7549+
*/
7550+
getSymbolicNameToken(): Token | undefined {
7551+
return Token.from(cxx.getASTSlot(this.getHandle(), 1), this.parser);
7552+
}
7553+
7554+
/**
7555+
* Returns the location of the rbracket token in this node
7556+
*/
7557+
getRbracketToken(): Token | undefined {
7558+
return Token.from(cxx.getASTSlot(this.getHandle(), 2), this.parser);
7559+
}
7560+
7561+
/**
7562+
* Returns the location of the constraintLiteral token in this node
7563+
*/
7564+
getConstraintLiteralToken(): Token | undefined {
7565+
return Token.from(cxx.getASTSlot(this.getHandle(), 3), this.parser);
7566+
}
7567+
7568+
/**
7569+
* Returns the location of the lparen token in this node
7570+
*/
7571+
getLparenToken(): Token | undefined {
7572+
return Token.from(cxx.getASTSlot(this.getHandle(), 4), this.parser);
7573+
}
7574+
7575+
/**
7576+
* Returns the expression of this node
7577+
*/
7578+
getExpression(): ExpressionAST | undefined {
7579+
return AST.from<ExpressionAST>(
7580+
cxx.getASTSlot(this.getHandle(), 5),
7581+
this.parser,
7582+
);
7583+
}
7584+
7585+
/**
7586+
* Returns the location of the rparen token in this node
7587+
*/
7588+
getRparenToken(): Token | undefined {
7589+
return Token.from(cxx.getASTSlot(this.getHandle(), 6), this.parser);
7590+
}
7591+
7592+
/**
7593+
* Returns the symbolicName attribute of this node
7594+
*/
7595+
getSymbolicName(): string | undefined {
7596+
const slot = cxx.getASTSlot(this.getHandle(), 7);
7597+
return cxx.getIdentifierValue(slot);
7598+
}
7599+
7600+
/**
7601+
* Returns the constraintLiteral attribute of this node
7602+
*/
7603+
getConstraintLiteral(): string | undefined {
7604+
const slot = cxx.getASTSlot(this.getHandle(), 8);
7605+
return cxx.getLiteralValue(slot);
7606+
}
7607+
}
7608+
7609+
/**
7610+
* AsmQualifierAST node.
7611+
*/
7612+
export class AsmQualifierAST extends DeclarationAST {
7613+
/**
7614+
* Traverse this node using the given visitor.
7615+
* @param visitor the visitor.
7616+
* @param context the context.
7617+
* @returns the result of the visit.
7618+
*/
7619+
accept<Context, Result>(
7620+
visitor: ASTVisitor<Context, Result>,
7621+
context: Context,
7622+
): Result {
7623+
return visitor.visitAsmQualifier(this, context);
7624+
}
7625+
7626+
/**
7627+
* Returns the location of the qualifier token in this node
7628+
*/
7629+
getQualifierToken(): Token | undefined {
7630+
return Token.from(cxx.getASTSlot(this.getHandle(), 0), this.parser);
7631+
}
7632+
7633+
/**
7634+
* Returns the qualifier attribute of this node
7635+
*/
7636+
getQualifier(): TokenKind {
7637+
return cxx.getASTSlot(this.getHandle(), 1);
7638+
}
7639+
}
7640+
7641+
/**
7642+
* AsmClobberAST node.
7643+
*/
7644+
export class AsmClobberAST extends DeclarationAST {
7645+
/**
7646+
* Traverse this node using the given visitor.
7647+
* @param visitor the visitor.
7648+
* @param context the context.
7649+
* @returns the result of the visit.
7650+
*/
7651+
accept<Context, Result>(
7652+
visitor: ASTVisitor<Context, Result>,
7653+
context: Context,
7654+
): Result {
7655+
return visitor.visitAsmClobber(this, context);
7656+
}
7657+
7658+
/**
7659+
* Returns the location of the literal token in this node
7660+
*/
7661+
getLiteralToken(): Token | undefined {
7662+
return Token.from(cxx.getASTSlot(this.getHandle(), 0), this.parser);
7663+
}
7664+
7665+
/**
7666+
* Returns the literal attribute of this node
7667+
*/
7668+
getLiteral(): string | undefined {
7669+
const slot = cxx.getASTSlot(this.getHandle(), 1);
7670+
return cxx.getLiteralValue(slot);
7671+
}
7672+
}
7673+
7674+
/**
7675+
* AsmGotoLabelAST node.
7676+
*/
7677+
export class AsmGotoLabelAST extends DeclarationAST {
7678+
/**
7679+
* Traverse this node using the given visitor.
7680+
* @param visitor the visitor.
7681+
* @param context the context.
7682+
* @returns the result of the visit.
7683+
*/
7684+
accept<Context, Result>(
7685+
visitor: ASTVisitor<Context, Result>,
7686+
context: Context,
7687+
): Result {
7688+
return visitor.visitAsmGotoLabel(this, context);
7689+
}
7690+
7691+
/**
7692+
* Returns the location of the identifier token in this node
7693+
*/
7694+
getIdentifierToken(): Token | undefined {
7695+
return Token.from(cxx.getASTSlot(this.getHandle(), 0), this.parser);
7696+
}
7697+
7698+
/**
7699+
* Returns the identifier attribute of this node
7700+
*/
7701+
getIdentifier(): string | undefined {
7702+
const slot = cxx.getASTSlot(this.getHandle(), 1);
7703+
return cxx.getIdentifierValue(slot);
7704+
}
7705+
}
7706+
75237707
/**
75247708
* AsmDeclarationAST node.
75257709
*/
@@ -7550,46 +7734,111 @@ export class AsmDeclarationAST extends DeclarationAST {
75507734
}
75517735
}
75527736

7737+
/**
7738+
* Returns the asmQualifierList of this node
7739+
*/
7740+
*getAsmQualifierList(): Generator<AsmQualifierAST | undefined> {
7741+
for (
7742+
let it = cxx.getASTSlot(this.getHandle(), 1);
7743+
it;
7744+
it = cxx.getListNext(it)
7745+
) {
7746+
yield AST.from<AsmQualifierAST>(cxx.getListValue(it), this.parser);
7747+
}
7748+
}
7749+
75537750
/**
75547751
* Returns the location of the asm token in this node
75557752
*/
75567753
getAsmToken(): Token | undefined {
7557-
return Token.from(cxx.getASTSlot(this.getHandle(), 1), this.parser);
7754+
return Token.from(cxx.getASTSlot(this.getHandle(), 2), this.parser);
75587755
}
75597756

75607757
/**
75617758
* Returns the location of the lparen token in this node
75627759
*/
75637760
getLparenToken(): Token | undefined {
7564-
return Token.from(cxx.getASTSlot(this.getHandle(), 2), this.parser);
7761+
return Token.from(cxx.getASTSlot(this.getHandle(), 3), this.parser);
75657762
}
75667763

75677764
/**
75687765
* Returns the location of the literal token in this node
75697766
*/
75707767
getLiteralToken(): Token | undefined {
7571-
return Token.from(cxx.getASTSlot(this.getHandle(), 3), this.parser);
7768+
return Token.from(cxx.getASTSlot(this.getHandle(), 4), this.parser);
7769+
}
7770+
7771+
/**
7772+
* Returns the outputOperandList of this node
7773+
*/
7774+
*getOutputOperandList(): Generator<AsmOperandAST | undefined> {
7775+
for (
7776+
let it = cxx.getASTSlot(this.getHandle(), 5);
7777+
it;
7778+
it = cxx.getListNext(it)
7779+
) {
7780+
yield AST.from<AsmOperandAST>(cxx.getListValue(it), this.parser);
7781+
}
7782+
}
7783+
7784+
/**
7785+
* Returns the inputOperandList of this node
7786+
*/
7787+
*getInputOperandList(): Generator<AsmOperandAST | undefined> {
7788+
for (
7789+
let it = cxx.getASTSlot(this.getHandle(), 6);
7790+
it;
7791+
it = cxx.getListNext(it)
7792+
) {
7793+
yield AST.from<AsmOperandAST>(cxx.getListValue(it), this.parser);
7794+
}
7795+
}
7796+
7797+
/**
7798+
* Returns the clobberList of this node
7799+
*/
7800+
*getClobberList(): Generator<AsmClobberAST | undefined> {
7801+
for (
7802+
let it = cxx.getASTSlot(this.getHandle(), 7);
7803+
it;
7804+
it = cxx.getListNext(it)
7805+
) {
7806+
yield AST.from<AsmClobberAST>(cxx.getListValue(it), this.parser);
7807+
}
7808+
}
7809+
7810+
/**
7811+
* Returns the gotoLabelList of this node
7812+
*/
7813+
*getGotoLabelList(): Generator<AsmGotoLabelAST | undefined> {
7814+
for (
7815+
let it = cxx.getASTSlot(this.getHandle(), 8);
7816+
it;
7817+
it = cxx.getListNext(it)
7818+
) {
7819+
yield AST.from<AsmGotoLabelAST>(cxx.getListValue(it), this.parser);
7820+
}
75727821
}
75737822

75747823
/**
75757824
* Returns the location of the rparen token in this node
75767825
*/
75777826
getRparenToken(): Token | undefined {
7578-
return Token.from(cxx.getASTSlot(this.getHandle(), 4), this.parser);
7827+
return Token.from(cxx.getASTSlot(this.getHandle(), 9), this.parser);
75797828
}
75807829

75817830
/**
75827831
* Returns the location of the semicolon token in this node
75837832
*/
75847833
getSemicolonToken(): Token | undefined {
7585-
return Token.from(cxx.getASTSlot(this.getHandle(), 5), this.parser);
7834+
return Token.from(cxx.getASTSlot(this.getHandle(), 10), this.parser);
75867835
}
75877836

75887837
/**
75897838
* Returns the literal attribute of this node
75907839
*/
75917840
getLiteral(): string | undefined {
7592-
const slot = cxx.getASTSlot(this.getHandle(), 6);
7841+
const slot = cxx.getASTSlot(this.getHandle(), 11);
75937842
return cxx.getLiteralValue(slot);
75947843
}
75957844
}
@@ -10934,6 +11183,10 @@ const AST_CONSTRUCTORS: Array<
1093411183
UsingDirectiveAST,
1093511184
UsingDeclarationAST,
1093611185
UsingEnumDeclarationAST,
11186+
AsmOperandAST,
11187+
AsmQualifierAST,
11188+
AsmClobberAST,
11189+
AsmGotoLabelAST,
1093711190
AsmDeclarationAST,
1093811191
ExportDeclarationAST,
1093911192
ExportCompoundDeclarationAST,

packages/cxx-frontend/src/ASTKind.ts

+4
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,10 @@ export enum ASTKind {
193193
UsingDirective,
194194
UsingDeclaration,
195195
UsingEnumDeclaration,
196+
AsmOperand,
197+
AsmQualifier,
198+
AsmClobber,
199+
AsmGotoLabel,
196200
AsmDeclaration,
197201
ExportDeclaration,
198202
ExportCompoundDeclaration,

0 commit comments

Comments
 (0)