Changes in / [6256891:92538ab]
- Files:
-
- 2 added
- 22 edited
-
doc/proposals/enum.md (added)
-
src/AST/Convert.cpp (modified) (9 diffs)
-
src/AST/Decl.cpp (modified) (1 diff)
-
src/AST/Decl.hpp (modified) (2 diffs)
-
src/AST/Print.cpp (modified) (1 diff)
-
src/CodeGen/CodeGenerator.cc (modified) (3 diffs)
-
src/CodeGen/GenType.cc (modified) (1 diff)
-
src/Common/Eval.cc (modified) (1 diff)
-
src/Common/PassVisitor.impl.h (modified) (1 diff)
-
src/Parser/DeclarationNode.cc (modified) (5 diffs)
-
src/Parser/ParseNode.h (modified) (2 diffs)
-
src/Parser/StatementNode.cc (modified) (1 diff)
-
src/Parser/TypeData.cc (modified) (1 diff)
-
src/Parser/TypeData.h (modified) (1 diff)
-
src/Parser/parser.yy (modified) (4 diffs)
-
src/ResolvExpr/ConversionCost.cc (modified) (2 diffs)
-
src/ResolvExpr/Resolver.cc (modified) (1 diff)
-
src/SymTab/Validate.cc (modified) (2 diffs)
-
src/SynTree/AggregateDecl.cc (modified) (2 diffs)
-
src/SynTree/BasicType.cc (modified) (1 diff)
-
src/SynTree/Declaration.h (modified) (4 diffs)
-
src/SynTree/Type.h (modified) (1 diff)
-
src/SynTree/Visitor.h (modified) (2 diffs)
-
tests/enum_tests/typedIntEnum.c (added)
Legend:
- Unmodified
- Added
- Removed
-
src/AST/Convert.cpp
r6256891 r92538ab 273 273 decl->parent = get<AggregateDecl>().accept1( node->parent ); 274 274 declPostamble( decl, node ); 275 return nullptr; 275 return nullptr; // ?? 276 276 } 277 277 … … 307 307 node->name, 308 308 get<Attribute>().acceptL( node->attributes ), 309 LinkageSpec::Spec( node->linkage.val ) 310 ); 311 return aggregatePostamble( decl, node ); 309 LinkageSpec::Spec( node->linkage.val ), 310 get<Type>().accept1(node->base) 311 ); 312 return aggregatePostamble( decl, node ); // Node info, including members, processed in aggregatePostamble 312 313 } 313 314 … … 1470 1471 return strict_dynamic_cast< ast::Decl * >( node ); 1471 1472 } 1472 1473 1473 1474 ConverterOldToNew() = default; 1474 1475 ConverterOldToNew(const ConverterOldToNew &) = delete; … … 1498 1499 getAccept1< ast::type, decltype( old->child ) >( old->child ) 1499 1500 1501 1500 1502 template<typename NewT, typename OldC> 1501 1503 std::vector< ast::ptr<NewT> > getAcceptV( const OldC& old ) { … … 1512 1514 # define GET_ACCEPT_V(child, type) \ 1513 1515 getAcceptV< ast::type, decltype( old->child ) >( old->child ) 1516 1517 # define GET_ACCEPT_E(child, type) \ 1518 getAccept1< ast::type, decltype( old->base ) >( old->base ) 1514 1519 1515 1520 template<typename NewT, typename OldC> … … 1713 1718 } 1714 1719 1720 // Convert SynTree::EnumDecl to AST::EnumDecl 1715 1721 virtual void visit( const EnumDecl * old ) override final { 1716 1722 if ( inCache( old ) ) return; … … 1719 1725 old->name, 1720 1726 GET_ACCEPT_V(attributes, Attribute), 1721 { old->linkage.val } 1727 { old->linkage.val }, 1728 GET_ACCEPT_1(base, Type), 1729 old->enumValues 1722 1730 ); 1723 1731 cache.emplace( old, decl ); … … 1729 1737 decl->uniqueId = old->uniqueId; 1730 1738 decl->storage = { old->storageClasses.val }; 1731 1732 1739 this->node = decl; 1733 1740 } … … 2767 2774 } 2768 2775 2769 virtual void visit( const EnumInstType * old ) override final { 2770 ast::EnumInstType * ty; 2776 virtual void visit( const EnumInstType * old ) override final { // Here is visiting the EnumInst Decl not the usage. 2777 ast::EnumInstType * ty; 2771 2778 if ( old->baseEnum ) { 2772 ty = new ast::EnumInstType{ 2779 ty = new ast::EnumInstType{ // Probably here: missing the specification of the base 2773 2780 GET_ACCEPT_1( baseEnum, EnumDecl ), 2774 2781 cv( old ), -
src/AST/Decl.cpp
r6256891 r92538ab 136 136 137 137 auto it = enumValues.find( enumerator->name ); 138 138 139 if ( it != enumValues.end() ) { 139 value = it->second; 140 141 // Handle typed enum by casting the value in (C++) compiler 142 // if ( base ) { // A typed enum 143 // if ( const BasicType * bt = dynamic_cast<const BasicType *>(base) ) { 144 // switch( bt->kind ) { 145 // case BasicType::Kind::Bool: value = (bool) it->second; break; 146 // case BasicType::Kind::Char: value = (char) it->second; break; 147 // case BasicType::Kind::SignedChar: value = (signed char) it->second; break; 148 // case BasicType::Kind::UnsignedChar: value = (unsigned char) it->second; break; 149 // case BasicType::Kind::ShortSignedInt: value = (short signed int) it->second; break; 150 // case BasicType::Kind::SignedInt: value = (signed int) it->second; break; 151 // case BasicType::Kind::UnsignedInt: value = (unsigned int) it->second; break; 152 // case BasicType::Kind::LongSignedInt: value = (long signed int) it->second; break; 153 // case BasicType::Kind::LongUnsignedInt: value = (long unsigned int) it->second; break; 154 // case BasicType::Kind::LongLongSignedInt: value = (long long signed int) it->second; break; 155 // case BasicType::Kind::LongLongUnsignedInt: value = (long long unsigned int) it->second; break; 156 // // TODO: value should be able to handle long long unsigned int 157 158 // default: 159 // value = it->second; 160 // } 161 // } 162 // } else { 163 value = it->second; 164 //} 165 140 166 return true; 141 167 } -
src/AST/Decl.hpp
r6256891 r92538ab 302 302 class EnumDecl final : public AggregateDecl { 303 303 public: 304 ptr<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 … … 312 316 313 317 const char * typeString() const override { return aggrString( Enum ); } 318 319 bool isTyped() {return base && base.get();} 314 320 315 321 private: -
src/AST/Print.cpp
r6256891 r92538ab 210 210 } 211 211 212 auto ptrToEnum = dynamic_cast<const ast::EnumDecl *>(node); 213 if ( ! short_mode && ptrToEnum && ptrToEnum->base ) { 214 os << endl << indent << ".. with (enum) base" << endl; 215 ++indent; 216 ptrToEnum->base->accept( *this ); 217 --indent; 218 } 219 212 220 os << endl; 213 221 } -
src/CodeGen/CodeGenerator.cc
r6256891 r92538ab 274 274 void CodeGenerator::postvisit( EnumDecl * enumDecl ) { 275 275 extension( enumDecl ); 276 output << "enum ";277 genAttributes( enumDecl->get_attributes() );278 279 output << enumDecl->get_name();280 281 276 std::list< Declaration* > &memb = enumDecl->get_members(); 282 283 if ( ! memb.empty() ) { 284 output << " {" << endl; 285 286 ++indent; 277 if (enumDecl->base && ! memb.empty() && 278 (dynamic_cast<BasicType *>(enumDecl->base) 279 && !(dynamic_cast<BasicType *>(enumDecl->base)->kind == BasicType::Kind::SignedInt))) { 280 ObjectDecl * last = nullptr; 287 281 for ( std::list< Declaration* >::iterator i = memb.begin(); i != memb.end(); i++) { 288 282 ObjectDecl * obj = dynamic_cast< ObjectDecl* >( *i ); 289 283 assert( obj ); 290 output << indent << mangleName( obj ); 284 output << "static const "; 285 output << genType(enumDecl->base, "", options) << " "; 286 output << mangleName( obj ) << " "; 287 output << " = "; 288 output << "(" << genType(enumDecl->base, "", options) << ")";; 291 289 if ( obj->get_init() ) { 292 output << " = ";293 290 obj->get_init()->accept( *visitor ); 294 } // if 295 output << "," << endl; 291 } else { 292 if (last == nullptr) { 293 output << 0; 294 } else { 295 output << mangleName(last) << " + 1"; 296 } 297 } // if— 298 output << ";" << endl; 299 last = obj; 296 300 } // for 297 301 } else { 302 output << "enum "; 303 genAttributes( enumDecl->get_attributes() ); 304 305 output << enumDecl->get_name(); 306 307 if ( ! memb.empty() ) { 308 output << " {" << endl; 309 310 ++indent; 311 for ( std::list< Declaration* >::iterator i = memb.begin(); i != memb.end(); i++) { 312 ObjectDecl * obj = dynamic_cast< ObjectDecl* >( *i ); 313 assert( obj ); 314 output << indent << mangleName( obj ); 315 if ( obj->get_init() ) { 316 output << " = "; 317 obj->get_init()->accept( *visitor ); 318 } // if 319 output << "," << endl; 320 } // for 298 321 --indent; 299 300 322 output << indent << "}"; 323 } // if 301 324 } // if 302 325 } … … 347 370 des->accept( *visitor ); 348 371 } else { 349 // otherwise, it has to be a ConstantExpr or CastExpr, initializing array ele emnt372 // otherwise, it has to be a ConstantExpr or CastExpr, initializing array element 350 373 output << "["; 351 374 des->accept( *visitor ); … … 661 684 output << opInfo->symbol; 662 685 } else { 686 // if (dynamic_cast<EnumInstType *>(variableExpr->get_var()->get_type()) 687 // && dynamic_cast<EnumInstType *>(variableExpr->get_var()->get_type())->baseEnum->base) { 688 // output << '(' <<genType(dynamic_cast<EnumInstType *>(variableExpr->get_var()->get_type())->baseEnum->base, "", options) << ')'; 689 // } 663 690 output << mangleName( variableExpr->get_var() ); 664 691 } // if -
src/CodeGen/GenType.cc
r6256891 r92538ab 253 253 254 254 void GenType::postvisit( EnumInstType * enumInst ) { 255 typeString = enumInst->name + " " + typeString; 256 if ( options.genC ) typeString = "enum " + typeString; 255 if ( enumInst->baseEnum->base 256 && dynamic_cast<BasicType *>(enumInst->baseEnum->base) 257 && dynamic_cast<BasicType *>(enumInst->baseEnum->base)->kind != BasicType::Kind::SignedInt) { 258 typeString = genType(enumInst->baseEnum->base, "", options) + typeString; 259 } else { 260 typeString = enumInst->name + " " + typeString; 261 if ( options.genC ) { 262 typeString = "enum " + typeString; 263 } 264 } 257 265 handleQualifiers( enumInst ); 258 266 } -
src/Common/Eval.cc
r6256891 r92538ab 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
r6256891 r92538ab 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
r6256891 r92538ab 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 ) {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 ); … … 263 263 } // DeclarationNode::newEnum 264 264 265 266 265 267 DeclarationNode * DeclarationNode::newName( const string * name ) { 266 268 DeclarationNode * newnode = new DeclarationNode; … … 270 272 } // DeclarationNode::newName 271 273 272 DeclarationNode * DeclarationNode::newEnumConstant( const string * name, ExpressionNode * constant ) { 274 DeclarationNode * DeclarationNode::newEnumConstant( const string * name, ExpressionNode * constant ) { // Marker 273 275 DeclarationNode * newnode = newName( name ); 274 276 newnode->enumeratorValue.reset( constant ); … … 665 667 } 666 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 667 677 DeclarationNode * DeclarationNode::addTypedef() { 668 678 TypeData * newtype = new TypeData( TypeData::Symbolic ); -
src/Parser/ParseNode.h
r6256891 r92538ab 235 235 static DeclarationNode * newFunction( const std::string * name, DeclarationNode * ret, DeclarationNode * param, StatementNode * body ); 236 236 static DeclarationNode * newAggregate( AggregateDecl::Aggregate kind, const std::string * name, ExpressionNode * actuals, DeclarationNode * fields, bool body ); 237 static DeclarationNode * newEnum( const std::string * name, DeclarationNode * constants, bool body );237 static DeclarationNode * newEnum( const std::string * name, DeclarationNode * constants, bool body, bool typed ); 238 238 static DeclarationNode * newEnumConstant( const std::string * name, ExpressionNode * constant ); 239 239 static DeclarationNode * newName( const std::string * ); … … 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
r6256891 r92538ab 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
r6256891 r92538ab 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 ); 920 Type * baseType = td->base ? typebuild(td->base) : nullptr; 921 EnumDecl * ret = new EnumDecl( *td->enumeration.name, attributes, linkage, baseType ); 921 922 buildList( td->enumeration.constants, ret->get_members() ); 922 923 list< Declaration * >::iterator members = ret->get_members().begin(); 923 for ( const DeclarationNode * cur = td->enumeration. constants; cur != nullptr; cur = dynamic_cast< DeclarationNode * >( cur->get_next() ), ++members ) {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); 926 927 member->set_init( new SingleInit( maybeMoveBuild< Expression >( cur->consume_enumeratorValue() ) ) ); 928 } else { 929 if ( baseType && (!dynamic_cast<BasicType *>(baseType) || !dynamic_cast<BasicType *>(baseType)->isWholeNumber())) { 930 SemanticError( td->location, "A non whole number enum value decl must be explicitly initialized." ); 931 } 927 932 } // if 928 933 } // for 929 ret->set_body( td->enumeration.body ); 934 ret->set_body( td->enumeration.body ); // Boolean; if it has body 930 935 return ret; 931 936 } // buildEnum -
src/Parser/TypeData.h
r6256891 r92538ab 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
r6256891 r92538ab 2303 2303 ; 2304 2304 2305 enum_type: // enum2305 enum_type: // static DeclarationNode * newEnum( const std::string * name, DeclarationNode * constants, bool body, bool typed ); // enum 2306 2306 ENUM attribute_list_opt '{' enumerator_list comma_opt '}' 2307 { $$ = DeclarationNode::newEnum( nullptr, $4, true )->addQualifiers( $2 ); }2307 { $$ = DeclarationNode::newEnum( nullptr, $4, true, false )->addQualifiers( $2 ); } 2308 2308 | ENUM attribute_list_opt identifier 2309 2309 { typedefTable.makeTypedef( *$3 ); } 2310 2310 '{' enumerator_list comma_opt '}' 2311 { $$ = DeclarationNode::newEnum( $3, $6, true )->addQualifiers( $2 ); }2311 { $$ = DeclarationNode::newEnum( $3, $6, true, false )->addQualifiers( $2 ); } 2312 2312 | ENUM attribute_list_opt typedef_name // unqualified type name 2313 2313 '{' enumerator_list comma_opt '}' 2314 { $$ = DeclarationNode::newEnum( $3->name, $5, true )->addQualifiers( $2 ); }2314 { $$ = DeclarationNode::newEnum( $3->name, $5, true, false )->addQualifiers( $2 ); } 2315 2315 | ENUM '(' cfa_abstract_parameter_declaration ')' attribute_list_opt '{' enumerator_list comma_opt '}' 2316 2316 { 2317 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." ); } 2318 SemanticError( yylloc, "Typed enumeration is currently unimplemented." ); $$ = nullptr; 2319 } 2320 | ENUM '(' cfa_abstract_parameter_declaration ')' attribute_list_opt identifier attribute_list_opt 2317 if ( $3->storageClasses.val != 0 || $3->type->qualifiers.val != 0 ) 2318 { SemanticError( yylloc, "storage-class and CV qualifiers are not meaningful for enumeration constants, which are const." ); } 2319 // SemanticError( yylloc, "Typed enumeration is currently unimplemented." ); $$ = nullptr; 2320 2321 $$ = DeclarationNode::newEnum( nullptr, $7, true, true ) ->addQualifiers( $5 ) -> addEnumBase( $3 ); 2322 // $$ = DeclarationNode::newEnum( nullptr, $7, true, true ) ->addQualifiers( $5 ); 2323 } 2324 | ENUM '(' cfa_abstract_parameter_declaration ')' attribute_list_opt identifier attribute_list_opt // Question: why attributes/qualifier after identifier 2321 2325 { 2322 2326 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." ); } … … 2325 2329 '{' enumerator_list comma_opt '}' 2326 2330 { 2327 SemanticError( yylloc, "Typed enumeration is currently unimplemented." ); $$ = nullptr; 2331 $$ = DeclarationNode::newEnum( $6, $10, true, true ) -> addQualifiers( $5 ) -> addQualifiers( $7 ) -> addEnumBase( $3 ); 2332 // $$ = DeclarationNode::newEnum( $6, $10, true, true ) -> addQualifiers( $5 ) -> addQualifiers( $7 ); 2328 2333 } 2329 2334 | ENUM '(' cfa_abstract_parameter_declaration ')' attribute_list_opt typedef_name attribute_list_opt '{' enumerator_list comma_opt '}' … … 2331 2336 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." ); } 2332 2337 typedefTable.makeTypedef( *$6->name ); 2333 SemanticError( yylloc, "Typed enumeration is currently unimplemented." ); $$ = nullptr; 2338 $$ = DeclarationNode::newEnum( $6->name, $9, true, true ) -> addQualifiers( $5 ) -> addQualifiers( $7 ) -> addEnumBase( $3 ); 2339 // $$ = DeclarationNode::newEnum( $6->name, $9, true, true ) -> addQualifiers( $5 ) -> addQualifiers( $7 ); 2334 2340 } 2335 2341 | enum_type_nobody … … 2338 2344 enum_type_nobody: // enum - {...} 2339 2345 ENUM attribute_list_opt identifier 2340 { typedefTable.makeTypedef( *$3 ); $$ = DeclarationNode::newEnum( $3, 0, false )->addQualifiers( $2 ); }2346 { typedefTable.makeTypedef( *$3 ); $$ = DeclarationNode::newEnum( $3, 0, false, false )->addQualifiers( $2 ); } 2341 2347 | ENUM attribute_list_opt type_name // qualified type name 2342 { typedefTable.makeTypedef( *$3->type->symbolic.name ); $$ = DeclarationNode::newEnum( $3->type->symbolic.name, 0, false )->addQualifiers( $2 ); }2348 { typedefTable.makeTypedef( *$3->type->symbolic.name ); $$ = DeclarationNode::newEnum( $3->type->symbolic.name, 0, false, false )->addQualifiers( $2 ); } 2343 2349 ; 2344 2350 -
src/ResolvExpr/ConversionCost.cc
r6256891 r92538ab 333 333 } else if ( dynamic_cast< const EnumInstType * >( dest ) ) { 334 334 // xxx - not positive this is correct, but appears to allow casting int => enum 335 cost = Cost::unsafe; 335 // TODO 336 EnumDecl * decl = dynamic_cast< const EnumInstType * >( dest )->baseEnum; 337 if ( decl->base ) { 338 cost = Cost::infinity; 339 } else { 340 cost = Cost::unsafe; 341 } // if 336 342 } // if 337 343 // no cases for zero_t/one_t because it should not be possible to convert int, etc. to zero_t/one_t. … … 610 616 } else if ( dynamic_cast< const ast::EnumInstType * >( dst ) ) { 611 617 // xxx - not positive this is correct, but appears to allow casting int => enum 612 cost = Cost::unsafe; 618 const ast::EnumDecl * decl = (dynamic_cast< const ast::EnumInstType * >( dst ))->base.get(); 619 if ( decl->base ) { 620 cost = Cost::infinity; 621 } else { 622 cost = Cost::unsafe; 623 } // if 613 624 } 614 625 } -
src/ResolvExpr/Resolver.cc
r6256891 r92538ab 1476 1476 // enumerator initializers should not use the enum type to initialize, since the 1477 1477 // enum type is still incomplete at this point. Use `int` instead. 1478 objectDecl = fixObjectType(objectDecl, context); 1479 currentObject = ast::CurrentObject{ 1480 objectDecl->location, new ast::BasicType{ ast::BasicType::SignedInt } }; 1478 1479 if (dynamic_cast< const ast::EnumInstType * >( objectDecl->get_type() )->base->base) { // const ast::PointerType & 1480 const ast::Type * enumBase = (dynamic_cast< const ast::EnumInstType * >( objectDecl->get_type() )->base->base.get()); 1481 const ast::PointerType * enumBaseAsPtr = dynamic_cast<const ast::PointerType *>(enumBase); 1482 1483 if ( enumBaseAsPtr ) { 1484 const ast::Type * pointerBase = enumBaseAsPtr->base.get(); 1485 if ( dynamic_cast<const ast::BasicType *>(pointerBase) ) { 1486 objectDecl = fixObjectType(objectDecl, symtab); 1487 if (dynamic_cast<const ast::BasicType *>(pointerBase)->kind == ast::BasicType::Char) 1488 currentObject = ast::CurrentObject{ 1489 objectDecl->location, new ast::PointerType{ 1490 new ast::BasicType{ ast::BasicType::Char } 1491 } }; 1492 } else { 1493 objectDecl = fixObjectType(objectDecl, symtab); 1494 currentObject = ast::CurrentObject{objectDecl->location, new ast::BasicType{ ast::BasicType::SignedInt } }; 1495 } 1496 } 1497 } else { 1498 objectDecl = fixObjectType(objectDecl, symtab); 1499 currentObject = ast::CurrentObject{ 1500 objectDecl->location, new ast::BasicType{ ast::BasicType::SignedInt } }; 1501 } 1502 1481 1503 } 1482 1504 else { -
src/SymTab/Validate.cc
r6256891 r92538ab 974 974 // need to resolve enumerator initializers early so that other passes that determine if an expression is constexpr have the appropriate information. 975 975 SingleInit * init = strict_dynamic_cast<SingleInit *>( field->init ); 976 ResolvExpr::findSingleExpression( init->value, new BasicType( Type::Qualifiers(), BasicType::SignedInt ), indexer ); 976 if ( !enumDecl->base || dynamic_cast<BasicType *>(enumDecl->base)) 977 ResolvExpr::findSingleExpression( init->value, new BasicType( Type::Qualifiers(), BasicType::SignedInt ), indexer ); 978 else { 979 if (dynamic_cast<PointerType *>(enumDecl->base)) { 980 auto typePtr = dynamic_cast<PointerType *>(enumDecl->base); 981 ResolvExpr::findSingleExpression( init->value, 982 new PointerType( Type::Qualifiers(), typePtr->base ), indexer ); 983 } else { 984 ResolvExpr::findSingleExpression( init->value, new BasicType( Type::Qualifiers(), BasicType::SignedInt ), indexer ); 985 } 986 } 987 977 988 } 978 989 } 990 979 991 } // if 980 992 } … … 1240 1252 declsToAddBefore.push_back( new UnionDecl( aggDecl->name, noAttributes, tyDecl->linkage ) ); 1241 1253 } else if ( EnumInstType * enumDecl = dynamic_cast< EnumInstType * >( designatorType ) ) { 1242 declsToAddBefore.push_back( new EnumDecl( enumDecl->name, noAttributes, tyDecl->linkage ) ); 1254 // declsToAddBefore.push_back( new EnumDecl( enumDecl->name, noAttributes, tyDecl->linkage, enumDecl->baseEnum->base ) ); 1255 if (enumDecl->baseEnum) { 1256 declsToAddBefore.push_back( new EnumDecl( enumDecl->name, noAttributes, tyDecl->linkage, enumDecl->baseEnum->base ) ); 1257 } else { 1258 declsToAddBefore.push_back( new EnumDecl( enumDecl->name, noAttributes, tyDecl->linkage ) ); 1259 } 1243 1260 } // if 1244 1261 return tyDecl->clone(); -
src/SynTree/AggregateDecl.cc
r6256891 r92538ab 59 59 } // if 60 60 os << " with body " << has_body(); 61 62 61 if ( ! parameters.empty() ) { 63 62 os << endl << indent << "... with parameters" << endl; … … 106 105 const char * EnumDecl::typeString() const { return aggrString( Enum ); } 107 106 107 void EnumDecl::print( std::ostream & os, Indenter indent ) const { 108 AggregateDecl::print(os, indent); 109 os << " with base? " << (base? "True" : "False") << std::endl; 110 if ( base ) { 111 os << "Base Type of Enum:" << std::endl; 112 base->print(os, indent); 113 } 114 os << std::endl << "End of EnumDecl::print" << std::endl; 115 } 116 108 117 const char * TraitDecl::typeString() const { return aggrString( Trait ); } 109 118 -
src/SynTree/BasicType.cc
r6256891 r92538ab 29 29 } 30 30 31 bool BasicType::isWholeNumber() const { 32 return kind == Bool || 33 kind ==Char || 34 kind == SignedChar || 35 kind == UnsignedChar || 36 kind == ShortSignedInt || 37 kind == ShortUnsignedInt || 38 kind == SignedInt || 39 kind == UnsignedInt || 40 kind == LongSignedInt || 41 kind == LongUnsignedInt || 42 kind == LongLongSignedInt || 43 kind ==LongLongUnsignedInt || 44 kind == SignedInt128 || 45 kind == UnsignedInt128; 46 } 47 31 48 bool BasicType::isInteger() const { 32 49 return kind <= UnsignedInt128; -
src/SynTree/Declaration.h
r6256891 r92538ab 144 144 virtual void print( std::ostream & os, Indenter indent = {} ) const override; 145 145 virtual void printShort( std::ostream & os, Indenter indent = {} ) const override; 146 147 // TODO: Move to the right place 148 void checkAssignedValue() const; 146 149 }; 147 150 … … 287 290 AggregateDecl * set_body( bool body ) { AggregateDecl::body = body; return this; } 288 291 289 virtual void print( std::ostream & os, Indenter indent = {} ) const override final;292 virtual void print( std::ostream & os, Indenter indent = {} ) const override; 290 293 virtual void printShort( std::ostream & os, Indenter indent = {} ) const override; 291 294 protected: … … 335 338 typedef AggregateDecl Parent; 336 339 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 ) {} 338 EnumDecl( const EnumDecl & other ) : Parent( other ) {} 340 EnumDecl( const std::string & name, 341 const std::list< Attribute * > & attributes = std::list< class Attribute * >(), 342 LinkageSpec::Spec linkage = LinkageSpec::Cforall, 343 Type * baseType = nullptr ) : Parent( name, attributes, linkage ) , base( baseType ){} 344 EnumDecl( const EnumDecl & other ) : Parent( other ), base( other.base ) {} 339 345 340 346 bool valueOf( Declaration * enumerator, long long int & value ); … … 344 350 virtual void accept( Visitor & v ) const override { v.visit( this ); } 345 351 virtual Declaration * acceptMutator( Mutator & m ) override { return m.mutate( this ); } 346 private: 352 Type * base; 347 353 std::unordered_map< std::string, long long int > enumValues; 354 virtual void print( std::ostream & os, Indenter indent = {} ) const override final; 355 private: 356 // std::unordered_map< std::string, long long int > enumValues; 348 357 virtual const char * typeString() const override; 349 358 }; -
src/SynTree/Type.h
r6256891 r92538ab 268 268 virtual Type *acceptMutator( Mutator & m ) override { return m.mutate( this ); } 269 269 virtual void print( std::ostream & os, Indenter indent = {} ) const override; 270 270 bool isWholeNumber() const; 271 271 bool isInteger() const; 272 272 }; -
src/SynTree/Visitor.h
r6256891 r92538ab 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.