[298fe57] | 1 | // |
---|
| 2 | // Cforall Version 1.0.0 Copyright (C) 2018 University of Waterloo |
---|
| 3 | // |
---|
| 4 | // The contents of this file are covered under the licence agreement in the |
---|
| 5 | // file "LICENCE" distributed with Cforall. |
---|
| 6 | // |
---|
| 7 | // NoIdSymbolTable.hpp -- Special WithSymbolTable variant ast::Pass helper. |
---|
| 8 | // |
---|
| 9 | // Author : Andrew Beach |
---|
| 10 | // Created On : Thr Apr 21 11:57:00 2022 |
---|
| 11 | // Last Modified By : Andrew Beach |
---|
| 12 | // Last Modified On : Thr Apr 21 11:57:00 2022 |
---|
| 13 | // Update Count : 0 |
---|
| 14 | // |
---|
| 15 | |
---|
| 16 | #pragma once |
---|
| 17 | |
---|
| 18 | #include "AST/SymbolTable.hpp" |
---|
| 19 | |
---|
| 20 | namespace Validate { |
---|
| 21 | |
---|
[4d860ea3] | 22 | // A SymbolTable that only tracks names relevant to Validate passes. |
---|
| 23 | // It tracks type names but not identifier names. |
---|
| 24 | // Some of the canonicalization that occurs before the resolver |
---|
| 25 | // affects how identifier name errors get reported to the user. |
---|
| 26 | // The Validate phase needs to chase type names, |
---|
| 27 | // but it is too early to try tracking identifier names. |
---|
| 28 | // Identifier skipping is acheived by omitting methods that should not be |
---|
[298fe57] | 29 | // called by the Pass template (lookupId and addId). |
---|
| 30 | class NoIdSymbolTable { |
---|
| 31 | ast::SymbolTable base; |
---|
| 32 | public: |
---|
[4d860ea3] | 33 | // All names that are tracked (now) are eligible for collision validation (now). |
---|
| 34 | // (Names that are only tracked later get their collision validation then.) |
---|
| 35 | NoIdSymbolTable() : base(ast::SymbolTable::ValidateOnAdd) {} |
---|
| 36 | |
---|
[298fe57] | 37 | # define FORWARD_X( func, types_and_names, just_names ) \ |
---|
| 38 | inline auto func types_and_names -> decltype( base.func just_names ) { \ |
---|
| 39 | return base.func just_names ; \ |
---|
| 40 | } |
---|
| 41 | # define FORWARD_0( func ) FORWARD_X( func, (), () ) |
---|
| 42 | # define FORWARD_1( func, type ) FORWARD_X( func, (type arg), (arg) ) |
---|
| 43 | # define FORWARD_2( func, t0, t1 ) FORWARD_X( func, (t0 a0, t1 a1), (a0, a1) ) |
---|
| 44 | |
---|
| 45 | FORWARD_0( enterScope ) |
---|
| 46 | FORWARD_0( leaveScope ) |
---|
| 47 | FORWARD_1( lookupType , const std::string & ) |
---|
| 48 | FORWARD_1( lookupStruct, const std::string & ) |
---|
| 49 | FORWARD_1( lookupEnum , const std::string & ) |
---|
| 50 | FORWARD_1( lookupUnion , const std::string & ) |
---|
| 51 | FORWARD_1( lookupTrait , const std::string & ) |
---|
| 52 | FORWARD_1( addType , const ast::NamedTypeDecl * ) |
---|
| 53 | FORWARD_1( addStruct, const ast::StructDecl * ) |
---|
| 54 | FORWARD_1( addEnum , const ast::EnumDecl * ) |
---|
| 55 | FORWARD_1( addUnion , const ast::UnionDecl * ) |
---|
| 56 | FORWARD_1( addTrait , const ast::TraitDecl * ) |
---|
| 57 | FORWARD_2( addWith , const std::vector< ast::ptr<ast::Expr> > &, const ast::Decl * ) |
---|
[e0069bd] | 58 | FORWARD_1( addStructId, const std::string & ) |
---|
| 59 | FORWARD_1( addUnionId , const std::string & ) |
---|
[298fe57] | 60 | |
---|
| 61 | FORWARD_1( globalLookupType, const std::string & ) |
---|
| 62 | |
---|
| 63 | # undef FORWARD_2 |
---|
| 64 | # undef FORWARD_1 |
---|
| 65 | # undef FORWARD_0 |
---|
| 66 | # undef FORWARD_X |
---|
| 67 | }; |
---|
| 68 | |
---|
| 69 | struct WithNoIdSymbolTable { |
---|
| 70 | NoIdSymbolTable symtab; |
---|
| 71 | }; |
---|
| 72 | |
---|
| 73 | } |
---|
| 74 | |
---|
| 75 | // Local Variables: // |
---|
| 76 | // tab-width: 4 // |
---|
| 77 | // mode: c++ // |
---|
| 78 | // compile-command: "make install" // |
---|
| 79 | // End: // |
---|