|
26 | 26 | #include <cxx/decl.h> |
27 | 27 | #include <cxx/decl_specs.h> |
28 | 28 | #include <cxx/memory_layout.h> |
| 29 | +#include <cxx/name_lookup.h> |
29 | 30 | #include <cxx/names.h> |
30 | 31 | #include <cxx/scope.h> |
31 | 32 | #include <cxx/symbols.h> |
@@ -186,6 +187,153 @@ auto Binder::declareTypeAlias(SourceLocation identifierLoc, TypeIdAST* typeId) |
186 | 187 | return symbol; |
187 | 188 | } |
188 | 189 |
|
| 190 | +void Binder::bind(UsingDeclaratorAST* ast, Symbol* target) { |
| 191 | + if (auto u = symbol_cast<UsingDeclarationSymbol>(target)) { |
| 192 | + target = u->target(); |
| 193 | + } |
| 194 | + |
| 195 | + const auto name = get_name(control(), ast->unqualifiedId); |
| 196 | + |
| 197 | + auto symbol = control()->newUsingDeclarationSymbol( |
| 198 | + scope(), ast->unqualifiedId->firstSourceLocation()); |
| 199 | + |
| 200 | + ast->symbol = symbol; |
| 201 | + |
| 202 | + symbol->setName(name); |
| 203 | + symbol->setDeclarator(ast); |
| 204 | + symbol->setTarget(target); |
| 205 | + |
| 206 | + scope()->addSymbol(symbol); |
| 207 | +} |
| 208 | + |
| 209 | +void Binder::bind(BaseSpecifierAST* ast) { |
| 210 | + Symbol* symbol = nullptr; |
| 211 | + |
| 212 | + if (auto decltypeId = ast_cast<DecltypeIdAST>(ast->unqualifiedId)) { |
| 213 | + if (auto classType = type_cast<ClassType>( |
| 214 | + control()->remove_cv(decltypeId->decltypeSpecifier->type))) { |
| 215 | + symbol = classType->symbol(); |
| 216 | + } |
| 217 | + } |
| 218 | + |
| 219 | + if (auto nameId = ast_cast<NameIdAST>(ast->unqualifiedId)) { |
| 220 | + symbol = Lookup{scope_}(ast->nestedNameSpecifier, nameId->identifier); |
| 221 | + } |
| 222 | + |
| 223 | + if (auto typeAlias = symbol_cast<TypeAliasSymbol>(symbol)) { |
| 224 | + if (auto classType = |
| 225 | + type_cast<ClassType>(control()->remove_cv(typeAlias->type()))) { |
| 226 | + symbol = classType->symbol(); |
| 227 | + } |
| 228 | + } |
| 229 | + |
| 230 | + if (symbol) { |
| 231 | + auto location = ast->unqualifiedId->firstSourceLocation(); |
| 232 | + auto baseClassSymbol = control()->newBaseClassSymbol(scope(), location); |
| 233 | + ast->symbol = baseClassSymbol; |
| 234 | + |
| 235 | + baseClassSymbol->setVirtual(ast->isVirtual); |
| 236 | + baseClassSymbol->setSymbol(symbol); |
| 237 | + |
| 238 | + if (symbol) { |
| 239 | + baseClassSymbol->setName(symbol->name()); |
| 240 | + } |
| 241 | + |
| 242 | + switch (ast->accessSpecifier) { |
| 243 | + case TokenKind::T_PRIVATE: |
| 244 | + baseClassSymbol->setAccessSpecifier(AccessSpecifier::kPrivate); |
| 245 | + break; |
| 246 | + case TokenKind::T_PROTECTED: |
| 247 | + baseClassSymbol->setAccessSpecifier(AccessSpecifier::kProtected); |
| 248 | + break; |
| 249 | + case TokenKind::T_PUBLIC: |
| 250 | + baseClassSymbol->setAccessSpecifier(AccessSpecifier::kPublic); |
| 251 | + break; |
| 252 | + default: |
| 253 | + break; |
| 254 | + } // switch |
| 255 | + } |
| 256 | +} |
| 257 | + |
| 258 | +void Binder::bind(NonTypeTemplateParameterAST* ast, int index, int depth) { |
| 259 | + auto symbol = control()->newNonTypeParameterSymbol( |
| 260 | + scope(), ast->declaration->firstSourceLocation()); |
| 261 | + ast->symbol = symbol; |
| 262 | + |
| 263 | + symbol->setIndex(index); |
| 264 | + symbol->setDepth(depth); |
| 265 | + symbol->setName(ast->declaration->identifier); |
| 266 | + symbol->setParameterPack(ast->declaration->isPack); |
| 267 | + symbol->setObjectType(ast->declaration->type); |
| 268 | + scope()->addSymbol(symbol); |
| 269 | +} |
| 270 | + |
| 271 | +void Binder::bind(TypenameTypeParameterAST* ast, int index, int depth) { |
| 272 | + auto location = ast->identifier ? ast->identifierLoc : ast->classKeyLoc; |
| 273 | + |
| 274 | + auto symbol = control()->newTypeParameterSymbol(scope(), location); |
| 275 | + ast->symbol = symbol; |
| 276 | + |
| 277 | + symbol->setIndex(index); |
| 278 | + symbol->setDepth(depth); |
| 279 | + symbol->setParameterPack(ast->isPack); |
| 280 | + symbol->setName(ast->identifier); |
| 281 | + scope()->addSymbol(symbol); |
| 282 | +} |
| 283 | + |
| 284 | +void Binder::bind(ConstraintTypeParameterAST* ast, int index, int depth) { |
| 285 | + auto symbol = |
| 286 | + control()->newConstraintTypeParameterSymbol(scope(), ast->identifierLoc); |
| 287 | + symbol->setIndex(index); |
| 288 | + symbol->setDepth(depth); |
| 289 | + symbol->setName(ast->identifier); |
| 290 | + scope()->addSymbol(symbol); |
| 291 | +} |
| 292 | + |
| 293 | +void Binder::bind(TemplateTypeParameterAST* ast, int index, int depth) { |
| 294 | + auto symbol = |
| 295 | + control()->newTemplateTypeParameterSymbol(scope(), ast->templateLoc); |
| 296 | + |
| 297 | + ast->symbol = symbol; |
| 298 | + |
| 299 | + symbol->setIndex(index); |
| 300 | + symbol->setDepth(depth); |
| 301 | + symbol->setName(ast->identifier); |
| 302 | + symbol->setParameterPack(ast->isPack); |
| 303 | + scope()->addSymbol(symbol); |
| 304 | +} |
| 305 | + |
| 306 | +void Binder::bind(ConceptDefinitionAST* ast) { |
| 307 | + auto templateParameters = currentTemplateParameters(); |
| 308 | + |
| 309 | + auto symbol = control()->newConceptSymbol(scope(), ast->identifierLoc); |
| 310 | + symbol->setName(ast->identifier); |
| 311 | + symbol->setTemplateParameters(templateParameters); |
| 312 | + |
| 313 | + declaringScope()->addSymbol(symbol); |
| 314 | +} |
| 315 | + |
| 316 | +void Binder::bind(LambdaExpressionAST* ast) { |
| 317 | + auto parentScope = declaringScope(); |
| 318 | + auto symbol = control()->newLambdaSymbol(parentScope, ast->lbracketLoc); |
| 319 | + ast->symbol = symbol; |
| 320 | + |
| 321 | + setScope(symbol); |
| 322 | +} |
| 323 | + |
| 324 | +void Binder::complete(LambdaExpressionAST* ast) { |
| 325 | + if (auto params = ast->parameterDeclarationClause) { |
| 326 | + auto lambdaScope = ast->symbol->scope(); |
| 327 | + lambdaScope->addSymbol(params->functionParametersSymbol); |
| 328 | + setScope(params->functionParametersSymbol); |
| 329 | + } else { |
| 330 | + setScope(ast->symbol); |
| 331 | + } |
| 332 | + |
| 333 | + auto parentScope = ast->symbol->enclosingScope(); |
| 334 | + parentScope->addSymbol(ast->symbol); |
| 335 | +} |
| 336 | + |
189 | 337 | auto Binder::declareTypedef(DeclaratorAST* declarator, const Decl& decl) |
190 | 338 | -> TypeAliasSymbol* { |
191 | 339 | auto name = decl.getName(); |
|
0 commit comments