34
34
35
35
namespace cxx {
36
36
37
- auto ASTRewriter::make_substitution (
38
- TranslationUnit* unit, TemplateDeclarationAST* templateDecl,
39
- List<TemplateArgumentAST*>* templateArgumentList)
40
- -> std::vector<TemplateArgument> {
41
- auto control = unit->control ();
42
- auto interp = ASTInterpreter{unit};
43
-
44
- std::vector<TemplateArgument> templateArguments;
45
-
46
- for (auto arg : ListView{templateArgumentList}) {
47
- if (auto exprArg = ast_cast<ExpressionTemplateArgumentAST>(arg)) {
48
- auto expr = exprArg->expression ;
49
- auto value = interp.evaluate (expr);
50
- if (!value.has_value ()) {
51
- #if false
52
- unit->error (arg->firstSourceLocation (),
53
- " template argument is not a constant expression" );
54
- #endif
55
- continue ;
56
- }
57
-
58
- // ### need to set scope and location
59
- auto templArg = control->newVariableSymbol (nullptr , {});
60
- templArg->setInitializer (expr);
61
- templArg->setType (control->add_const (expr->type ));
62
- templArg->setConstValue (value);
63
- templateArguments.push_back (templArg);
64
- } else if (auto typeArg = ast_cast<TypeTemplateArgumentAST>(arg)) {
65
- auto type = typeArg->typeId ->type ;
66
- // ### need to set scope and location
67
- auto templArg = control->newTypeAliasSymbol (nullptr , {});
68
- templArg->setType (type);
69
- templateArguments.push_back (templArg);
70
- }
71
- }
72
-
73
- return templateArguments;
74
- }
75
-
76
- ASTRewriter::ASTRewriter (TranslationUnit* unit, Scope* scope,
37
+ ASTRewriter::ASTRewriter (TranslationUnit* unit, ScopeSymbol* scope,
77
38
const std::vector<TemplateArgument>& templateArguments)
78
39
: unit_(unit), templateArguments_(templateArguments), binder_(unit_) {
79
40
binder_.setScope (scope);
@@ -167,7 +128,7 @@ auto ASTRewriter::instantiateClassTemplate(
167
128
return subst;
168
129
}
169
130
170
- auto parentScope = classSymbol->enclosingSymbol ()-> scope ();
131
+ auto parentScope = classSymbol->enclosingNonTemplateParametersScope ();
171
132
172
133
auto rewriter = ASTRewriter{unit, parentScope, templateArguments};
173
134
@@ -222,7 +183,10 @@ auto ASTRewriter::instantiateTypeAliasTemplate(
222
183
}
223
184
#endif
224
185
225
- auto parentScope = typeAliasSymbol->enclosingSymbol ()->scope ();
186
+ auto parentScope = typeAliasSymbol->parent ();
187
+ while (parentScope->isTemplateParameters ()) {
188
+ parentScope = parentScope->parent ();
189
+ }
226
190
227
191
auto rewriter = ASTRewriter{unit, parentScope, templateArguments};
228
192
@@ -236,4 +200,43 @@ auto ASTRewriter::instantiateTypeAliasTemplate(
236
200
return instance->symbol ;
237
201
}
238
202
203
+ auto ASTRewriter::make_substitution (
204
+ TranslationUnit* unit, TemplateDeclarationAST* templateDecl,
205
+ List<TemplateArgumentAST*>* templateArgumentList)
206
+ -> std::vector<TemplateArgument> {
207
+ auto control = unit->control ();
208
+ auto interp = ASTInterpreter{unit};
209
+
210
+ std::vector<TemplateArgument> templateArguments;
211
+
212
+ for (auto arg : ListView{templateArgumentList}) {
213
+ if (auto exprArg = ast_cast<ExpressionTemplateArgumentAST>(arg)) {
214
+ auto expr = exprArg->expression ;
215
+ auto value = interp.evaluate (expr);
216
+ if (!value.has_value ()) {
217
+ #if false
218
+ unit->error (arg->firstSourceLocation (),
219
+ " template argument is not a constant expression" );
220
+ #endif
221
+ continue ;
222
+ }
223
+
224
+ // ### need to set scope and location
225
+ auto templArg = control->newVariableSymbol (nullptr , {});
226
+ templArg->setInitializer (expr);
227
+ templArg->setType (control->add_const (expr->type ));
228
+ templArg->setConstValue (value);
229
+ templateArguments.push_back (templArg);
230
+ } else if (auto typeArg = ast_cast<TypeTemplateArgumentAST>(arg)) {
231
+ auto type = typeArg->typeId ->type ;
232
+ // ### need to set scope and location
233
+ auto templArg = control->newTypeAliasSymbol (nullptr , {});
234
+ templArg->setType (type);
235
+ templateArguments.push_back (templArg);
236
+ }
237
+ }
238
+
239
+ return templateArguments;
240
+ }
241
+
239
242
} // namespace cxx
0 commit comments