Changeset f135b50
- Timestamp:
- Feb 28, 2022, 3:41:44 AM (3 years ago)
- Branches:
- ADT, ast-experimental, enum, master, pthread-emulation, qualifiedEnum
- Children:
- 786c438
- Parents:
- a8ef59e
- Location:
- src
- Files:
-
- 16 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 -
src/CodeGen/CodeGenerator.cc
ra8ef59e rf135b50 274 274 void CodeGenerator::postvisit( EnumDecl * enumDecl ) { 275 275 extension( enumDecl ); 276 output << "enum ";276 output << "enum /* Marker CodeGenerator::EnumDecl */ "; 277 277 genAttributes( enumDecl->get_attributes() ); 278 278 … … 291 291 if ( obj->get_init() ) { 292 292 output << " = "; 293 // In progress 293 294 obj->get_init()->accept( *visitor ); 294 295 } // if -
src/CodeGen/GenType.cc
ra8ef59e rf135b50 254 254 void GenType::postvisit( EnumInstType * enumInst ) { 255 255 typeString = enumInst->name + " " + typeString; 256 if ( options.genC ) typeString = "enum " + typeString;256 if ( options.genC ) typeString = "enum /* Marker GenType::EnumInstType */ " + typeString; 257 257 handleQualifiers( enumInst ); 258 258 } -
src/Common/Eval.cc
ra8ef59e rf135b50 112 112 } 113 113 114 void postvisit( const ast::VariableExpr * expr ) { 114 void postvisit( const ast::VariableExpr * expr ) { // No hit 115 115 if ( const ast::EnumInstType * inst = dynamic_cast<const ast::EnumInstType *>(expr->result.get()) ) { 116 116 if ( const ast::EnumDecl * decl = inst->base ) { -
src/Common/PassVisitor.impl.h
ra8ef59e rf135b50 754 754 755 755 // unlike structs, traits, and unions, enums inject their members into the global scope 756 if ( node->base ) maybeAccept_impl( node->base, *this ); // Need this? Maybe not? 756 757 maybeAccept_impl( node->parameters, *this ); 757 758 maybeAccept_impl( node->members , *this ); -
src/Parser/DeclarationNode.cc
ra8ef59e rf135b50 78 78 delete variable.initializer; 79 79 80 delete type;80 // delete type; 81 81 delete bitfieldWidth; 82 82 … … 253 253 } // DeclarationNode::newAggregate 254 254 255 DeclarationNode * DeclarationNode::newEnum( const string * name, DeclarationNode * constants, bool body, bool ) {255 DeclarationNode * DeclarationNode::newEnum( const string * name, DeclarationNode * constants, bool body, bool typed) { 256 256 DeclarationNode * newnode = new DeclarationNode; 257 257 newnode->type = new TypeData( TypeData::Enum ); … … 272 272 } // DeclarationNode::newName 273 273 274 DeclarationNode * DeclarationNode::newEnumConstant( const string * name, ExpressionNode * constant ) { 274 DeclarationNode * DeclarationNode::newEnumConstant( const string * name, ExpressionNode * constant ) { // Marker 275 275 DeclarationNode * newnode = newName( name ); 276 276 newnode->enumeratorValue.reset( constant ); … … 667 667 } 668 668 669 DeclarationNode * DeclarationNode::addEnumBase( DeclarationNode * o ) { 670 if ( o && o -> type) { 671 type->base= o->type; 672 } 673 delete o; 674 return this; 675 } 676 669 677 DeclarationNode * DeclarationNode::addTypedef() { 670 678 TypeData * newtype = new TypeData( TypeData::Symbolic ); -
src/Parser/ParseNode.h
ra8ef59e rf135b50 265 265 DeclarationNode * addType( DeclarationNode * ); 266 266 DeclarationNode * addTypedef(); 267 DeclarationNode * addEnumBase( DeclarationNode * ); 267 268 DeclarationNode * addAssertions( DeclarationNode * ); 268 269 DeclarationNode * addName( std::string * ); -
src/Parser/StatementNode.cc
ra8ef59e rf135b50 366 366 } // maybe_build_compound 367 367 368 // Question 368 369 Statement * build_asm( bool voltile, Expression * instruction, ExpressionNode * output, ExpressionNode * input, ExpressionNode * clobber, LabelNode * gotolabels ) { 369 370 list< Expression * > out, in; -
src/Parser/TypeData.cc
ra8ef59e rf135b50 918 918 EnumDecl * buildEnum( const TypeData * td, std::list< Attribute * > attributes, LinkageSpec::Spec linkage ) { 919 919 assert( td->kind == TypeData::Enum ); 920 EnumDecl * ret = new EnumDecl( *td->enumeration.name, attributes, linkage ); 921 buildList( td->enumeration.constants, ret->get_members() ); 920 Type* baseType = td->base ? typebuild(td->base) : nullptr; 921 EnumDecl * ret = new EnumDecl( *td->enumeration.name, attributes, linkage, baseType ); 922 buildList( td->enumeration.constants, ret->get_members() ); // enumConstant is both a node and a list 922 923 list< Declaration * >::iterator members = ret->get_members().begin(); 923 for ( const DeclarationNode * cur = td->enumeration. 924 for ( const DeclarationNode * cur = td->enumeration.constants; cur != nullptr; cur = dynamic_cast< DeclarationNode * >( cur->get_next() ), ++members ) { 924 925 if ( cur->has_enumeratorValue() ) { 925 926 ObjectDecl * member = dynamic_cast< ObjectDecl * >(* members); … … 927 928 } // if 928 929 } // for 929 ret->set_body( td->enumeration.body ); 930 ret->set_body( td->enumeration.body ); // Boolean; if it has body 930 931 return ret; 931 932 } // buildEnum -
src/Parser/TypeData.h
ra8ef59e rf135b50 132 132 Initializer * init = nullptr, std::list< class Attribute * > attributes = std::list< class Attribute * >() ); 133 133 FunctionType * buildFunction( const TypeData * ); 134 Declaration * addEnumBase( Declaration *, const TypeData * ); 134 135 void buildKRFunction( const TypeData::Function_t & function ); 135 136 -
src/Parser/parser.yy
ra8ef59e rf135b50 2292 2292 { SemanticError( yylloc, "storage-class and CV qualifiers are not meaningful for enumeration constants, which are const." ); } 2293 2293 // SemanticError( yylloc, "Typed enumeration is currently unimplemented." ); $$ = nullptr; 2294 $$ = DeclarationNode::newEnum( nullptr, $7, true, true ) ->addQualifiers( $5 ); 2294 2295 $$ = DeclarationNode::newEnum( nullptr, $7, true, true ) ->addQualifiers( $5 ) -> addEnumBase( $3 ); 2296 // $$ = DeclarationNode::newEnum( nullptr, $7, true, true ) ->addQualifiers( $5 ); 2295 2297 } 2296 2298 | ENUM '(' cfa_abstract_parameter_declaration ')' attribute_list_opt identifier attribute_list_opt // Question: why attributes/qualifier after identifier … … 2301 2303 '{' enumerator_list comma_opt '}' 2302 2304 { 2303 $$ = DeclarationNode::newEnum( $6, $10, true, true ) -> addQualifiers( $5 ) -> addQualifiers( $7 ); 2305 $$ = DeclarationNode::newEnum( $6, $10, true, true ) -> addQualifiers( $5 ) -> addQualifiers( $7 ) -> addEnumBase( $3 ); 2306 // $$ = DeclarationNode::newEnum( $6, $10, true, true ) -> addQualifiers( $5 ) -> addQualifiers( $7 ); 2304 2307 } 2305 2308 | ENUM '(' cfa_abstract_parameter_declaration ')' attribute_list_opt typedef_name attribute_list_opt '{' enumerator_list comma_opt '}' … … 2307 2310 if ( $3->storageClasses.val != 0 || $3->type->qualifiers.val != 0 ) { SemanticError( yylloc, "storage-class and CV qualifiers are not meaningful for enumeration constants, which are const." ); } 2308 2311 typedefTable.makeTypedef( *$6->name ); 2309 $$ = DeclarationNode::newEnum( $6->name, $9, true, true ) -> addQualifiers( $5 ) -> addQualifiers( $7 ); 2312 $$ = DeclarationNode::newEnum( $6->name, $9, true, true ) -> addQualifiers( $5 ) -> addQualifiers( $7 ) -> addEnumBase( $3 ); 2313 // $$ = DeclarationNode::newEnum( $6->name, $9, true, true ) -> addQualifiers( $5 ) -> addQualifiers( $7 ); 2310 2314 } 2311 2315 | enum_type_nobody -
src/SymTab/Demangle.cc
ra8ef59e rf135b50 252 252 253 253 void GenType::postvisit( EnumInstType * enumInst ) { 254 typeString = "enum " + enumInst->name + " " + typeString;254 typeString = "enum /* Marker demangle::EnumInstType */ " + enumInst->name + " " + typeString; 255 255 handleQualifiers( enumInst ); 256 256 } -
src/SynTree/Declaration.h
ra8ef59e rf135b50 119 119 public: 120 120 Type * type; 121 Initializer * init; 121 Initializer * init; // For Enum, the init is a pointer that contain the enum value; see Parser::TypeData::buildEnum 122 122 Expression * bitfieldWidth; 123 123 … … 335 335 typedef AggregateDecl Parent; 336 336 public: 337 EnumDecl( const std::string & name, const std::list< Attribute * > & attributes = std::list< class Attribute * >(), LinkageSpec::Spec linkage = LinkageSpec::Cforall ) : Parent( name, attributes, linkage ) {} 337 EnumDecl( const std::string & name, 338 const std::list< Attribute * > & attributes = std::list< class Attribute * >(), 339 LinkageSpec::Spec linkage = LinkageSpec::Cforall, 340 Type * baseType = nullptr ) : Parent( name, attributes, linkage ) , base( baseType ){} 338 341 EnumDecl( const EnumDecl & other ) : Parent( other ) {} 339 342 … … 344 347 virtual void accept( Visitor & v ) const override { v.visit( this ); } 345 348 virtual Declaration * acceptMutator( Mutator & m ) override { return m.mutate( this ); } 346 private: 349 Type * base; 347 350 std::unordered_map< std::string, long long int > enumValues; 351 private: 352 // std::unordered_map< std::string, long long int > enumValues; 348 353 virtual const char * typeString() const override; 349 354 }; -
src/SynTree/Visitor.h
ra8ef59e rf135b50 35 35 virtual void visit( UnionDecl * node ) { visit( const_cast<const UnionDecl *>(node) ); } 36 36 virtual void visit( const UnionDecl * aggregateDecl ) = 0; 37 virtual void visit( EnumDecl * node ) { visit( const_cast<const EnumDecl *>(node) ); } 37 virtual void visit( EnumDecl * node ) { visit( const_cast<const EnumDecl *>(node) ); } // Marker 1 38 38 virtual void visit( const EnumDecl * aggregateDecl ) = 0; 39 39 virtual void visit( TraitDecl * node ) { visit( const_cast<const TraitDecl *>(node) ); } … … 190 190 virtual void visit( UnionInstType * node ) { visit( const_cast<const UnionInstType *>(node) ); } 191 191 virtual void visit( const UnionInstType * aggregateUseType ) = 0; 192 virtual void visit( EnumInstType * node ) { visit( const_cast<const EnumInstType *>(node) ); } 192 virtual void visit( EnumInstType * node ) { visit( const_cast<const EnumInstType *>(node) ); } // Marker 2 193 193 virtual void visit( const EnumInstType * aggregateUseType ) = 0; 194 194 virtual void visit( TraitInstType * node ) { visit( const_cast<const TraitInstType *>(node) ); }
Note: See TracChangeset
for help on using the changeset viewer.