- Timestamp:
- Nov 14, 2022, 11:52:44 AM (3 years ago)
- Branches:
- ADT, ast-experimental, master
- Children:
- 7d9598d8
- Parents:
- b77f0e1 (diff), 19a8c40 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)links above to see all the changes relative to each parent. - Location:
- src/AST
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
src/AST/Convert.cpp
rb77f0e1 r63be3387 234 234 } 235 235 return declWithTypePostamble( decl, node ); 236 } 237 238 // InlineMemberDecl vanish after EnumAndPointerDecay pass so no necessary to implement NewToOld 239 const ast::DeclWithType * visit( const ast::InlineMemberDecl * node ) override final { 240 assert( false ); 241 (void) node; 242 return nullptr; 236 243 } 237 244 … … 1614 1621 { old->get_funcSpec().val } 1615 1622 ); 1616 decl->enumInLine = old->enumInLine;1617 1623 cache.emplace(old, decl); 1618 1624 assert(cache.find( old ) != cache.end()); … … 1859 1865 decl->uniqueId = old->uniqueId; 1860 1866 decl->storage = { old->storageClasses.val }; 1867 1868 this->node = decl; 1869 } 1870 1871 virtual void visit( const InlineMemberDecl * old ) override final { 1872 if ( inCache( old ) ) { 1873 return; 1874 } 1875 auto&& type = GET_ACCEPT_1(type, Type); 1876 auto&& attr = GET_ACCEPT_V(attributes, Attribute); 1877 1878 auto decl = new ast::InlineMemberDecl( 1879 old->location, 1880 old->name, 1881 type, 1882 { old->get_storageClasses().val }, 1883 { old->linkage.val }, 1884 std::move(attr), 1885 { old->get_funcSpec().val } 1886 ); 1887 cache.emplace(old, decl); 1888 assert(cache.find( old ) != cache.end()); 1889 decl->scopeLevel = old->scopeLevel; 1890 decl->mangleName = old->mangleName; 1891 decl->isDeleted = old->isDeleted; 1892 decl->asmName = GET_ACCEPT_1(asmName, Expr); 1893 decl->uniqueId = old->uniqueId; 1894 decl->extension = old->extension; 1861 1895 1862 1896 this->node = decl; -
src/AST/Decl.hpp
rb77f0e1 r63be3387 105 105 ptr<Init> init; 106 106 ptr<Expr> bitfieldWidth; 107 bool enumInLine = false; // enum inline is not a real object declaration.108 // It is a place holder for a set of enum value (ObjectDecl)109 bool importValue = false; // if the value copied from somewhere else110 107 111 108 ObjectDecl( const CodeLocation & loc, const std::string & name, const Type * type, … … 400 397 }; 401 398 399 /// Static Assertion `_Static_assert( ... , ... );` 402 400 class StaticAssertDecl : public Decl { 403 401 public: … … 411 409 private: 412 410 StaticAssertDecl * clone() const override { return new StaticAssertDecl( *this ); } 411 MUTATE_FRIEND 412 }; 413 414 /// Inline Member Declaration `inline TypeName;` 415 class InlineMemberDecl final : public DeclWithType { 416 public: 417 ptr<Type> type; 418 419 InlineMemberDecl( const CodeLocation & loc, const std::string & name, const Type * type, 420 Storage::Classes storage = {}, Linkage::Spec linkage = Linkage::Cforall, 421 std::vector< ptr<Attribute> > && attrs = {}, Function::Specs fs = {} ) 422 : DeclWithType( loc, name, storage, linkage, std::move(attrs), fs ), type( type ) {} 423 424 const Type * get_type() const override { return type; } 425 void set_type( const Type * ty ) override { type = ty; } 426 427 const DeclWithType * accept( Visitor& v ) const override { return v.visit( this ); } 428 private: 429 InlineMemberDecl * clone() const override { return new InlineMemberDecl{ *this }; } 413 430 MUTATE_FRIEND 414 431 }; -
src/AST/Fwd.hpp
rb77f0e1 r63be3387 37 37 class DirectiveDecl; 38 38 class StaticAssertDecl; 39 class InlineMemberDecl; 39 40 40 41 class Stmt; -
src/AST/Pass.hpp
rb77f0e1 r63be3387 141 141 const ast::DirectiveDecl * visit( const ast::DirectiveDecl * ) override final; 142 142 const ast::StaticAssertDecl * visit( const ast::StaticAssertDecl * ) override final; 143 const ast::DeclWithType * visit( const ast::InlineMemberDecl * ) override final; 143 144 const ast::CompoundStmt * visit( const ast::CompoundStmt * ) override final; 144 145 const ast::Stmt * visit( const ast::ExprStmt * ) override final; -
src/AST/Pass.impl.hpp
rb77f0e1 r63be3387 617 617 maybe_accept( node, &FunctionDecl::returns ); 618 618 maybe_accept( node, &FunctionDecl::type ); 619 maybe_accept( node, &FunctionDecl::attributes ); 619 620 // First remember that we are now within a function. 620 621 ValueGuard< bool > oldInFunction( inFunction ); … … 625 626 atFunctionTop = true; 626 627 maybe_accept( node, &FunctionDecl::stmts ); 627 maybe_accept( node, &FunctionDecl::attributes );628 628 } 629 629 } … … 800 800 801 801 VISIT_END( StaticAssertDecl, node ); 802 } 803 804 //-------------------------------------------------------------------------- 805 // InlineMemberDecl 806 template< typename core_t > 807 const ast::DeclWithType * ast::Pass< core_t >::visit( const ast::InlineMemberDecl * node ) { 808 VISIT_START( node ); 809 810 if ( __visit_children() ) { 811 { 812 guard_symtab guard { *this }; 813 maybe_accept( node, &InlineMemberDecl::type ); 814 } 815 } 816 817 VISIT_END( DeclWithType, node ); 802 818 } 803 819 -
src/AST/Print.cpp
rb77f0e1 r63be3387 398 398 virtual const ast::Decl * visit( const ast::StructDecl * node ) override final { 399 399 print(node); 400 return node; 401 } 402 403 virtual const ast::DeclWithType * visit( const ast::InlineMemberDecl * node ) override final { 404 os << "inline "; 405 if ( ! node->name.empty() ) os << node->name; 406 400 407 return node; 401 408 } -
src/AST/Type.cpp
rb77f0e1 r63be3387 147 147 // --- TypeInstType 148 148 149 bool TypeInstType::operator==( const TypeInstType & other ) const { 150 return base == other.base 151 && formal_usage == other.formal_usage 152 && expr_id == other.expr_id; 153 } 154 149 155 TypeInstType::TypeInstType( const TypeDecl * b, 150 156 CV::Qualifiers q, std::vector<ptr<Attribute>> && as ) … … 157 163 158 164 bool TypeInstType::isComplete() const { return base->sized; } 165 166 std::string TypeInstType::TypeEnvKey::typeString() const { 167 return std::string("_") + std::to_string(formal_usage) 168 + "_" + std::to_string(expr_id) + "_" + base->name; 169 } 170 171 bool TypeInstType::TypeEnvKey::operator==( 172 const TypeInstType::TypeEnvKey & other ) const { 173 return base == other.base 174 && formal_usage == other.formal_usage 175 && expr_id == other.expr_id; 176 } 177 178 bool TypeInstType::TypeEnvKey::operator<( 179 const TypeInstType::TypeEnvKey & other ) const { 180 // TypeEnvKey ordering is an arbitrary total ordering. 181 // It doesn't mean anything but allows for a sorting. 182 if ( base < other.base ) { 183 return true; 184 } else if ( other.base < base ) { 185 return false; 186 } else if ( formal_usage < other.formal_usage ) { 187 return true; 188 } else if ( other.formal_usage < formal_usage ) { 189 return false; 190 } else { 191 return expr_id < other.expr_id; 192 } 193 } 159 194 160 195 // --- TupleType -
src/AST/Type.hpp
rb77f0e1 r63be3387 408 408 409 409 TypeEnvKey() = default; 410 TypeEnvKey(const TypeDecl * base, int formal_usage = 0, int expr_id = 0): base(base), formal_usage(formal_usage), expr_id(expr_id) {} 411 TypeEnvKey(const TypeInstType & inst): base(inst.base), formal_usage(inst.formal_usage), expr_id(inst.expr_id) {} 412 std::string typeString() const { return std::string("_") + std::to_string(formal_usage) + "_" + std::to_string(expr_id) + "_" + base->name; } 413 bool operator==(const TypeEnvKey & other) const { return base == other.base && formal_usage == other.formal_usage && expr_id == other.expr_id; } 410 TypeEnvKey(const TypeDecl * base, int formal_usage = 0, int expr_id = 0) 411 : base(base), formal_usage(formal_usage), expr_id(expr_id) {} 412 TypeEnvKey(const TypeInstType & inst) 413 : base(inst.base), formal_usage(inst.formal_usage), expr_id(inst.expr_id) {} 414 std::string typeString() const; 415 bool operator==(const TypeEnvKey & other) const; 416 bool operator<(const TypeEnvKey & other) const; 414 417 }; 415 418 416 bool operator==(const TypeInstType & other) const { return base == other.base && formal_usage == other.formal_usage && expr_id == other.expr_id; }419 bool operator==(const TypeInstType & other) const; 417 420 418 421 TypeInstType( -
src/AST/Visitor.hpp
rb77f0e1 r63be3387 33 33 virtual const ast::DirectiveDecl * visit( const ast::DirectiveDecl * ) = 0; 34 34 virtual const ast::StaticAssertDecl * visit( const ast::StaticAssertDecl * ) = 0; 35 virtual const ast::DeclWithType * visit( const ast::InlineMemberDecl * ) = 0; 35 36 virtual const ast::CompoundStmt * visit( const ast::CompoundStmt * ) = 0; 36 37 virtual const ast::Stmt * visit( const ast::ExprStmt * ) = 0;
Note:
See TracChangeset
for help on using the changeset viewer.