Changeset f238fcc2
- Timestamp:
- Mar 21, 2022, 3:17:37 PM (3 years ago)
- Branches:
- ADT, ast-experimental, enum, master, pthread-emulation, qualifiedEnum
- Children:
- 4390fb6
- Parents:
- 3e54399
- Location:
- src
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
src/AST/Convert.cpp
r3e54399 rf238fcc2 1496 1496 getAccept1< ast::type, decltype( old->child ) >( old->child ) 1497 1497 1498 # define GET_ACCEPT_E(child, type) \1499 getAccept1< ast::type, decltype( old->base ) >( old->base )1500 1498 1501 1499 template<typename NewT, typename OldC> … … 1513 1511 # define GET_ACCEPT_V(child, type) \ 1514 1512 getAcceptV< ast::type, decltype( old->child ) >( old->child ) 1513 1514 # define GET_ACCEPT_E(child, type) \ 1515 getAccept1< ast::type, decltype( old->base ) >( old->base ) 1515 1516 1516 1517 template<typename NewT, typename OldC> … … 1714 1715 } 1715 1716 1716 // Marker1717 1717 // Convert SynTree::EnumDecl to AST::EnumDecl 1718 1718 virtual void visit( const EnumDecl * old ) override final { … … 1723 1723 GET_ACCEPT_V(attributes, Attribute), 1724 1724 { old->linkage.val }, 1725 old->base? GET_ACCEPT_E(base, Type) : nullptr,1725 GET_ACCEPT_1(base, Type), 1726 1726 old->enumValues 1727 1727 ); -
src/CodeGen/GenType.cc
r3e54399 rf238fcc2 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/Parser/TypeData.cc
r3e54399 rf238fcc2 918 918 EnumDecl * buildEnum( const TypeData * td, std::list< Attribute * > attributes, LinkageSpec::Spec linkage ) { 919 919 assert( td->kind == TypeData::Enum ); 920 Type * baseType = td->base ? typebuild(td->base) : nullptr;920 Type * baseType = td->base ? typebuild(td->base) : nullptr; 921 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 list922 buildList( td->enumeration.constants, ret->get_members() ); 923 923 list< Declaration * >::iterator members = ret->get_members().begin(); 924 924 for ( const DeclarationNode * cur = td->enumeration.constants; cur != nullptr; cur = dynamic_cast< DeclarationNode * >( cur->get_next() ), ++members ) { … … 926 926 ObjectDecl * member = dynamic_cast< ObjectDecl * >(* members); 927 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 } 928 932 } // if 929 933 } // for -
src/ResolvExpr/ConversionCost.cc
r3e54399 rf238fcc2 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/SynTree/BasicType.cc
r3e54399 rf238fcc2 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/Type.h
r3e54399 rf238fcc2 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 };
Note: See TracChangeset
for help on using the changeset viewer.