Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
203 changes: 102 additions & 101 deletions packages/cxx-frontend/src/ASTSlot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,105 +156,106 @@ export enum ASTSlot {
literalOperatorId = 133,
lparen2Loc = 134,
lparenLoc = 135,
memInitializerList = 136,
minusGreaterLoc = 137,
moduleDeclaration = 138,
moduleLoc = 139,
moduleName = 140,
modulePartition = 141,
moduleQualifier = 142,
mutableLoc = 143,
namespaceLoc = 144,
nestedNameSpecifier = 145,
nestedNamespaceSpecifierList = 146,
newInitalizer = 147,
newLoc = 148,
newPlacement = 149,
noexceptLoc = 150,
noreturnLoc = 151,
offsetofLoc = 152,
op = 153,
opLoc = 154,
openLoc = 155,
operatorFunctionId = 156,
operatorLoc = 157,
otherVirtualOrAccessLoc = 158,
outputOperandList = 159,
parameterDeclarationClause = 160,
parameterDeclarationList = 161,
privateLoc = 162,
privateModuleFragment = 163,
ptrOpList = 164,
qualifier = 165,
qualifierLoc = 166,
questionLoc = 167,
rangeDeclaration = 168,
rangeInitializer = 169,
rbraceLoc = 170,
rbracket2Loc = 171,
rbracketLoc = 172,
refLoc = 173,
refOp = 174,
refQualifierLoc = 175,
registerLoc = 176,
requirementList = 177,
requiresClause = 178,
requiresLoc = 179,
restrictLoc = 180,
returnLoc = 181,
rightExpression = 182,
rparen2Loc = 183,
rparenLoc = 184,
scopeLoc = 185,
secondColonLoc = 186,
semicolonLoc = 187,
sizeExpression = 188,
sizeofLoc = 189,
specifier = 190,
specifierLoc = 191,
splicer = 192,
starLoc = 193,
statement = 194,
statementList = 195,
staticAssertLoc = 196,
staticLoc = 197,
stringLiteral = 198,
stringliteralLoc = 199,
switchLoc = 200,
symbolicName = 201,
symbolicNameLoc = 202,
templateArgumentList = 203,
templateId = 204,
templateLoc = 205,
templateParameterList = 206,
templateRequiresClause = 207,
thisLoc = 208,
threadLoc = 209,
threadLocalLoc = 210,
throwLoc = 211,
tildeLoc = 212,
trailingReturnType = 213,
tryLoc = 214,
typeConstraint = 215,
typeId = 216,
typeIdList = 217,
typeLoc = 218,
typeQualifierList = 219,
typeSpecifier = 220,
typeSpecifierList = 221,
typeTraitLoc = 222,
typedefLoc = 223,
typeidLoc = 224,
typenameLoc = 225,
underlyingTypeLoc = 226,
unqualifiedId = 227,
usingDeclaratorList = 228,
usingLoc = 229,
vaArgLoc = 230,
virtualLoc = 231,
virtualOrAccessLoc = 232,
voidLoc = 233,
volatileLoc = 234,
whileLoc = 235,
yieldLoc = 236,
matchedAssocIndex = 136,
memInitializerList = 137,
minusGreaterLoc = 138,
moduleDeclaration = 139,
moduleLoc = 140,
moduleName = 141,
modulePartition = 142,
moduleQualifier = 143,
mutableLoc = 144,
namespaceLoc = 145,
nestedNameSpecifier = 146,
nestedNamespaceSpecifierList = 147,
newInitalizer = 148,
newLoc = 149,
newPlacement = 150,
noexceptLoc = 151,
noreturnLoc = 152,
offsetofLoc = 153,
op = 154,
opLoc = 155,
openLoc = 156,
operatorFunctionId = 157,
operatorLoc = 158,
otherVirtualOrAccessLoc = 159,
outputOperandList = 160,
parameterDeclarationClause = 161,
parameterDeclarationList = 162,
privateLoc = 163,
privateModuleFragment = 164,
ptrOpList = 165,
qualifier = 166,
qualifierLoc = 167,
questionLoc = 168,
rangeDeclaration = 169,
rangeInitializer = 170,
rbraceLoc = 171,
rbracket2Loc = 172,
rbracketLoc = 173,
refLoc = 174,
refOp = 175,
refQualifierLoc = 176,
registerLoc = 177,
requirementList = 178,
requiresClause = 179,
requiresLoc = 180,
restrictLoc = 181,
returnLoc = 182,
rightExpression = 183,
rparen2Loc = 184,
rparenLoc = 185,
scopeLoc = 186,
secondColonLoc = 187,
semicolonLoc = 188,
sizeExpression = 189,
sizeofLoc = 190,
specifier = 191,
specifierLoc = 192,
splicer = 193,
starLoc = 194,
statement = 195,
statementList = 196,
staticAssertLoc = 197,
staticLoc = 198,
stringLiteral = 199,
stringliteralLoc = 200,
switchLoc = 201,
symbolicName = 202,
symbolicNameLoc = 203,
templateArgumentList = 204,
templateId = 205,
templateLoc = 206,
templateParameterList = 207,
templateRequiresClause = 208,
thisLoc = 209,
threadLoc = 210,
threadLocalLoc = 211,
throwLoc = 212,
tildeLoc = 213,
trailingReturnType = 214,
tryLoc = 215,
typeConstraint = 216,
typeId = 217,
typeIdList = 218,
typeLoc = 219,
typeQualifierList = 220,
typeSpecifier = 221,
typeSpecifierList = 222,
typeTraitLoc = 223,
typedefLoc = 224,
typeidLoc = 225,
typenameLoc = 226,
underlyingTypeLoc = 227,
unqualifiedId = 228,
usingDeclaratorList = 229,
usingLoc = 230,
vaArgLoc = 231,
virtualLoc = 232,
virtualOrAccessLoc = 233,
voidLoc = 234,
volatileLoc = 235,
whileLoc = 236,
yieldLoc = 237,
}
1 change: 1 addition & 0 deletions packages/cxx-gen-ast/src/tokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ export const CXX_KEYWORDS: string[] = [
"__underlying_type",
"_Atomic",
"_Complex",
"_Generic",
];

