Changes in / [13edbac:2856982c]
- Files:
-
- 1 deleted
- 26 edited
-
src/AST/Convert.cpp (modified) (2 diffs)
-
src/AST/Decl.hpp (modified) (1 diff)
-
src/AST/Fwd.hpp (modified) (1 diff)
-
src/AST/Pass.hpp (modified) (1 diff)
-
src/AST/Pass.impl.hpp (modified) (1 diff)
-
src/AST/Print.cpp (modified) (1 diff)
-
src/AST/Visitor.hpp (modified) (1 diff)
-
src/Common/CodeLocationTools.cpp (modified) (1 diff)
-
src/Common/PassVisitor.h (modified) (2 diffs)
-
src/Common/PassVisitor.impl.h (modified) (1 diff)
-
src/Parser/DeclarationNode.cc (modified) (2 diffs)
-
src/Parser/ExpressionNode.cc (modified) (1 diff)
-
src/Parser/TypeData.cc (modified) (1 diff)
-
src/ResolvExpr/CommonType.cc (modified) (2 diffs)
-
src/ResolvExpr/ConversionCost.cc (modified) (1 diff)
-
src/SynTree/Declaration.h (modified) (1 diff)
-
src/SynTree/InlineValueDecl.cc (deleted)
-
src/SynTree/Mutator.h (modified) (1 diff)
-
src/SynTree/SynTree.h (modified) (1 diff)
-
src/SynTree/Visitor.h (modified) (1 diff)
-
src/SynTree/module.mk (modified) (1 diff)
-
src/Validate/EnumAndPointerDecay.cpp (modified) (3 diffs)
-
src/Validate/LinkReferenceToTypes.cpp (modified) (2 diffs)
-
tests/enum_tests/.expect/enumInlineValue.txt (modified) (1 diff)
-
tests/enum_tests/.expect/qualifiedEnum.cfa (modified) (1 diff)
-
tests/enum_tests/enumInlineValue.cfa (modified) (1 diff)
-
tests/enum_tests/qualifiedEnum.cfa (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
src/AST/Convert.cpp
r13edbac r2856982c 234 234 } 235 235 return declWithTypePostamble( decl, node ); 236 }237 238 // InlineValueDecl vanish after EnumAndPointerDecay pass so no necessary to implement NewToOld239 const ast::DeclWithType * visit( const ast::InlineValueDecl * node ) override final {240 assert( false );241 (void) node;242 return nullptr;243 236 } 244 237 … … 1870 1863 } 1871 1864 1872 virtual void visit( const InlineValueDecl * old ) override final {1873 if ( inCache( old ) ) {1874 return;1875 }1876 auto&& type = GET_ACCEPT_1(type, Type);1877 auto&& attr = GET_ACCEPT_V(attributes, Attribute);1878 1879 auto decl = new ast::InlineValueDecl(1880 old->location,1881 old->name,1882 type,1883 { old->get_storageClasses().val },1884 { old->linkage.val },1885 std::move(attr),1886 { old->get_funcSpec().val }1887 );1888 cache.emplace(old, decl);1889 assert(cache.find( old ) != cache.end());1890 decl->scopeLevel = old->scopeLevel;1891 decl->mangleName = old->mangleName;1892 decl->isDeleted = old->isDeleted;1893 decl->asmName = GET_ACCEPT_1(asmName, Expr);1894 decl->uniqueId = old->uniqueId;1895 decl->extension = old->extension;1896 1897 this->node = decl;1898 }1899 1900 1865 virtual void visit( const CompoundStmt * old ) override final { 1901 1866 if ( inCache( old ) ) return; -
src/AST/Decl.hpp
r13edbac r2856982c 414 414 }; 415 415 416 class InlineValueDecl final : public DeclWithType {417 public:418 ptr<Type> type;419 420 InlineValueDecl( const CodeLocation & loc, const std::string & name, const Type * type,421 Storage::Classes storage = {}, Linkage::Spec linkage = Linkage::Cforall,422 std::vector< ptr<Attribute> > && attrs = {}, Function::Specs fs = {} )423 : DeclWithType( loc, name, storage, linkage, std::move(attrs), fs ), type( type ) {}424 425 const Type * get_type() const override { return type; }426 void set_type( const Type * ty ) override { type = ty; }427 428 const DeclWithType * accept( Visitor& v ) const override { return v.visit( this ); }429 private:430 InlineValueDecl * clone() const override { return new InlineValueDecl{ *this }; }431 MUTATE_FRIEND432 };433 416 } 434 417 -
src/AST/Fwd.hpp
r13edbac r2856982c 37 37 class DirectiveDecl; 38 38 class StaticAssertDecl; 39 class InlineValueDecl;40 39 41 40 class Stmt; -
src/AST/Pass.hpp
r13edbac r2856982c 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::InlineValueDecl * ) override final;144 143 const ast::CompoundStmt * visit( const ast::CompoundStmt * ) override final; 145 144 const ast::Stmt * visit( const ast::ExprStmt * ) override final; -
src/AST/Pass.impl.hpp
r13edbac r2856982c 803 803 804 804 //-------------------------------------------------------------------------- 805 // DeclWithType806 template< typename core_t >807 const ast::DeclWithType * ast::Pass< core_t >::visit( const ast::InlineValueDecl * node ) {808 VISIT_START( node );809 810 if ( __visit_children() ) {811 {812 guard_symtab guard { *this };813 maybe_accept( node, &InlineValueDecl::type );814 }815 }816 817 VISIT_END( DeclWithType, node );818 }819 820 //--------------------------------------------------------------------------821 805 // CompoundStmt 822 806 template< typename core_t > -
src/AST/Print.cpp
r13edbac r2856982c 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::InlineValueDecl * node ) override final {404 os << "inline ";405 if ( ! node->name.empty() ) os << node->name;406 407 400 return node; 408 401 } -
src/AST/Visitor.hpp
r13edbac r2856982c 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::InlineValueDecl * ) = 0;36 35 virtual const ast::CompoundStmt * visit( const ast::CompoundStmt * ) = 0; 37 36 virtual const ast::Stmt * visit( const ast::ExprStmt * ) = 0; -
src/Common/CodeLocationTools.cpp
r13edbac r2856982c 111 111 macro(DirectiveDecl, DirectiveDecl) \ 112 112 macro(StaticAssertDecl, StaticAssertDecl) \ 113 macro(InlineValueDecl, DeclWithType) \114 113 macro(CompoundStmt, CompoundStmt) \ 115 114 macro(ExprStmt, Stmt) \ -
src/Common/PassVisitor.h
r13edbac r2856982c 81 81 virtual void visit( StaticAssertDecl * assertDecl ) override final; 82 82 virtual void visit( const StaticAssertDecl * assertDecl ) override final; 83 virtual void visit( InlineValueDecl * valueDecl ) override final;84 virtual void visit( const InlineValueDecl * valueDecl ) override final;85 83 86 84 virtual void visit( CompoundStmt * compoundStmt ) override final; … … 275 273 virtual DirectiveDecl * mutate( DirectiveDecl * directiveDecl ) override final; 276 274 virtual StaticAssertDecl * mutate( StaticAssertDecl * assertDecl ) override final; 277 virtual DeclarationWithType * mutate( InlineValueDecl * valueDecl ) override final;278 275 279 276 virtual CompoundStmt * mutate( CompoundStmt * compoundStmt ) override final; -
src/Common/PassVisitor.impl.h
r13edbac r2856982c 1047 1047 1048 1048 //-------------------------------------------------------------------------- 1049 // InlineValueDecl1050 template< typename pass_type >1051 void PassVisitor< pass_type >::visit( InlineValueDecl * node ) {1052 VISIT_START( node );1053 1054 maybeAccept_impl( node->type, *this );1055 1056 VISIT_END( node );1057 }1058 1059 template< typename pass_type >1060 void PassVisitor< pass_type >::visit( const InlineValueDecl * node ) {1061 VISIT_START( node );1062 1063 maybeAccept_impl( node->type, *this );1064 1065 VISIT_END( node );1066 }1067 1068 template< typename pass_type >1069 DeclarationWithType * PassVisitor< pass_type >::mutate( InlineValueDecl * node ) {1070 MUTATE_START( node );1071 1072 maybeMutate_impl( node->type, *this );1073 1074 MUTATE_END( DeclarationWithType, node );1075 }1076 1077 //--------------------------------------------------------------------------1078 1049 // CompoundStmt 1079 1050 template< typename pass_type > -
src/Parser/DeclarationNode.cc
r13edbac r2856982c 27 27 #include "SynTree/LinkageSpec.h" // for Spec, linkageName, Cforall 28 28 #include "SynTree/Attribute.h" // for Attribute 29 #include "SynTree/Declaration.h" // for TypeDecl, ObjectDecl, InlineValueDecl,Declaration29 #include "SynTree/Declaration.h" // for TypeDecl, ObjectDecl, Declaration 30 30 #include "SynTree/Expression.h" // for Expression, ConstantExpr 31 31 #include "SynTree/Statement.h" // for AsmStmt … … 1165 1165 SemanticError( this, "invalid function specifier for " ); 1166 1166 } // if 1167 if ( enumInLine ) {1168 return new InlineValueDecl( *name, storageClasses, linkage, nullptr );1169 } // if1170 1167 assertf( name, "ObjectDecl must a have name\n" ); 1171 1168 return (new ObjectDecl( *name, storageClasses, linkage, maybeBuild< Expression >( bitfieldWidth ), nullptr, maybeBuild< Initializer >( initializer ) ))->set_asmName( asmName )->set_extension( extension ); -
src/Parser/ExpressionNode.cc
r13edbac r2856982c 519 519 } 520 520 } 521 return new QualifiedNameExpr( newDecl, name->name ); 521 auto ret = new QualifiedNameExpr( newDecl, name->name ); 522 if ( auto e = dynamic_cast<EnumDecl*>(newDecl) ) { 523 auto enumInst = new EnumInstType( Type::Qualifiers(), e ); 524 auto obj = new ObjectDecl( name->name, Type::StorageClasses(), LinkageSpec::Cforall, nullptr, enumInst, nullptr ); 525 } 526 return ret; 522 527 } 523 528 -
src/Parser/TypeData.cc
r13edbac r2856982c 925 925 for ( const DeclarationNode * cur = td->enumeration.constants; cur != nullptr; cur = dynamic_cast< DeclarationNode * >( cur->get_next() ), ++members ) { 926 926 if ( cur->enumInLine ) { 927 // Do Nothing 928 } else if ( ret->isTyped && !ret->base && cur->has_enumeratorValue() ) { 927 // Tell the compiler this is a inline value placeholder 928 ObjectDecl * member = dynamic_cast< ObjectDecl* >(* members); 929 member->enumInLine = true; 930 } 931 if ( ret->isTyped && !ret->base && cur->has_enumeratorValue() ) { 929 932 SemanticError( td->location, "Enumerator of enum(void) cannot have an explicit initializer value." ); 930 933 } else if ( cur->has_enumeratorValue() ) { -
src/ResolvExpr/CommonType.cc
r13edbac r2856982c 991 991 add_qualifiers( result, type2->qualifiers ); 992 992 } else { 993 // xxx - does unifying a ref with typed enumInst makes sense? 993 994 if (!dynamic_cast<const ast::EnumInstType *>(type2)) 994 995 result = commonType( type2, ref, tenv, need, have, open, widen, symtab ); … … 1009 1010 1010 1011 void postvisit( const ast::EnumInstType * enumInst ) { 1012 // reuse BasicType/EnumInstType common type by swapping 1013 // xxx - is this already handled by unify? 1011 1014 if (!dynamic_cast<const ast::EnumInstType *>(type2)) 1012 1015 result = commonType( type2, enumInst, tenv, need, have, open, widen, symtab); -
src/ResolvExpr/ConversionCost.cc
r13edbac r2856982c 720 720 costCalc( baseType, dst, srcIsLvalue, symtab, env ); 721 721 } else { 722 (void)enumInstType; 722 723 static ast::ptr<ast::BasicType> integer = { new ast::BasicType( ast::BasicType::SignedInt ) }; 723 724 cost = costCalc( integer, dst, srcIsLvalue, symtab, env ); -
src/SynTree/Declaration.h
r13edbac r2856982c 449 449 }; 450 450 451 452 class InlineValueDecl : public DeclarationWithType {453 typedef DeclarationWithType Parent;454 public:455 Type * type;456 457 InlineValueDecl( const std::string & name, Type::StorageClasses scs, LinkageSpec::Spec linkage, Type * type,458 const std::list< Attribute * > attributes = std::list< Attribute * >(), Type::FuncSpecifiers fs = Type::FuncSpecifiers() );459 InlineValueDecl( const InlineValueDecl & other );460 virtual ~InlineValueDecl();461 462 virtual Type * get_type() const override { return type; }463 virtual void set_type(Type * newType) override { type = newType; }464 465 static InlineValueDecl * newInlineValueDecl( const std::string & name, Type * type );466 467 virtual InlineValueDecl * clone() const override { return new InlineValueDecl( *this ); }468 virtual void accept( Visitor & v ) override { v.visit( this ); }469 virtual void accept( Visitor & v ) const override { v.visit( this ); }470 virtual DeclarationWithType * acceptMutator( Mutator & m ) override { return m.mutate( this ); }471 virtual void print( std::ostream & os, Indenter indent = {} ) const override;472 virtual void printShort( std::ostream & os, Indenter indent = {} ) const override;473 474 };475 476 451 std::ostream & operator<<( std::ostream & os, const TypeDecl::Data & data ); 477 452 -
src/SynTree/Mutator.h
r13edbac r2856982c 36 36 virtual DirectiveDecl * mutate( DirectiveDecl * directiveDecl ) = 0; 37 37 virtual StaticAssertDecl * mutate( StaticAssertDecl * assertDecl ) = 0; 38 virtual DeclarationWithType * mutate( InlineValueDecl * inlineValueDecl ) = 0;39 38 40 39 virtual CompoundStmt * mutate( CompoundStmt * compoundStmt ) = 0; -
src/SynTree/SynTree.h
r13edbac r2856982c 38 38 class DirectiveDecl; 39 39 class StaticAssertDecl; 40 class InlineValueDecl;41 40 42 41 class Statement; -
src/SynTree/Visitor.h
r13edbac r2856982c 49 49 virtual void visit( StaticAssertDecl * node ) { visit( const_cast<const StaticAssertDecl *>(node) ); } 50 50 virtual void visit( const StaticAssertDecl * assertDecl ) = 0; 51 virtual void visit( InlineValueDecl * node ) { visit( const_cast<const InlineValueDecl *>(node) ); }52 virtual void visit( const InlineValueDecl * valueDecl ) = 0;53 51 54 52 virtual void visit( CompoundStmt * node ) { visit( const_cast<const CompoundStmt *>(node) ); } -
src/SynTree/module.mk
r13edbac r2856982c 42 42 SynTree/Initializer.cc \ 43 43 SynTree/Initializer.h \ 44 SynTree/InlineValueDecl.cc \45 44 SynTree/Label.h \ 46 45 SynTree/LinkageSpec.cc \ -
src/Validate/EnumAndPointerDecay.cpp
r13edbac r2856982c 21 21 #include "AST/Type.hpp" 22 22 #include "SymTab/FixFunction.h" 23 #include "Validate/NoIdSymbolTable.hpp"24 23 25 24 namespace Validate { … … 27 26 namespace { 28 27 29 struct EnumAndPointerDecayCore final : public WithNoIdSymbolTable, publicast::WithCodeLocation {28 struct EnumAndPointerDecayCore final : public ast::WithCodeLocation { 30 29 ast::EnumDecl const * previsit( ast::EnumDecl const * decl ); 31 30 ast::FunctionDecl const * previsit( ast::FunctionDecl const * decl ); … … 40 39 // Set the type of each member of the enumeration to be EnumContant. 41 40 auto mut = ast::mutate( decl ); 42 std::vector<ast::ptr<ast::Decl>> buffer; 43 for ( auto it = decl->members.begin(); it != decl->members.end(); ++it ) { 44 if ( ast::ObjectDecl const * object = (*it).as<ast::ObjectDecl>() ) { 45 buffer.push_back( ast::mutate_field( object, &ast::ObjectDecl::type, new ast::EnumInstType( decl, ast::CV::Const ) ) ); 46 } else if ( ast::InlineValueDecl const * value = (*it).as<ast::InlineValueDecl>() ) { 47 if ( auto targetEnum = symtab.lookupEnum( value->name ) ) { 48 for ( auto singleMember : targetEnum->members ) { 49 auto copyingMember = singleMember.as<ast::ObjectDecl>(); 50 buffer.push_back( new ast::ObjectDecl( 51 value->location, // use the "inline" location 52 copyingMember->name, 53 new ast::EnumInstType( decl, ast::CV::Const ), 54 // Construct a new EnumInstType as the type 55 copyingMember->init, 56 copyingMember->storage, 57 copyingMember->linkage, 58 copyingMember->bitfieldWidth, 59 {}, 60 copyingMember->funcSpec 61 ) ); 62 } 63 } 64 } 41 for ( ast::ptr<ast::Decl> & member : mut->members ) { 42 ast::ObjectDecl const * object = member.strict_as<ast::ObjectDecl>(); 43 member = ast::mutate_field( object, &ast::ObjectDecl::type, 44 new ast::EnumInstType( decl, ast::CV::Const ) ); 65 45 } 66 mut->members = buffer;67 46 return mut; 68 47 } -
src/Validate/LinkReferenceToTypes.cpp
r13edbac r2856982c 185 185 decl = mut; 186 186 } 187 // visit the base188 187 } else if ( auto ptr = decl->base.as<ast::PointerType>() ) { 189 188 if ( auto base = ptr->base.as<ast::TypeInstType>() ) { … … 204 203 205 204 // The following section 205 auto mut = ast::mutate( decl ); 206 std::vector<ast::ptr<ast::Decl>> buffer; 207 for ( auto it = decl->members.begin(); it != decl->members.end(); ++it) { 208 auto member = (*it).as<ast::ObjectDecl>(); 209 if ( member->enumInLine ) { 210 auto targetEnum = symtab.lookupEnum( member->name ); 211 if ( targetEnum ) { 212 for ( auto singleMamber : targetEnum->members ) { 213 auto tm = singleMamber.as<ast::ObjectDecl>(); 214 auto t = new ast::ObjectDecl( 215 member->location, // use the "inline" location 216 tm->name, 217 new ast::EnumInstType( decl, ast::CV::Const ), 218 // Construct a new EnumInstType as the type 219 tm->init, 220 tm->storage, 221 tm->linkage, 222 tm->bitfieldWidth, 223 {}, // enum member doesn't have attribute 224 tm->funcSpec 225 ); 226 t->importValue = true; 227 buffer.push_back(t); 228 } 229 } 230 } else { 231 auto search_it = std::find_if( buffer.begin(), buffer.end(), [member](ast::ptr<ast::Decl> cur) { 232 auto curAsObjDecl = cur.as<ast::ObjectDecl>(); 233 return (curAsObjDecl->importValue) && (curAsObjDecl->name == member->name); 234 }); 235 if ( search_it != buffer.end() ) { 236 buffer.erase( search_it ); // Found an import enum value that has the same name 237 // override the imported value 238 } 239 buffer.push_back( *it ); 240 } 241 } 242 mut->members = buffer; 243 decl = mut; 206 244 207 245 ForwardEnumsType::iterator fwds = forwardEnums.find( decl->name ); -
tests/enum_tests/.expect/enumInlineValue.txt
r13edbac r2856982c 1 1 enumB.A is 5 2 enumB.B is 62 enumB.B is 10 3 3 enumB.D is 11 4 4 enumB.E is 12 -
tests/enum_tests/.expect/qualifiedEnum.cfa
r13edbac r2856982c 1 l : 11 l :0 -
tests/enum_tests/enumInlineValue.cfa
r13edbac r2856982c 6 6 enum enumB { 7 7 inline enumA, 8 E 8 E, B=10 9 9 }; 10 10 -
tests/enum_tests/qualifiedEnum.cfa
r13edbac r2856982c 8 8 9 9 int main() { 10 enum Level l = Level. MEDIUM;10 enum Level l = Level.LOW; 11 11 sout | "l :" | l; 12 12 return 0;
Note:
See TracChangeset
for help on using the changeset viewer.