- Timestamp:
- Feb 28, 2022, 3:41:44 AM (4 years ago)
- Branches:
- ADT, ast-experimental, enum, master, pthread-emulation, qualifiedEnum
- Children:
- 786c438
- Parents:
- a8ef59e
- Location:
- src/AST
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
src/AST/Convert.cpp
ra8ef59e rf135b50 276 276 decl->parent = get<AggregateDecl>().accept1( node->parent ); 277 277 declPostamble( decl, node ); 278 return nullptr; 278 return nullptr; // ?? 279 279 } 280 280 … … 305 305 } 306 306 307 const ast::Decl * visit( const ast::EnumDecl * node ) override final { 307 const ast::Decl * visit( const ast::EnumDecl * node ) override final { // Marker: what is this for? 308 // Called in ConverterNewToOld 308 309 if ( inCache( node ) ) return nullptr; 309 310 auto decl = new EnumDecl( … … 312 313 LinkageSpec::Spec( node->linkage.val ) 313 314 ); 314 return aggregatePostamble( decl, node ); 315 return aggregatePostamble( decl, node ); // Node info, including members, processed in aggregatePostamble 315 316 } 316 317 … … 1495 1496 getAccept1< ast::type, decltype( old->child ) >( old->child ) 1496 1497 1498 # define GET_ACCEPT_E(child, type) \ 1499 getAccept1< ast::type, decltype( old->base ) >( old->base ) 1500 1497 1501 template<typename NewT, typename OldC> 1498 1502 std::vector< ast::ptr<NewT> > getAcceptV( const OldC& old ) { … … 1710 1714 } 1711 1715 1716 // Marker 1717 // Convert SynTree::EnumDecl to AST::EnumDecl 1712 1718 virtual void visit( const EnumDecl * old ) override final { 1713 1719 if ( inCache( old ) ) return; … … 1716 1722 old->name, 1717 1723 GET_ACCEPT_V(attributes, Attribute), 1718 { old->linkage.val } 1724 { old->linkage.val }, 1725 old->base? GET_ACCEPT_E(base, Type) : nullptr, 1726 old->enumValues 1719 1727 ); 1720 1728 cache.emplace( old, decl ); … … 1726 1734 decl->uniqueId = old->uniqueId; 1727 1735 decl->storage = { old->storageClasses.val }; 1728 1729 1736 this->node = decl; 1730 1737 } -
src/AST/Decl.cpp
ra8ef59e rf135b50 133 133 134 134 auto it = enumValues.find( enumerator->name ); 135 135 136 if ( it != enumValues.end() ) { 136 value = it->second; 137 138 // Handle typed enum by casting the value in (C++) compiler 139 if ( base ) { // A typed enum 140 if ( const BasicType * bt = dynamic_cast<const BasicType *>(base) ) { 141 switch( bt->kind ) { 142 case BasicType::Kind::Bool: value = (bool) it->second; break; 143 case BasicType::Kind::Char: value = (char) it->second; break; 144 case BasicType::Kind::SignedChar: value = (signed char) it->second; break; 145 case BasicType::Kind::UnsignedChar: value = (unsigned char) it->second; break; 146 case BasicType::Kind::ShortSignedInt: value = (short signed int) it->second; break; 147 case BasicType::Kind::SignedInt: value = (signed int) it->second; break; 148 case BasicType::Kind::UnsignedInt: value = (unsigned int) it->second; break; 149 case BasicType::Kind::LongSignedInt: value = (long signed int) it->second; break; 150 case BasicType::Kind::LongUnsignedInt: value = (long unsigned int) it->second; break; 151 case BasicType::Kind::LongLongSignedInt: value = (long long signed int) it->second; break; 152 case BasicType::Kind::LongLongUnsignedInt: value = (long long unsigned int) it->second; break; 153 // TODO: value should be able to handle long long unsigned int 154 155 default: 156 value = it->second; 157 } 158 } 159 } else { 160 value = it->second; 161 } 162 137 163 return true; 138 164 } -
src/AST/Decl.hpp
ra8ef59e rf135b50 302 302 class EnumDecl final : public AggregateDecl { 303 303 public: 304 Type * base; 305 304 306 EnumDecl( const CodeLocation& loc, const std::string& name, 305 std::vector<ptr<Attribute>>&& attrs = {}, Linkage::Spec linkage = Linkage::Cforall ) 306 : AggregateDecl( loc, name, std::move(attrs), linkage ), enumValues() {} 307 std::vector<ptr<Attribute>>&& attrs = {}, Linkage::Spec linkage = Linkage::Cforall, Type * base = nullptr, 308 std::unordered_map< std::string, long long > enumValues = std::unordered_map< std::string, long long >() ) 309 : AggregateDecl( loc, name, std::move(attrs), linkage ), base(base), enumValues(enumValues) {} 307 310 308 311 /// gets the integer value for this enumerator, returning true iff value found 312 // Maybe it is not used in producing the enum value 309 313 bool valueOf( const Decl * enumerator, long long& value ) const; 310 314
Note:
See TracChangeset
for help on using the changeset viewer.