export const BUILTIN_TYPE_TRAITS: string[] = [
Expand Down
1 change: 1 addition & 0 deletions src/parser/cxx/ast.h
Original file line number Diff line number Diff line change
Expand Up @@ -1344,6 +1344,7 @@ class GenericSelectionExpressionAST final : public ExpressionAST {
SourceLocation commaLoc;
List<GenericAssociationAST*>* genericAssociationList = nullptr;
SourceLocation rparenLoc;
int matchedAssocIndex = -1;

void accept(ASTVisitor* visitor) override { visitor->visit(this); }

Expand Down
20 changes: 20 additions & 0 deletions src/parser/cxx/ast_interpreter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1646,6 +1646,26 @@ auto ASTInterpreter::ExpressionVisitor::operator()(ThisExpressionAST* ast)

auto ASTInterpreter::ExpressionVisitor::operator()(
GenericSelectionExpressionAST* ast) -> ExpressionResult {
if (ast->matchedAssocIndex == -1) return std::nullopt;

GenericAssociationAST* assoc = nullptr;
int index = 0;
for (auto assocNode : ListView{ast->genericAssociationList}) {
if (index == ast->matchedAssocIndex) {
assoc = assocNode;
break;
}
++index;
}

if (auto def = ast_cast<DefaultGenericAssociationAST>(assoc)) {
return accept(def->expression);
}

if (auto entry = ast_cast<TypeGenericAssociationAST>(assoc)) {
return accept(entry->expression);
}

return std::nullopt;
}

Expand Down
4 changes: 4 additions & 0 deletions src/parser/cxx/ast_printer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -854,6 +854,10 @@ void ASTPrinter::visit(GenericSelectionExpressionAST* ast) {
to_string(ast->type));
}
out_ << "\n";
++indent_;
out_ << std::format("{:{}}", "", indent_ * 2);
out_ << std::format("matched-assoc-index: {}\n", ast->matchedAssocIndex);
--indent_;
accept(ast->expression, "expression");
if (ast->genericAssociationList) {
++indent_;
Expand Down
1 change: 1 addition & 0 deletions src/parser/cxx/ast_rewriter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2489,6 +2489,7 @@ auto ASTRewriter::ExpressionVisitor::operator()(
}

copy->rparenLoc = ast->rparenLoc;
copy->matchedAssocIndex = ast->matchedAssocIndex;

return copy;
}
Expand Down
Loading