Changeset 5fda7143
- Timestamp:
- Sep 7, 2016, 9:30:25 AM (8 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, ctor, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
- Children:
- 9f70ab57
- Parents:
- 1f75e2d (diff), f04a8b81 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - Location:
- src
- Files:
-
- 3 added
- 2 deleted
- 39 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Common/SemanticError.cc
r1f75e2d r5fda7143 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // SemanticError.cc -- 7 // SemanticError.cc -- 8 8 // 9 9 // Author : Richard C. Bilson … … 26 26 27 27 SemanticError::SemanticError( std::string error ) { 28 errors.push_back( std::string( "Error: " ) +error );28 append( error ); 29 29 } 30 30 31 31 void SemanticError::append( SemanticError &other ) { 32 errors.splice( errors.end(), other.errors ); 32 errors.splice( errors.end(), other.errors ); 33 } 34 35 void SemanticError::append( const std::string & msg ) { 36 errors.push_back( std::string( "Error: ") + msg ); 33 37 } 34 38 -
src/Common/SemanticError.h
r1f75e2d r5fda7143 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // SemanticError.h -- 7 // SemanticError.h -- 8 8 // 9 9 // Author : Richard C. Bilson … … 31 31 32 32 void append( SemanticError &other ); 33 void append( const std::string & ); 33 34 bool isEmpty() const; 34 35 void print( std::ostream &os ); … … 42 43 template< typename T > 43 44 SemanticError::SemanticError( const std::string &error, const T *obj ) { 44 std::ostringstream os; 45 os << "Error: " << error; 46 obj->print( os ); 47 errors.push_back( os.str() ); 45 append( toString( error, obj ) ); 48 46 } 47 49 48 50 49 #endif // SEMANTICERROR_H -
src/Common/utility.h
r1f75e2d r5fda7143 265 265 std::weak_ptr<ThisType> RefCountSingleton<ThisType>::global_instance; 266 266 267 // RAII object to regulate "save and restore" behaviour, e.g. 268 // void Foo::bar() { 269 // ValueGuard<int> guard(var); // var is a member of type Foo 270 // var = ...; 271 // } // var's original value is restored 272 template< typename T > 273 struct ValueGuard { 274 T old; 275 T& ref; 276 277 ValueGuard(T& inRef) : old(inRef), ref(inRef) {} 278 ~ValueGuard() { ref = old; } 279 }; 280 281 template< typename T > 282 struct reverseIterate_t { 283 T& ref; 284 285 reverseIterate_t( T & ref ) : ref(ref) {} 286 287 typedef typename T::reverse_iterator iterator; 288 iterator begin() { return ref.rbegin(); } 289 iterator end() { return ref.rend(); } 290 }; 291 292 template< typename T > 293 reverseIterate_t< T > reverseIterate( T & ref ) { 294 return reverseIterate_t< T >( ref ); 295 } 296 267 297 #endif // _UTILITY_H 268 298 -
src/GenPoly/Box.cc
r1f75e2d r5fda7143 158 158 class PolyGenericCalculator : public PolyMutator { 159 159 public: 160 typedef PolyMutator Parent; 161 using Parent::mutate; 162 160 163 template< typename DeclClass > 161 164 DeclClass *handleDecl( DeclClass *decl, Type *type ); … … 1675 1678 DeclClass * PolyGenericCalculator::handleDecl( DeclClass *decl, Type *type ) { 1676 1679 beginTypeScope( type ); 1680 // knownLayouts.beginScope(); 1681 // knownOffsets.beginScope(); 1682 1683 DeclClass *ret = static_cast< DeclClass *>( Parent::mutate( decl ) ); 1684 1685 // knownOffsets.endScope(); 1686 // knownLayouts.endScope(); 1687 endTypeScope(); 1688 return ret; 1689 } 1690 1691 ObjectDecl * PolyGenericCalculator::mutate( ObjectDecl *objectDecl ) { 1692 return handleDecl( objectDecl, objectDecl->get_type() ); 1693 } 1694 1695 DeclarationWithType * PolyGenericCalculator::mutate( FunctionDecl *functionDecl ) { 1677 1696 knownLayouts.beginScope(); 1678 1697 knownOffsets.beginScope(); 1679 1698 1680 DeclClass *ret = static_cast< DeclClass *>( Mutator::mutate( decl ) ); 1681 1699 DeclarationWithType * decl = handleDecl( functionDecl, functionDecl->get_functionType() ); 1682 1700 knownOffsets.endScope(); 1683 1701 knownLayouts.endScope(); 1684 endTypeScope(); 1685 return ret; 1686 } 1687 1688 ObjectDecl * PolyGenericCalculator::mutate( ObjectDecl *objectDecl ) { 1689 return handleDecl( objectDecl, objectDecl->get_type() ); 1690 } 1691 1692 DeclarationWithType * PolyGenericCalculator::mutate( FunctionDecl *functionDecl ) { 1693 return handleDecl( functionDecl, functionDecl->get_functionType() ); 1702 return decl; 1694 1703 } 1695 1704 … … 1700 1709 TypeDecl * PolyGenericCalculator::mutate( TypeDecl *typeDecl ) { 1701 1710 scopeTyVars[ typeDecl->get_name() ] = typeDecl->get_kind(); 1702 return Mutator::mutate( typeDecl );1711 return Parent::mutate( typeDecl ); 1703 1712 } 1704 1713 … … 1706 1715 beginTypeScope( pointerType ); 1707 1716 1708 Type *ret = Mutator::mutate( pointerType );1717 Type *ret = Parent::mutate( pointerType ); 1709 1718 1710 1719 endTypeScope(); … … 1724 1733 } 1725 1734 1726 Type *ret = Mutator::mutate( funcType );1735 Type *ret = Parent::mutate( funcType ); 1727 1736 1728 1737 endTypeScope(); … … 1745 1754 } 1746 1755 } 1747 return Mutator::mutate( declStmt );1756 return Parent::mutate( declStmt ); 1748 1757 } 1749 1758 … … 1787 1796 Expression *PolyGenericCalculator::mutate( MemberExpr *memberExpr ) { 1788 1797 // mutate, exiting early if no longer MemberExpr 1789 Expression *expr = Mutator::mutate( memberExpr );1798 Expression *expr = Parent::mutate( memberExpr ); 1790 1799 memberExpr = dynamic_cast< MemberExpr* >( expr ); 1791 1800 if ( ! memberExpr ) return expr; … … 1972 1981 Expression *PolyGenericCalculator::mutate( OffsetofExpr *offsetofExpr ) { 1973 1982 // mutate, exiting early if no longer OffsetofExpr 1974 Expression *expr = Mutator::mutate( offsetofExpr );1983 Expression *expr = Parent::mutate( offsetofExpr ); 1975 1984 offsetofExpr = dynamic_cast< OffsetofExpr* >( expr ); 1976 1985 if ( ! offsetofExpr ) return expr; -
src/GenPoly/PolyMutator.cc
r1f75e2d r5fda7143 30 30 31 31 void PolyMutator::mutateStatementList( std::list< Statement* > &statements ) { 32 SemanticError errors; 33 32 34 for ( std::list< Statement* >::iterator i = statements.begin(); i != statements.end(); ++i ) { 33 35 if ( ! stmtsToAddAfter.empty() ) { 34 36 statements.splice( i, stmtsToAddAfter ); 35 37 } // if 36 *i = (*i)->acceptMutator( *this ); 38 try { 39 *i = (*i)->acceptMutator( *this ); 40 } catch ( SemanticError &e ) { 41 errors.append( e ); 42 } // try 37 43 if ( ! stmtsToAdd.empty() ) { 38 44 statements.splice( i, stmtsToAdd ); … … 42 48 statements.splice( statements.end(), stmtsToAddAfter ); 43 49 } // if 50 if ( ! errors.isEmpty() ) { 51 throw errors; 52 } 44 53 } 45 54 -
src/GenPoly/PolyMutator.h
r1f75e2d r5fda7143 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // PolyMutator.h -- 7 // PolyMutator.h -- 8 8 // 9 9 // Author : Richard C. Bilson … … 30 30 class PolyMutator : public Mutator { 31 31 public: 32 typedef Mutator Parent; 33 using Parent::mutate; 34 32 35 PolyMutator(); 33 36 … … 42 45 virtual Statement* mutate(ExprStmt *catchStmt); 43 46 virtual Statement* mutate(ReturnStmt *catchStmt); 44 47 45 48 virtual Expression* mutate(UntypedExpr *untypedExpr); 46 49 … … 54 57 Statement* mutateStatement( Statement *stmt ); 55 58 Expression* mutateExpression( Expression *expr ); 56 59 57 60 TyVarMap scopeTyVars; 58 61 TypeSubstitution *env; … … 60 63 std::list< Statement* > stmtsToAddAfter; 61 64 }; 62 } // namespace 65 } // namespace 63 66 64 67 #endif // _POLYMUTATOR_H -
src/InitTweak/FixInit.cc
r1f75e2d r5fda7143 31 31 #include "SynTree/Mutator.h" 32 32 #include "SymTab/Indexer.h" 33 #include "SymTab/Autogen.h" 33 34 #include "GenPoly/PolyMutator.h" 34 35 #include "SynTree/AddStmtVisitor.h" … … 176 177 }; 177 178 178 class WarnStructMembers : public Visitor {179 class GenStructMemberCalls : public SymTab::Indexer { 179 180 public: 180 typedef Visitor Parent; 181 /// warn if a user-defined constructor or destructor is missing calls for 182 /// a struct member or if a member is used before constructed 183 static void warnings( std::list< Declaration * > & translationUnit ); 181 typedef Indexer Parent; 182 /// generate default/copy ctor and dtor calls for user-defined struct ctor/dtors 183 /// for any member that is missing a corresponding ctor/dtor call. 184 /// error if a member is used before constructed 185 static void generate( std::list< Declaration * > & translationUnit ); 184 186 185 187 virtual void visit( FunctionDecl * funcDecl ); … … 188 190 virtual void visit( ApplicationExpr * appExpr ); 189 191 192 SemanticError errors; 190 193 private: 191 194 void handleFirstParam( Expression * firstParam ); 195 template< typename... Params > 196 void emit( const Params &... params ); 192 197 193 198 FunctionDecl * function = 0; 194 std::set< DeclarationWithType * > unhandled ;199 std::set< DeclarationWithType * > unhandled, usedUninit; 195 200 ObjectDecl * thisParam = 0; 201 bool isCtor = false; // true if current function is a constructor 202 StructDecl * structDecl = 0; 203 }; 204 205 // very simple resolver-like mutator class - used to 206 // resolve UntypedExprs that are found within newly 207 // generated constructor/destructor calls 208 class MutatingResolver : public Mutator { 209 public: 210 MutatingResolver( SymTab::Indexer & indexer ) : indexer( indexer ) {} 211 212 virtual DeclarationWithType* mutate( ObjectDecl *objectDecl ); 213 214 virtual Expression* mutate( UntypedExpr *untypedExpr ); 215 private: 216 SymTab::Indexer & indexer; 196 217 }; 197 218 } // namespace … … 209 230 FixCopyCtors::fixCopyCtors( translationUnit ); 210 231 211 WarnStructMembers::warnings( translationUnit );232 GenStructMemberCalls::generate( translationUnit ); 212 233 } 213 234 … … 254 275 } 255 276 256 void WarnStructMembers::warnings( std::list< Declaration * > & translationUnit ) { 257 if ( true ) { // fix this condition to skip this pass if warnings aren't enabled 258 WarnStructMembers warner; 259 acceptAll( translationUnit, warner ); 277 void GenStructMemberCalls::generate( std::list< Declaration * > & translationUnit ) { 278 GenStructMemberCalls warner; 279 acceptAll( translationUnit, warner ); 280 281 // visitor doesn't throw so that it can collect all errors 282 if ( ! warner.errors.isEmpty() ) { 283 throw warner.errors; 260 284 } 261 285 } … … 528 552 FunctionDecl * dtorCaller = new FunctionDecl( objDecl->get_mangleName() + dtorCallerNamer.newName(), DeclarationNode::Static, LinkageSpec::C, new FunctionType( Type::Qualifiers(), false ), new CompoundStmt( noLabels ), false, false ); 529 553 dtorCaller->fixUniqueId(); 530 dtorCaller->get_statements()-> get_kids().push_back( dtorStmt );554 dtorCaller->get_statements()->push_back( dtorStmt ); 531 555 532 556 // atexit(dtor_atexit); … … 543 567 // at global scope and there could be multiple function-scoped 544 568 // static variables with the same name in different functions. 569 // Note: it isn't sufficient to modify only the mangleName, because 570 // then subsequent Indexer passes can choke on seeing the object's name 571 // if another object has the same name and type. An unfortunate side-effect 572 // of renaming the object is that subsequent NameExprs may fail to resolve, 573 // but there shouldn't be any remaining past this point. 545 574 static UniqueName staticNamer( "_static_var" ); 546 objDecl->set_mangleName( objDecl->get_mangleName() + staticNamer.newName() ); 575 objDecl->set_name( objDecl->get_name() + staticNamer.newName() ); 576 objDecl->set_mangleName( SymTab::Mangler::mangle( objDecl ) ); 547 577 548 578 objDecl->set_init( NULL ); … … 709 739 } 710 740 711 void WarnStructMembers::visit( FunctionDecl * funcDecl ) { 712 WarnStructMembers old = *this; 713 *this = WarnStructMembers(); 741 void GenStructMemberCalls::visit( FunctionDecl * funcDecl ) { 742 ValueGuard< FunctionDecl * > oldFunction( funcDecl ); 743 ValueGuard< std::set< DeclarationWithType * > > oldUnhandled( unhandled ); 744 ValueGuard< std::set< DeclarationWithType * > > oldUsedUninit( usedUninit ); 745 ValueGuard< ObjectDecl * > oldThisParam( thisParam ); 746 ValueGuard< bool > oldIsCtor( isCtor ); 747 ValueGuard< StructDecl * > oldStructDecl( structDecl ); 748 749 // need to start with fresh sets 750 unhandled.clear(); 751 usedUninit.clear(); 714 752 715 753 function = funcDecl; 716 if ( checkWarnings( funcDecl ) ) { 717 FunctionType * type = funcDecl->get_functionType(); 754 isCtor = isConstructor( function->get_name() ); 755 if ( checkWarnings( function ) ) { 756 FunctionType * type = function->get_functionType(); 718 757 assert( ! type->get_parameters().empty() ); 719 758 thisParam = safe_dynamic_cast< ObjectDecl * >( type->get_parameters().front() ); … … 721 760 StructInstType * structType = dynamic_cast< StructInstType * >( ptrType->get_base() ); 722 761 if ( structType ) { 723 StructDecl *structDecl = structType->get_baseStruct();762 structDecl = structType->get_baseStruct(); 724 763 for ( Declaration * member : structDecl->get_members() ) { 725 764 if ( ObjectDecl * field = dynamic_cast< ObjectDecl * >( member ) ) { … … 731 770 } 732 771 } 733 Parent::visit( funcDecl ); 734 735 for ( DeclarationWithType * member : unhandled ) { 736 // emit a warning for each unhandled member 737 warn( "in ", CodeGen::genType( function->get_functionType(), function->get_name(), false ), ", member ", member->get_name(), " may not have been ", isConstructor( funcDecl->get_name() ) ? "constructed" : "destructed" ); 772 Parent::visit( function ); 773 774 // remove the unhandled objects from usedUninit, because a call is inserted 775 // to handle them - only objects that are later constructed are used uninitialized. 776 std::set< DeclarationWithType * > diff; 777 std::set_difference( usedUninit.begin(), usedUninit.end(), unhandled.begin(), unhandled.end(), std::inserter( diff, diff.begin() ) ); 778 for ( DeclarationWithType * member : diff ) { 779 emit( "in ", CodeGen::genType( function->get_functionType(), function->get_name(), false ), ", field ", member->get_name(), " used before being constructed" ); 738 780 } 739 781 740 *this = old; 741 } 742 743 void WarnStructMembers::visit( ApplicationExpr * appExpr ) { 782 if ( ! unhandled.empty() ) { 783 // need to explicitly re-add function parameters in order to resolve copy constructors 784 enterScope(); 785 maybeAccept( function->get_functionType(), *this ); 786 787 // need to iterate through members in reverse in order for 788 // ctor/dtor statements to come out in the right order 789 for ( Declaration * member : reverseIterate( structDecl->get_members() ) ) { 790 DeclarationWithType * field = dynamic_cast< DeclarationWithType * >( member ); 791 // skip non-DWT members 792 if ( ! field ) continue; 793 // skip handled members 794 if ( ! unhandled.count( field ) ) continue; 795 796 // insert and resolve default/copy constructor call for each field that's unhandled 797 std::list< Statement * > stmt; 798 UntypedExpr * deref = new UntypedExpr( new NameExpr( "*?" ) ); 799 deref->get_args().push_back( new VariableExpr( thisParam ) ); 800 801 Expression * arg2 = 0; 802 if ( isCopyConstructor( function ) ) { 803 // if copy ctor, need to pass second-param-of-this-function.field 804 std::list< DeclarationWithType * > & params = function->get_functionType()->get_parameters(); 805 assert( params.size() == 2 ); 806 arg2 = new MemberExpr( field, new VariableExpr( params.back() ) ); 807 } 808 InitExpander srcParam( arg2 ); 809 SymTab::genImplicitCall( srcParam, new MemberExpr( field, deref ), function->get_name(), back_inserter( stmt ), field, isCtor ); 810 811 assert( stmt.size() <= 1 ); 812 if ( stmt.size() == 1 ) { 813 Statement * callStmt = stmt.front(); 814 815 MutatingResolver resolver( *this ); 816 try { 817 callStmt->acceptMutator( resolver ); 818 if ( isCtor ) { 819 function->get_statements()->push_front( callStmt ); 820 } else { 821 // destructor statements should be added at the end 822 function->get_statements()->push_back( callStmt ); 823 } 824 } catch ( SemanticError & error ) { 825 emit( "in ", CodeGen::genType( function->get_functionType(), function->get_name(), false ), ", field ", field->get_name(), " not explicitly ", isCtor ? "constructed" : "destructed", " and no ", isCtor ? "default constructor" : "destructor", " found" ); 826 } 827 } 828 } 829 leaveScope(); 830 } 831 } 832 833 void GenStructMemberCalls::visit( ApplicationExpr * appExpr ) { 744 834 if ( ! checkWarnings( function ) ) return; 745 835 … … 760 850 handleFirstParam( firstParam ); 761 851 } 762 } else if ( fname == "?=?" && isIntrinsicCallExpr( appExpr ) ) {763 // forgive use of intrinsic assignment to construct, since instrinsic constructors764 // codegen as assignment anyway.765 assert( appExpr->get_args().size() == 2 );766 handleFirstParam( appExpr->get_args().front() );767 852 } 768 853 … … 770 855 } 771 856 772 void WarnStructMembers::handleFirstParam( Expression * firstParam ) {857 void GenStructMemberCalls::handleFirstParam( Expression * firstParam ) { 773 858 using namespace std; 774 859 if ( AddressExpr * addrExpr = dynamic_cast< AddressExpr * >( firstParam ) ) { … … 787 872 } 788 873 789 void WarnStructMembers::visit( MemberExpr * memberExpr ) {874 void GenStructMemberCalls::visit( MemberExpr * memberExpr ) { 790 875 if ( ! checkWarnings( function ) ) return; 791 if ( ! isC onstructor( function->get_name() )) return;876 if ( ! isCtor ) return; 792 877 793 878 if ( ApplicationExpr * deref = dynamic_cast< ApplicationExpr * >( memberExpr->get_aggregate() ) ) { … … 797 882 if ( unhandled.count( memberExpr->get_member() ) ) { 798 883 // emit a warning because a member was used before it was constructed 799 warn( "in ", CodeGen::genType( function->get_functionType(), function->get_name(), false ), ", member ", memberExpr->get_member()->get_name(), " used before being constructed");884 usedUninit.insert( memberExpr->get_member() ); 800 885 } 801 886 } … … 805 890 Parent::visit( memberExpr ); 806 891 } 892 893 template< typename Visitor, typename... Params > 894 void error( Visitor & v, const Params &... params ) { 895 v.errors.append( toString( params... ) ); 896 } 897 898 template< typename... Params > 899 void GenStructMemberCalls::emit( const Params &... params ) { 900 // toggle warnings vs. errors here. 901 // warn( params... ); 902 error( *this, params... ); 903 } 904 905 DeclarationWithType * MutatingResolver::mutate( ObjectDecl *objectDecl ) { 906 // add object to the indexer assumes that there will be no name collisions 907 // in generated code. If this changes, add mutate methods for entities with 908 // scope and call {enter,leave}Scope explicitly. 909 objectDecl->accept( indexer ); 910 return objectDecl; 911 } 912 913 Expression* MutatingResolver::mutate( UntypedExpr *untypedExpr ) { 914 return safe_dynamic_cast< ApplicationExpr * >( ResolvExpr::findVoidExpression( untypedExpr, indexer ) ); 915 } 807 916 } // namespace 808 917 } // namespace InitTweak -
src/InitTweak/GenInit.cc
r1f75e2d r5fda7143 25 25 #include "SynTree/Mutator.h" 26 26 #include "SymTab/Autogen.h" 27 #include "SymTab/Mangler.h" 27 28 #include "GenPoly/PolyMutator.h" 28 29 #include "GenPoly/DeclMutator.h" 30 #include "GenPoly/ScopedSet.h" 29 31 30 32 namespace InitTweak { … … 55 57 class CtorDtor : public GenPoly::PolyMutator { 56 58 public: 59 typedef GenPoly::PolyMutator Parent; 60 using Parent::mutate; 57 61 /// create constructor and destructor statements for object declarations. 58 62 /// the actual call statements will be added in after the resolver has run … … 65 69 // should not traverse into any of these declarations to find objects 66 70 // that need to be constructed or destructed 67 virtual Declaration* mutate( StructDecl *aggregateDecl ) { return aggregateDecl; }71 virtual Declaration* mutate( StructDecl *aggregateDecl ); 68 72 virtual Declaration* mutate( UnionDecl *aggregateDecl ) { return aggregateDecl; } 69 73 virtual Declaration* mutate( EnumDecl *aggregateDecl ) { return aggregateDecl; } … … 74 78 virtual Type * mutate( FunctionType *funcType ) { return funcType; } 75 79 76 protected: 80 virtual CompoundStmt * mutate( CompoundStmt * compoundStmt ); 81 82 private: 83 // set of mangled type names for which a constructor or destructor exists in the current scope. 84 // these types require a ConstructorInit node to be generated, anything else is a POD type and thus 85 // should not have a ConstructorInit generated. 86 87 bool isManaged( ObjectDecl * objDecl ) const ; // determine if object is managed 88 void handleDWT( DeclarationWithType * dwt ); // add type to managed if ctor/dtor 89 GenPoly::ScopedSet< std::string > managedTypes; 90 bool inFunction = false; 77 91 }; 78 92 … … 142 156 143 157 DeclarationWithType* ReturnFixer::mutate( FunctionDecl *functionDecl ) { 144 std::list<DeclarationWithType*> oldReturnVals = returnVals;145 std::string oldFuncName = funcName;158 ValueGuard< std::list<DeclarationWithType*> > oldReturnVals( returnVals ); 159 ValueGuard< std::string > oldFuncName( funcName ); 146 160 147 161 FunctionType * type = functionDecl->get_functionType(); … … 149 163 funcName = functionDecl->get_name(); 150 164 DeclarationWithType * decl = Mutator::mutate( functionDecl ); 151 returnVals = oldReturnVals;152 funcName = oldFuncName;153 165 return decl; 154 166 } … … 197 209 198 210 DeclarationWithType * HoistArrayDimension::mutate( FunctionDecl *functionDecl ) { 199 bool oldInFunc = inFunction;211 ValueGuard< bool > oldInFunc( inFunction ); 200 212 inFunction = true; 201 213 DeclarationWithType * decl = Parent::mutate( functionDecl ); 202 inFunction = oldInFunc;203 214 return decl; 204 215 } … … 209 220 } 210 221 222 bool CtorDtor::isManaged( ObjectDecl * objDecl ) const { 223 Type * type = objDecl->get_type(); 224 while ( ArrayType * at = dynamic_cast< ArrayType * >( type ) ) { 225 type = at->get_base(); 226 } 227 return managedTypes.find( SymTab::Mangler::mangle( type ) ) != managedTypes.end(); 228 } 229 230 void CtorDtor::handleDWT( DeclarationWithType * dwt ) { 231 // if this function is a user-defined constructor or destructor, mark down the type as "managed" 232 if ( ! LinkageSpec::isOverridable( dwt->get_linkage() ) && isCtorDtor( dwt->get_name() ) ) { 233 std::list< DeclarationWithType * > & params = GenPoly::getFunctionType( dwt->get_type() )->get_parameters(); 234 assert( ! params.empty() ); 235 PointerType * type = safe_dynamic_cast< PointerType * >( params.front()->get_type() ); 236 managedTypes.insert( SymTab::Mangler::mangle( type->get_base() ) ); 237 } 238 } 239 211 240 DeclarationWithType * CtorDtor::mutate( ObjectDecl * objDecl ) { 212 // hands off if designated, if @=, or if extern 213 if ( tryConstruct( objDecl ) ) { 241 handleDWT( objDecl ); 242 // hands off if @=, extern, builtin, etc. 243 // if global but initializer is not constexpr, always try to construct, since this is not legal C 244 if ( ( tryConstruct( objDecl ) && isManaged( objDecl ) ) || (! inFunction && ! isConstExpr( objDecl->get_init() ) ) ) { 245 // constructed objects cannot be designated 246 if ( isDesignated( objDecl->get_init() ) ) throw SemanticError( "Cannot include designations in the initializer for a managed Object. If this is really what you want, then initialize with @=.", objDecl ); 247 // constructed objects should not have initializers nested too deeply 248 if ( ! checkInitDepth( objDecl ) ) throw SemanticError( "Managed object's initializer is too deep ", objDecl ); 249 214 250 // call into genImplicitCall from Autogen.h to generate calls to ctor/dtor 215 251 // for each constructable object … … 241 277 } 242 278 } 243 return Mutator::mutate( objDecl );279 return Parent::mutate( objDecl ); 244 280 } 245 281 246 282 DeclarationWithType * CtorDtor::mutate( FunctionDecl *functionDecl ) { 283 ValueGuard< bool > oldInFunc = inFunction; 284 inFunction = true; 285 286 handleDWT( functionDecl ); 287 288 managedTypes.beginScope(); 289 // go through assertions and recursively add seen ctor/dtors 290 for ( TypeDecl * tyDecl : functionDecl->get_functionType()->get_forall() ) { 291 for ( DeclarationWithType *& assertion : tyDecl->get_assertions() ) { 292 assertion = assertion->acceptMutator( *this ); 293 } 294 } 247 295 // parameters should not be constructed and destructed, so don't mutate FunctionType 248 296 mutateAll( functionDecl->get_oldDecls(), *this ); 249 297 functionDecl->set_statements( maybeMutate( functionDecl->get_statements(), *this ) ); 298 299 managedTypes.endScope(); 250 300 return functionDecl; 251 301 } 302 303 Declaration* CtorDtor::mutate( StructDecl *aggregateDecl ) { 304 // don't construct members, but need to take note if there is a managed member, 305 // because that means that this type is also managed 306 for ( Declaration * member : aggregateDecl->get_members() ) { 307 if ( ObjectDecl * field = dynamic_cast< ObjectDecl * >( member ) ) { 308 if ( isManaged( field ) ) { 309 managedTypes.insert( SymTab::Mangler::mangle( aggregateDecl ) ); 310 break; 311 } 312 } 313 } 314 return aggregateDecl; 315 } 316 317 CompoundStmt * CtorDtor::mutate( CompoundStmt * compoundStmt ) { 318 managedTypes.beginScope(); 319 CompoundStmt * stmt = Parent::mutate( compoundStmt ); 320 managedTypes.endScope(); 321 return stmt; 322 } 323 252 324 } // namespace InitTweak 253 325 -
src/InitTweak/InitTweak.cc
r1f75e2d r5fda7143 7 7 #include "SynTree/Attribute.h" 8 8 #include "GenPoly/GenPoly.h" 9 #include "ResolvExpr/typeops.h" 9 10 10 11 namespace InitTweak { … … 22 23 }; 23 24 25 class InitDepthChecker : public Visitor { 26 public: 27 bool depthOkay = true; 28 Type * type; 29 int curDepth = 0, maxDepth = 0; 30 InitDepthChecker( Type * type ) : type( type ) { 31 Type * t = type; 32 while ( ArrayType * at = dynamic_cast< ArrayType * >( t ) ) { 33 maxDepth++; 34 t = at->get_base(); 35 } 36 maxDepth++; 37 } 38 virtual void visit( ListInit * listInit ) { 39 curDepth++; 40 if ( curDepth > maxDepth ) depthOkay = false; 41 Visitor::visit( listInit ); 42 curDepth--; 43 } 44 }; 45 24 46 class InitFlattener : public Visitor { 25 47 public: … … 52 74 maybeAccept( init, finder ); 53 75 return finder.hasDesignations; 76 } 77 78 bool checkInitDepth( ObjectDecl * objDecl ) { 79 InitDepthChecker checker( objDecl->get_type() ); 80 maybeAccept( objDecl->get_init(), checker ); 81 return checker.depthOkay; 54 82 } 55 83 … … 231 259 return ! LinkageSpec::isBuiltin( objDecl->get_linkage() ) && 232 260 (objDecl->get_init() == NULL || 233 ( objDecl->get_init() != NULL && objDecl->get_init()->get_maybeConstructed() )) && 234 ! isDesignated( objDecl->get_init() ) 261 ( objDecl->get_init() != NULL && objDecl->get_init()->get_maybeConstructed() )) 235 262 && objDecl->get_storageClass() != DeclarationNode::Extern; 236 263 } … … 390 417 virtual void visit( ApplicationExpr *applicationExpr ) { isConstExpr = false; } 391 418 virtual void visit( UntypedExpr *untypedExpr ) { isConstExpr = false; } 392 virtual void visit( NameExpr *nameExpr ) { isConstExpr = false; } 393 virtual void visit( CastExpr *castExpr ) { isConstExpr = false; } 419 virtual void visit( NameExpr *nameExpr ) { 420 // xxx - temporary hack, because 0 and 1 really should be constexprs, even though they technically aren't in Cforall today 421 if ( nameExpr->get_name() != "0" && nameExpr->get_name() != "1" ) isConstExpr = false; 422 } 423 // virtual void visit( CastExpr *castExpr ) { isConstExpr = false; } 424 virtual void visit( AddressExpr *addressExpr ) { 425 // address of a variable or member expression is constexpr 426 Expression * arg = addressExpr->get_arg(); 427 if ( ! dynamic_cast< NameExpr * >( arg) && ! dynamic_cast< VariableExpr * >( arg ) && ! dynamic_cast< MemberExpr * >( arg ) && ! dynamic_cast< UntypedMemberExpr * >( arg ) ) isConstExpr = false; 428 } 394 429 virtual void visit( LabelAddressExpr *labAddressExpr ) { isConstExpr = false; } 395 430 virtual void visit( UntypedMemberExpr *memberExpr ) { isConstExpr = false; } 396 431 virtual void visit( MemberExpr *memberExpr ) { isConstExpr = false; } 397 432 virtual void visit( VariableExpr *variableExpr ) { isConstExpr = false; } 398 virtual void visit( ConstantExpr *constantExpr ) { /* bottom out */ }399 433 // these might be okay? 400 434 // virtual void visit( SizeofExpr *sizeofExpr ); … … 439 473 bool isDestructor( const std::string & str ) { return str == "^?{}"; } 440 474 bool isCtorDtor( const std::string & str ) { return isConstructor( str ) || isDestructor( str ); } 475 476 FunctionDecl * isCopyConstructor( Declaration * decl ) { 477 FunctionDecl * function = dynamic_cast< FunctionDecl * >( decl ); 478 if ( ! function ) return 0; 479 if ( ! isConstructor( function->get_name() ) ) return 0; 480 FunctionType * ftype = function->get_functionType(); 481 if ( ftype->get_parameters().size() != 2 ) return 0; 482 483 Type * t1 = ftype->get_parameters().front()->get_type(); 484 Type * t2 = ftype->get_parameters().back()->get_type(); 485 PointerType * ptrType = dynamic_cast< PointerType * > ( t1 ); 486 assert( ptrType ); 487 488 if ( ResolvExpr::typesCompatible( ptrType->get_base(), t2, SymTab::Indexer() ) ) { 489 return function; 490 } else { 491 return 0; 492 } 493 } 441 494 } -
src/InitTweak/InitTweak.h
r1f75e2d r5fda7143 30 30 bool isCtorDtor( const std::string & ); 31 31 32 FunctionDecl * isCopyConstructor( Declaration * decl ); 33 32 34 /// transform Initializer into an argument list that can be passed to a call expression 33 35 std::list< Expression * > makeInitList( Initializer * init ); … … 38 40 /// True if the Initializer contains designations 39 41 bool isDesignated( Initializer * init ); 42 43 /// True if the ObjectDecl's Initializer nesting level is not deeper than the depth of its 44 /// type, where the depth of its type is the number of nested ArrayTypes + 1 45 bool checkInitDepth( ObjectDecl * objDecl ); 40 46 41 47 /// Non-Null if expr is a call expression whose target function is intrinsic -
src/Parser/DeclarationNode.cc
r1f75e2d r5fda7143 10 10 // Created On : Sat May 16 12:34:05 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sun Aug 28 22:12:44201613 // Update Count : 27812 // Last Modified On : Mon Aug 29 22:30:56 2016 13 // Update Count : 327 14 14 // 15 15 … … 42 42 43 43 extern LinkageSpec::Spec linkage; // defined in parser.yy 44 45 DeclarationNode::DeclarationNode() 46 : type( 0 ) 47 , storageClass( NoStorageClass ) 48 , isInline( false ) 49 , isNoreturn( false ) 50 , bitfieldWidth( 0 ) 51 , initializer( 0 ) 52 , hasEllipsis( false ) 53 , linkage( ::linkage ) 54 , extension( false ) 55 , error() { 56 attr.expr = nullptr; 57 attr.type = nullptr; 58 59 variable.tyClass = DeclarationNode::Type; 60 variable.assertions = nullptr; 61 } 62 63 DeclarationNode::~DeclarationNode() { 64 delete attr.expr; 65 delete attr.type; 66 delete type; 67 delete bitfieldWidth; 68 delete initializer; 69 } 44 70 45 71 DeclarationNode *DeclarationNode::clone() const { … … 55 81 newnode->set_next( maybeClone( get_next() ) ); 56 82 newnode->linkage = linkage; 83 84 newnode->variable.assertions = maybeClone( variable.assertions ); 85 newnode->variable.name = variable.name; 86 newnode->variable.tyClass = variable.tyClass; 87 88 newnode->attr.expr = maybeClone( attr.expr ); 89 newnode->attr.type = maybeClone( attr.type ); 57 90 return newnode; 58 91 } // DeclarationNode::clone 59 60 DeclarationNode::DeclarationNode()61 : type( 0 )62 , storageClass( NoStorageClass )63 , isInline( false )64 , isNoreturn( false )65 , bitfieldWidth( 0 )66 , initializer( 0 )67 , hasEllipsis( false )68 , linkage( ::linkage )69 , extension( false )70 , error() {71 }72 73 DeclarationNode::~DeclarationNode() {74 delete type;75 delete bitfieldWidth;76 delete initializer;77 }78 92 79 93 bool DeclarationNode::get_hasEllipsis() const { … … 129 143 130 144 newnode->type = new TypeData( TypeData::Function ); 131 newnode->type->function ->params = param;132 newnode->type->function ->newStyle = newStyle;133 newnode->type->function ->body = body;145 newnode->type->function.params = param; 146 newnode->type->function.newStyle = newStyle; 147 newnode->type->function.body = body; 134 148 typedefTable.addToEnclosingScope( newnode->name, TypedefTable::ID ); 135 149 136 150 if ( body ) { 137 newnode->type->function ->hasBody = true;151 newnode->type->function.hasBody = true; 138 152 } // if 139 153 … … 175 189 DeclarationNode *newnode = new DeclarationNode; 176 190 newnode->type = new TypeData( TypeData::Basic ); 177 newnode->type->basic ->typeSpec.push_back( bt );191 newnode->type->basic.typeSpec.push_back( bt ); 178 192 return newnode; 179 193 } // DeclarationNode::newBasicType … … 182 196 DeclarationNode *newnode = new DeclarationNode; 183 197 newnode->type = new TypeData( TypeData::Basic ); 184 newnode->type->basic ->modifiers.push_back( mod );198 newnode->type->basic.modifiers.push_back( mod ); 185 199 return newnode; 186 200 } // DeclarationNode::newModifier 187 201 188 DeclarationNode * DeclarationNode::newBuiltinType( BuiltinType bt ) {189 DeclarationNode *newnode = new DeclarationNode;190 newnode->type = new TypeData( TypeData::Builtin );191 newnode->type->builtin->type = bt;192 return newnode;193 } // DeclarationNode::newBuiltinType194 195 202 DeclarationNode * DeclarationNode::newFromTypedef( std::string *name ) { 196 203 DeclarationNode *newnode = new DeclarationNode; 197 204 newnode->type = new TypeData( TypeData::SymbolicInst ); 198 newnode->type->symbolic ->name = assign_strptr( name );199 newnode->type->symbolic ->isTypedef = true;200 newnode->type->symbolic ->params = 0;205 newnode->type->symbolic.name = assign_strptr( name ); 206 newnode->type->symbolic.isTypedef = true; 207 newnode->type->symbolic.params = 0; 201 208 return newnode; 202 209 } // DeclarationNode::newFromTypedef … … 205 212 DeclarationNode *newnode = new DeclarationNode; 206 213 newnode->type = new TypeData( TypeData::Aggregate ); 207 newnode->type->aggregate ->kind = kind;208 newnode->type->aggregate ->name = assign_strptr( name );209 if ( newnode->type->aggregate ->name == "" ) { // anonymous aggregate ?210 newnode->type->aggregate ->name = anonymous.newName();211 } // if 212 newnode->type->aggregate ->actuals = actuals;213 newnode->type->aggregate ->fields = fields;214 newnode->type->aggregate ->body = body;214 newnode->type->aggregate.kind = kind; 215 newnode->type->aggregate.name = assign_strptr( name ); 216 if ( newnode->type->aggregate.name == "" ) { // anonymous aggregate ? 217 newnode->type->aggregate.name = anonymous.newName(); 218 } // if 219 newnode->type->aggregate.actuals = actuals; 220 newnode->type->aggregate.fields = fields; 221 newnode->type->aggregate.body = body; 215 222 return newnode; 216 223 } // DeclarationNode::newAggregate … … 220 227 newnode->name = assign_strptr( name ); 221 228 newnode->type = new TypeData( TypeData::Enum ); 222 newnode->type->enumeration ->name = newnode->name;223 if ( newnode->type->enumeration ->name == "" ) { // anonymous enumeration ?224 newnode->type->enumeration ->name = DeclarationNode::anonymous.newName();225 } // if 226 newnode->type->enumeration ->constants = constants;229 newnode->type->enumeration.name = newnode->name; 230 if ( newnode->type->enumeration.name == "" ) { // anonymous enumeration ? 231 newnode->type->enumeration.name = DeclarationNode::anonymous.newName(); 232 } // if 233 newnode->type->enumeration.constants = constants; 227 234 return newnode; 228 235 } // DeclarationNode::newEnum … … 245 252 DeclarationNode *newnode = new DeclarationNode; 246 253 newnode->type = new TypeData( TypeData::SymbolicInst ); 247 newnode->type->symbolic ->name = assign_strptr( name );248 newnode->type->symbolic ->isTypedef = false;249 newnode->type->symbolic ->actuals = params;254 newnode->type->symbolic.name = assign_strptr( name ); 255 newnode->type->symbolic.isTypedef = false; 256 newnode->type->symbolic.actuals = params; 250 257 return newnode; 251 258 } // DeclarationNode::newFromTypeGen … … 255 262 newnode->name = assign_strptr( name ); 256 263 newnode->type = new TypeData( TypeData::Variable ); 257 newnode-> type->variable->tyClass = tc;258 newnode-> type->variable->name = newnode->name;264 newnode->variable.tyClass = tc; 265 newnode->variable.name = newnode->name; 259 266 return newnode; 260 267 } // DeclarationNode::newTypeParam … … 263 270 DeclarationNode *newnode = new DeclarationNode; 264 271 newnode->type = new TypeData( TypeData::Aggregate ); 265 newnode->type->aggregate ->kind = Trait;266 newnode->type->aggregate ->params = params;267 newnode->type->aggregate ->fields = asserts;268 newnode->type->aggregate ->name = assign_strptr( name );272 newnode->type->aggregate.kind = Trait; 273 newnode->type->aggregate.params = params; 274 newnode->type->aggregate.fields = asserts; 275 newnode->type->aggregate.name = assign_strptr( name ); 269 276 return newnode; 270 277 } // DeclarationNode::newTrait … … 273 280 DeclarationNode *newnode = new DeclarationNode; 274 281 newnode->type = new TypeData( TypeData::AggregateInst ); 275 newnode->type->aggInst ->aggregate = new TypeData( TypeData::Aggregate );276 newnode->type->aggInst ->aggregate->aggregate->kind = Trait;277 newnode->type->aggInst ->aggregate->aggregate->name = assign_strptr( name );278 newnode->type->aggInst ->params = params;282 newnode->type->aggInst.aggregate = new TypeData( TypeData::Aggregate ); 283 newnode->type->aggInst.aggregate->aggregate.kind = Trait; 284 newnode->type->aggInst.aggregate->aggregate.name = assign_strptr( name ); 285 newnode->type->aggInst.params = params; 279 286 return newnode; 280 287 } // DeclarationNode::newTraitUse … … 284 291 newnode->name = assign_strptr( name ); 285 292 newnode->type = new TypeData( TypeData::Symbolic ); 286 newnode->type->symbolic ->isTypedef = false;287 newnode->type->symbolic ->params = typeParams;288 newnode->type->symbolic ->name = newnode->name;293 newnode->type->symbolic.isTypedef = false; 294 newnode->type->symbolic.params = typeParams; 295 newnode->type->symbolic.name = newnode->name; 289 296 return newnode; 290 297 } // DeclarationNode::newTypeDecl … … 299 306 DeclarationNode *newnode = new DeclarationNode; 300 307 newnode->type = new TypeData( TypeData::Array ); 301 newnode->type->array ->dimension = size;302 newnode->type->array ->isStatic = isStatic;303 if ( newnode->type->array ->dimension == 0 || newnode->type->array->dimension->isExpressionType<ConstantExpr *>() ) {304 newnode->type->array ->isVarLen = false;308 newnode->type->array.dimension = size; 309 newnode->type->array.isStatic = isStatic; 310 if ( newnode->type->array.dimension == 0 || newnode->type->array.dimension->isExpressionType<ConstantExpr *>() ) { 311 newnode->type->array.isVarLen = false; 305 312 } else { 306 newnode->type->array ->isVarLen = true;313 newnode->type->array.isVarLen = true; 307 314 } // if 308 315 return newnode->addQualifiers( qualifiers ); … … 312 319 DeclarationNode *newnode = new DeclarationNode; 313 320 newnode->type = new TypeData( TypeData::Array ); 314 newnode->type->array ->dimension = 0;315 newnode->type->array ->isStatic = false;316 newnode->type->array ->isVarLen = true;321 newnode->type->array.dimension = 0; 322 newnode->type->array.isStatic = false; 323 newnode->type->array.isVarLen = true; 317 324 return newnode->addQualifiers( qualifiers ); 318 325 } … … 327 334 DeclarationNode *newnode = new DeclarationNode; 328 335 newnode->type = new TypeData( TypeData::Tuple ); 329 newnode->type->tuple ->members= members;336 newnode->type->tuple = members; 330 337 return newnode; 331 338 } … … 334 341 DeclarationNode *newnode = new DeclarationNode; 335 342 newnode->type = new TypeData( TypeData::Typeof ); 336 newnode->type->typeexpr->expr = expr; 337 return newnode; 338 } 343 newnode->type->typeexpr = expr; 344 return newnode; 345 } 346 347 DeclarationNode * DeclarationNode::newBuiltinType( BuiltinType bt ) { 348 DeclarationNode *newnode = new DeclarationNode; 349 newnode->type = new TypeData( TypeData::Builtin ); 350 newnode->builtin = bt; 351 return newnode; 352 } // DeclarationNode::newBuiltinType 339 353 340 354 DeclarationNode *DeclarationNode::newAttr( std::string *name, ExpressionNode *expr ) { 341 355 DeclarationNode *newnode = new DeclarationNode; 342 356 newnode->type = new TypeData( TypeData::Attr ); 343 newnode-> type->attr->name = assign_strptr( name );344 newnode-> type->attr->expr = expr;357 newnode->attr.name = assign_strptr( name ); 358 newnode->attr.expr = expr; 345 359 return newnode; 346 360 } … … 349 363 DeclarationNode *newnode = new DeclarationNode; 350 364 newnode->type = new TypeData( TypeData::Attr ); 351 newnode-> type->attr->name = assign_strptr( name );352 newnode-> type->attr->type = type;365 newnode->attr.name = assign_strptr( name ); 366 newnode->attr.type = type; 353 367 return newnode; 354 368 } … … 407 421 } else { 408 422 if ( type->kind == TypeData::Aggregate ) { 409 type->aggregate ->params = q->type->forall;423 type->aggregate.params = q->type->forall; 410 424 // change implicit typedef from TYPEDEFname to TYPEGENname 411 typedefTable.changeKind( type->aggregate ->name, TypedefTable::TG );425 typedefTable.changeKind( type->aggregate.name, TypedefTable::TG ); 412 426 } else { 413 427 type->forall = q->type->forall; … … 457 471 if ( src->kind != TypeData::Unknown ) { 458 472 assert( src->kind == TypeData::Basic ); 459 dst->basic ->modifiers.splice( dst->basic->modifiers.end(), src->basic->modifiers );460 dst->basic ->typeSpec.splice( dst->basic->typeSpec.end(), src->basic->typeSpec );473 dst->basic.modifiers.splice( dst->basic.modifiers.end(), src->basic.modifiers ); 474 dst->basic.typeSpec.splice( dst->basic.typeSpec.end(), src->basic.typeSpec ); 461 475 } // if 462 476 break; … … 466 480 case TypeData::Enum: 467 481 dst->base = new TypeData( TypeData::AggregateInst ); 468 dst->base->aggInst ->aggregate = src;482 dst->base->aggInst.aggregate = src; 469 483 if ( src->kind == TypeData::Aggregate ) { 470 dst->base->aggInst ->params = maybeClone( src->aggregate->actuals );484 dst->base->aggInst.params = maybeClone( src->aggregate.actuals ); 471 485 } // if 472 486 dst->base->qualifiers |= src->qualifiers; … … 495 509 if ( o->type->kind == TypeData::Aggregate || o->type->kind == TypeData::Enum ) { 496 510 type = new TypeData( TypeData::AggregateInst ); 497 type->aggInst ->aggregate = o->type;511 type->aggInst.aggregate = o->type; 498 512 if ( o->type->kind == TypeData::Aggregate ) { 499 type->aggInst ->params = maybeClone( o->type->aggregate->actuals );513 type->aggInst.params = maybeClone( o->type->aggregate.actuals ); 500 514 } // if 501 515 type->qualifiers |= o->type->qualifiers; … … 523 537 DeclarationNode *DeclarationNode::addTypedef() { 524 538 TypeData *newtype = new TypeData( TypeData::Symbolic ); 525 newtype->symbolic ->params = 0;526 newtype->symbolic ->isTypedef = true;527 newtype->symbolic ->name = name;539 newtype->symbolic.params = 0; 540 newtype->symbolic.isTypedef = true; 541 newtype->symbolic.name = name; 528 542 newtype->base = type; 529 543 type = newtype; … … 535 549 switch ( type->kind ) { 536 550 case TypeData::Symbolic: 537 if ( type->symbolic ->assertions ) {538 type->symbolic ->assertions->appendList( assertions );551 if ( type->symbolic.assertions ) { 552 type->symbolic.assertions->appendList( assertions ); 539 553 } else { 540 type->symbolic ->assertions = assertions;554 type->symbolic.assertions = assertions; 541 555 } // if 542 556 break; 543 557 case TypeData::Variable: 544 if ( type->variable->assertions ) {545 type->variable->assertions->appendList( assertions );558 if ( variable.assertions ) { 559 variable.assertions->appendList( assertions ); 546 560 } else { 547 type->variable->assertions = assertions;561 variable.assertions = assertions; 548 562 } // if 549 563 break; … … 574 588 assert( type ); 575 589 assert( type->kind == TypeData::Function ); 576 assert( type->function ->body == 0 );577 type->function ->body = body;578 type->function ->hasBody = true;590 assert( type->function.body == 0 ); 591 type->function.body = body; 592 type->function.hasBody = true; 579 593 return this; 580 594 } … … 583 597 assert( type ); 584 598 assert( type->kind == TypeData::Function ); 585 assert( type->function ->oldDeclList == 0 );586 type->function ->oldDeclList = list;599 assert( type->function.oldDeclList == 0 ); 600 type->function.oldDeclList = list; 587 601 return this; 588 602 } … … 630 644 case TypeData::Enum: 631 645 p->type->base = new TypeData( TypeData::AggregateInst ); 632 p->type->base->aggInst ->aggregate = type;646 p->type->base->aggInst.aggregate = type; 633 647 if ( type->kind == TypeData::Aggregate ) { 634 p->type->base->aggInst ->params = maybeClone( type->aggregate->actuals );648 p->type->base->aggInst.params = maybeClone( type->aggregate.actuals ); 635 649 } // if 636 650 p->type->base->qualifiers |= type->qualifiers; … … 667 681 case TypeData::Enum: 668 682 lastArray->base = new TypeData( TypeData::AggregateInst ); 669 lastArray->base->aggInst ->aggregate = type;683 lastArray->base->aggInst.aggregate = type; 670 684 if ( type->kind == TypeData::Aggregate ) { 671 lastArray->base->aggInst ->params = maybeClone( type->aggregate->actuals );685 lastArray->base->aggInst.params = maybeClone( type->aggregate.actuals ); 672 686 } // if 673 687 lastArray->base->qualifiers |= type->qualifiers; … … 687 701 DeclarationNode *DeclarationNode::addParamList( DeclarationNode *params ) { 688 702 TypeData *ftype = new TypeData( TypeData::Function ); 689 ftype->function ->params = params;703 ftype->function.params = params; 690 704 setBase( type, ftype ); 691 705 return this; … … 697 711 type->base = addIdListToType( type->base, ids ); 698 712 } else { 699 type->function ->idList = ids;713 type->function.idList = ids; 700 714 } // if 701 715 return type; 702 716 } else { 703 717 TypeData *newtype = new TypeData( TypeData::Function ); 704 newtype->function ->idList = ids;718 newtype->function.idList = ids; 705 719 return newtype; 706 720 } // if … … 727 741 if ( newnode->type->kind == TypeData::AggregateInst ) { 728 742 // don't duplicate members 729 if ( newnode->type->aggInst ->aggregate->kind == TypeData::Enum ) {730 delete newnode->type->aggInst ->aggregate->enumeration->constants;731 newnode->type->aggInst ->aggregate->enumeration->constants = 0;743 if ( newnode->type->aggInst.aggregate->kind == TypeData::Enum ) { 744 delete newnode->type->aggInst.aggregate->enumeration.constants; 745 newnode->type->aggInst.aggregate->enumeration.constants = 0; 732 746 } else { 733 assert( newnode->type->aggInst ->aggregate->kind == TypeData::Aggregate );734 delete newnode->type->aggInst ->aggregate->aggregate->fields;735 newnode->type->aggInst ->aggregate->aggregate->fields = 0;747 assert( newnode->type->aggInst.aggregate->kind == TypeData::Aggregate ); 748 delete newnode->type->aggInst.aggregate->aggregate.fields; 749 newnode->type->aggInst.aggregate->aggregate.fields = 0; 736 750 } // if 737 751 } // if … … 753 767 if ( newType->kind == TypeData::AggregateInst ) { 754 768 // don't duplicate members 755 if ( newType->aggInst ->aggregate->kind == TypeData::Enum ) {756 delete newType->aggInst ->aggregate->enumeration->constants;757 newType->aggInst ->aggregate->enumeration->constants = 0;769 if ( newType->aggInst.aggregate->kind == TypeData::Enum ) { 770 delete newType->aggInst.aggregate->enumeration.constants; 771 newType->aggInst.aggregate->enumeration.constants = 0; 758 772 } else { 759 assert( newType->aggInst ->aggregate->kind == TypeData::Aggregate );760 delete newType->aggInst ->aggregate->aggregate->fields;761 newType->aggInst ->aggregate->aggregate->fields = 0;773 assert( newType->aggInst.aggregate->kind == TypeData::Aggregate ); 774 delete newType->aggInst.aggregate->aggregate.fields; 775 newType->aggInst.aggregate->aggregate.fields = 0; 762 776 } // if 763 777 } // if … … 896 910 if ( ! error.empty() ) throw SemanticError( error, this ); 897 911 if ( type ) { 898 return buildDecl( type, name, storageClass, maybeBuild< Expression >( bitfieldWidth ), isInline, isNoreturn, linkage, maybeBuild< Initializer >(initializer) )->set_extension( extension ); 912 if ( type->kind == TypeData::Variable ) { 913 static const TypeDecl::Kind kindMap[] = { TypeDecl::Any, TypeDecl::Ftype, TypeDecl::Dtype }; 914 TypeDecl * ret = new TypeDecl( variable.name, DeclarationNode::NoStorageClass, 0, kindMap[ variable.tyClass ] ); 915 buildList( variable.assertions, ret->get_assertions() ); 916 return ret; 917 } else { 918 return buildDecl( type, name, storageClass, maybeBuild< Expression >( bitfieldWidth ), isInline, isNoreturn, linkage, maybeBuild< Initializer >(initializer) )->set_extension( extension ); 919 } // if 899 920 } // if 900 921 if ( ! isInline && ! isNoreturn ) { … … 909 930 switch ( type->kind ) { 910 931 case TypeData::Enum: 911 return new EnumInstType( buildQualifiers( type ), type->enumeration ->name );932 return new EnumInstType( buildQualifiers( type ), type->enumeration.name ); 912 933 case TypeData::Aggregate: { 913 934 ReferenceToType *ret; 914 switch ( type->aggregate ->kind ) {935 switch ( type->aggregate.kind ) { 915 936 case DeclarationNode::Struct: 916 ret = new StructInstType( buildQualifiers( type ), type->aggregate ->name );937 ret = new StructInstType( buildQualifiers( type ), type->aggregate.name ); 917 938 break; 918 939 case DeclarationNode::Union: 919 ret = new UnionInstType( buildQualifiers( type ), type->aggregate ->name );940 ret = new UnionInstType( buildQualifiers( type ), type->aggregate.name ); 920 941 break; 921 942 case DeclarationNode::Trait: 922 ret = new TraitInstType( buildQualifiers( type ), type->aggregate ->name );943 ret = new TraitInstType( buildQualifiers( type ), type->aggregate.name ); 923 944 break; 924 945 default: 925 946 assert( false ); 926 947 } // switch 927 buildList( type->aggregate ->actuals, ret->get_parameters() );948 buildList( type->aggregate.actuals, ret->get_parameters() ); 928 949 return ret; 929 950 } 930 951 case TypeData::Symbolic: { 931 TypeInstType *ret = new TypeInstType( buildQualifiers( type ), type->symbolic->name, false ); 932 buildList( type->symbolic->actuals, ret->get_parameters() ); 952 TypeInstType *ret = new TypeInstType( buildQualifiers( type ), type->symbolic.name, false ); 953 buildList( type->symbolic.actuals, ret->get_parameters() ); 954 return ret; 955 } 956 case TypeData::Attr: { 957 assert( type->kind == TypeData::Attr ); 958 // assert( type->attr ); 959 AttrType * ret; 960 if ( attr.expr ) { 961 ret = new AttrType( buildQualifiers( type ), attr.name, attr.expr->build() ); 962 } else { 963 assert( attr.type ); 964 ret = new AttrType( buildQualifiers( type ), attr.name, attr.type->buildType() ); 965 } // if 933 966 return ret; 934 967 } -
src/Parser/ParseNode.cc
r1f75e2d r5fda7143 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // ParseNode.cc -- 7 // ParseNode.cc -- 8 8 // 9 9 // Author : Rodolfo G. Esteves … … 12 12 // Last Modified On : Wed Aug 17 23:14:16 2016 13 13 // Update Count : 126 14 // 14 // 15 15 16 16 #include "ParseNode.h" … … 19 19 int ParseNode::indent_by = 4; 20 20 21 std::ostream & operator<<( std::ostream & out, const ParseNode * node ) { 22 node->print( out ); 23 return out; 24 } 25 21 26 // Local Variables: // 22 27 // tab-width: 4 // -
src/Parser/ParseNode.h
r1f75e2d r5fda7143 10 10 // Created On : Sat May 16 13:28:16 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sun Aug 28 21:14:51201613 // Update Count : 5 7512 // Last Modified On : Mon Aug 29 21:45:43 2016 13 // Update Count : 583 14 14 // 15 15 … … 290 290 // bool buildFuncSpecifier( StorageClass key ) const; 291 291 292 struct Enumeration_t { 293 std::string name; 294 DeclarationNode * constants; 295 }; 296 Enumeration_t enumeration; 297 298 struct Variable_t { 299 DeclarationNode::TypeClass tyClass; 300 std::string name; 301 DeclarationNode * assertions; 302 }; 303 Variable_t variable; 304 305 struct Attr_t { 306 std::string name; 307 ExpressionNode * expr; 308 DeclarationNode * type; 309 }; 310 Attr_t attr; 311 312 BuiltinType builtin; 313 292 314 TypeData *type; 293 315 std::string name; … … 409 431 } 410 432 433 // in ParseNode.cc 434 std::ostream & operator<<( std::ostream & out, const ParseNode * node ); 411 435 412 436 #endif // PARSENODE_H -
src/Parser/TypeData.cc
r1f75e2d r5fda7143 10 10 // Created On : Sat May 16 15:12:51 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sun Aug 28 18:28:58201613 // Update Count : 2 2312 // Last Modified On : Mon Aug 29 22:31:53 2016 13 // Update Count : 277 14 14 // 15 15 … … 33 33 break; 34 34 case Basic: 35 basic = new Basic_t;35 // basic = new Basic_t; 36 36 break; 37 37 case Array: 38 array = new Array_t;39 array ->dimension = 0;40 array ->isVarLen = false;41 array ->isStatic = false;38 // array = new Array_t; 39 array.dimension = 0; 40 array.isVarLen = false; 41 array.isStatic = false; 42 42 break; 43 43 case Function: 44 function = new Function_t;45 function ->params = 0;46 function ->idList = 0;47 function ->oldDeclList = 0;48 function ->body = 0;49 function ->hasBody = false;50 function ->newStyle = false;44 // function = new Function_t; 45 function.params = 0; 46 function.idList = 0; 47 function.oldDeclList = 0; 48 function.body = 0; 49 function.hasBody = false; 50 function.newStyle = false; 51 51 break; 52 52 case Aggregate: 53 aggregate = new Aggregate_t;54 aggregate ->params = 0;55 aggregate ->actuals = 0;56 aggregate ->fields = 0;53 // aggregate = new Aggregate_t; 54 aggregate.params = 0; 55 aggregate.actuals = 0; 56 aggregate.fields = 0; 57 57 break; 58 58 case AggregateInst: 59 aggInst = new AggInst_t;60 aggInst ->aggregate = 0;61 aggInst ->params = 0;59 // aggInst = new AggInst_t; 60 aggInst.aggregate = 0; 61 aggInst.params = 0; 62 62 break; 63 63 case Enum: 64 enumeration = new Enumeration_t;65 enumeration ->constants = 0;64 // enumeration = new Enumeration_t; 65 enumeration.constants = 0; 66 66 break; 67 67 case Symbolic: 68 68 case SymbolicInst: 69 symbolic = new Symbolic_t;70 symbolic ->params = 0;71 symbolic ->actuals = 0;72 symbolic ->assertions = 0;69 // symbolic = new Symbolic_t; 70 symbolic.params = 0; 71 symbolic.actuals = 0; 72 symbolic.assertions = 0; 73 73 break; 74 74 case Variable: 75 variable = new Variable_t;76 variable->tyClass = DeclarationNode::Type;77 variable->assertions = 0;75 // variable = new Variable_t; 76 // variable.tyClass = DeclarationNode::Type; 77 // variable.assertions = 0; 78 78 break; 79 79 case Tuple: 80 tuple = new Tuple_t;81 tuple ->members = 0;80 // tuple = new Tuple_t; 81 tuple = nullptr; 82 82 break; 83 83 case Typeof: 84 typeexpr = new Typeof_t; 85 typeexpr->expr = 0; 84 // typeexpr = new Typeof_t; 85 typeexpr = nullptr; 86 break; 87 case Attr: 88 // attr = new Attr_t; 89 // attr.expr = nullptr; 90 // attr.type = nullptr; 86 91 break; 87 92 case Builtin: 88 builtin = new Builtin_t; 89 break; 90 case Attr: 91 attr = new Attr_t; 92 attr->expr = 0; 93 attr->type = 0; 93 // builtin = new Builtin_t; 94 94 break; 95 95 } // switch … … 107 107 break; 108 108 case Basic: 109 delete basic;109 // delete basic; 110 110 break; 111 111 case Array: 112 delete array ->dimension;113 delete array;112 delete array.dimension; 113 // delete array; 114 114 break; 115 115 case Function: 116 delete function ->params;117 delete function ->idList;118 delete function ->oldDeclList;119 delete function ->body;120 delete function;116 delete function.params; 117 delete function.idList; 118 delete function.oldDeclList; 119 delete function.body; 120 // delete function; 121 121 break; 122 122 case Aggregate: 123 delete aggregate ->params;124 delete aggregate ->actuals;125 delete aggregate ->fields;126 delete aggregate;123 delete aggregate.params; 124 delete aggregate.actuals; 125 delete aggregate.fields; 126 // delete aggregate; 127 127 break; 128 128 case AggregateInst: 129 delete aggInst ->aggregate;130 delete aggInst ->params;131 delete aggInst;129 delete aggInst.aggregate; 130 delete aggInst.params; 131 // delete aggInst; 132 132 break; 133 133 case Enum: 134 delete enumeration ->constants;135 delete enumeration;134 delete enumeration.constants; 135 // delete enumeration; 136 136 break; 137 137 case Symbolic: 138 138 case SymbolicInst: 139 delete symbolic ->params;140 delete symbolic ->actuals;141 delete symbolic ->assertions;142 delete symbolic;139 delete symbolic.params; 140 delete symbolic.actuals; 141 delete symbolic.assertions; 142 // delete symbolic; 143 143 break; 144 144 case Variable: 145 delete variable->assertions;146 delete variable;145 // delete variable.assertions; 146 // delete variable; 147 147 break; 148 148 case Tuple: 149 delete tuple->members;149 // delete tuple->members; 150 150 delete tuple; 151 151 break; 152 152 case Typeof: 153 delete typeexpr->expr;153 // delete typeexpr->expr; 154 154 delete typeexpr; 155 155 break; 156 case Attr: 157 // delete attr.expr; 158 // delete attr.type; 159 // delete attr; 160 break; 156 161 case Builtin: 157 delete builtin; 158 break; 159 case Attr: 160 delete attr->expr; 161 delete attr->type; 162 delete attr; 162 // delete builtin; 163 163 break; 164 164 } // switch … … 178 178 break; 179 179 case Basic: 180 newtype->basic ->typeSpec = basic->typeSpec;181 newtype->basic ->modifiers = basic->modifiers;180 newtype->basic.typeSpec = basic.typeSpec; 181 newtype->basic.modifiers = basic.modifiers; 182 182 break; 183 183 case Array: 184 newtype->array ->dimension = maybeClone( array->dimension );185 newtype->array ->isVarLen = array->isVarLen;186 newtype->array ->isStatic = array->isStatic;184 newtype->array.dimension = maybeClone( array.dimension ); 185 newtype->array.isVarLen = array.isVarLen; 186 newtype->array.isStatic = array.isStatic; 187 187 break; 188 188 case Function: 189 newtype->function ->params = maybeClone( function->params );190 newtype->function ->idList = maybeClone( function->idList );191 newtype->function ->oldDeclList = maybeClone( function->oldDeclList );192 newtype->function ->body = maybeClone( function->body );193 newtype->function ->hasBody = function->hasBody;194 newtype->function ->newStyle = function->newStyle;189 newtype->function.params = maybeClone( function.params ); 190 newtype->function.idList = maybeClone( function.idList ); 191 newtype->function.oldDeclList = maybeClone( function.oldDeclList ); 192 newtype->function.body = maybeClone( function.body ); 193 newtype->function.hasBody = function.hasBody; 194 newtype->function.newStyle = function.newStyle; 195 195 break; 196 196 case Aggregate: 197 newtype->aggregate ->params = maybeClone( aggregate->params );198 newtype->aggregate ->actuals = maybeClone( aggregate->actuals );199 newtype->aggregate ->fields = maybeClone( aggregate->fields );200 newtype->aggregate ->name = aggregate->name;201 newtype->aggregate ->kind = aggregate->kind;202 newtype->aggregate ->body = aggregate->body;197 newtype->aggregate.params = maybeClone( aggregate.params ); 198 newtype->aggregate.actuals = maybeClone( aggregate.actuals ); 199 newtype->aggregate.fields = maybeClone( aggregate.fields ); 200 newtype->aggregate.name = aggregate.name; 201 newtype->aggregate.kind = aggregate.kind; 202 newtype->aggregate.body = aggregate.body; 203 203 break; 204 204 case AggregateInst: 205 newtype->aggInst ->aggregate = maybeClone( aggInst->aggregate );206 newtype->aggInst ->params = maybeClone( aggInst->params );205 newtype->aggInst.aggregate = maybeClone( aggInst.aggregate ); 206 newtype->aggInst.params = maybeClone( aggInst.params ); 207 207 break; 208 208 case Enum: 209 newtype->enumeration ->name = enumeration->name;210 newtype->enumeration ->constants = maybeClone( enumeration->constants );209 newtype->enumeration.name = enumeration.name; 210 newtype->enumeration.constants = maybeClone( enumeration.constants ); 211 211 break; 212 212 case Symbolic: 213 213 case SymbolicInst: 214 newtype->symbolic ->params = maybeClone( symbolic->params );215 newtype->symbolic ->actuals = maybeClone( symbolic->actuals );216 newtype->symbolic ->assertions = maybeClone( symbolic->assertions );217 newtype->symbolic ->isTypedef = symbolic->isTypedef;218 newtype->symbolic ->name = symbolic->name;214 newtype->symbolic.params = maybeClone( symbolic.params ); 215 newtype->symbolic.actuals = maybeClone( symbolic.actuals ); 216 newtype->symbolic.assertions = maybeClone( symbolic.assertions ); 217 newtype->symbolic.isTypedef = symbolic.isTypedef; 218 newtype->symbolic.name = symbolic.name; 219 219 break; 220 220 case Variable: 221 newtype->variable->assertions = maybeClone( variable->assertions ); 222 newtype->variable->name = variable->name; 223 newtype->variable->tyClass = variable->tyClass; 221 assert( false ); 222 // newtype->variable.assertions = maybeClone( variable.assertions ); 223 // newtype->variable.name = variable.name; 224 // newtype->variable.tyClass = variable.tyClass; 224 225 break; 225 226 case Tuple: 226 newtype->tuple ->members = maybeClone( tuple->members);227 newtype->tuple = maybeClone( tuple ); 227 228 break; 228 229 case Typeof: 229 newtype->typeexpr->expr = maybeClone( typeexpr->expr ); 230 newtype->typeexpr = maybeClone( typeexpr ); 231 break; 232 case Attr: 233 assert( false ); 234 // newtype->attr.expr = maybeClone( attr.expr ); 235 // newtype->attr.type = maybeClone( attr.type ); 230 236 break; 231 237 case Builtin: 232 newtype->builtin->type = builtin->type; 233 break; 234 case Attr: 235 newtype->attr->expr = maybeClone( attr->expr ); 236 newtype->attr->type = maybeClone( attr->type ); 238 assert( false ); 239 // newtype->builtin = builtin; 237 240 break; 238 241 } // switch … … 268 271 break; 269 272 case Basic: 270 printEnums( basic ->modifiers.begin(), basic->modifiers.end(), DeclarationNode::modifierName, os );271 printEnums( basic ->typeSpec.begin(), basic->typeSpec.end(), DeclarationNode::basicTypeName, os );273 printEnums( basic.modifiers.begin(), basic.modifiers.end(), DeclarationNode::modifierName, os ); 274 printEnums( basic.typeSpec.begin(), basic.typeSpec.end(), DeclarationNode::basicTypeName, os ); 272 275 break; 273 276 case Array: 274 if ( array ->isStatic ) {277 if ( array.isStatic ) { 275 278 os << "static "; 276 279 } // if 277 if ( array ->dimension ) {280 if ( array.dimension ) { 278 281 os << "array of "; 279 array ->dimension->printOneLine( os, indent );280 } else if ( array ->isVarLen ) {282 array.dimension->printOneLine( os, indent ); 283 } else if ( array.isVarLen ) { 281 284 os << "variable-length array of "; 282 285 } else { … … 289 292 case Function: 290 293 os << "function" << endl; 291 if ( function ->params ) {294 if ( function.params ) { 292 295 os << string( indent + 2, ' ' ) << "with parameters " << endl; 293 function ->params->printList( os, indent + 4 );296 function.params->printList( os, indent + 4 ); 294 297 } else { 295 298 os << string( indent + 2, ' ' ) << "with no parameters " << endl; 296 299 } // if 297 if ( function ->idList ) {300 if ( function.idList ) { 298 301 os << string( indent + 2, ' ' ) << "with old-style identifier list " << endl; 299 function ->idList->printList( os, indent + 4 );300 } // if 301 if ( function ->oldDeclList ) {302 function.idList->printList( os, indent + 4 ); 303 } // if 304 if ( function.oldDeclList ) { 302 305 os << string( indent + 2, ' ' ) << "with old-style declaration list " << endl; 303 function ->oldDeclList->printList( os, indent + 4 );306 function.oldDeclList->printList( os, indent + 4 ); 304 307 } // if 305 308 os << string( indent + 2, ' ' ) << "returning "; … … 310 313 } // if 311 314 os << endl; 312 if ( function ->hasBody ) {315 if ( function.hasBody ) { 313 316 os << string( indent + 2, ' ' ) << "with body " << endl; 314 317 } // if 315 if ( function ->body ) {316 function ->body->printList( os, indent + 2 );318 if ( function.body ) { 319 function.body->printList( os, indent + 2 ); 317 320 } // if 318 321 break; 319 322 case Aggregate: 320 os << DeclarationNode::aggregateName[ aggregate ->kind ] << ' ' << aggregate->name << endl;321 if ( aggregate ->params ) {323 os << DeclarationNode::aggregateName[ aggregate.kind ] << ' ' << aggregate.name << endl; 324 if ( aggregate.params ) { 322 325 os << string( indent + 2, ' ' ) << "with type parameters " << endl; 323 aggregate ->params->printList( os, indent + 4 );324 } // if 325 if ( aggregate ->actuals ) {326 aggregate.params->printList( os, indent + 4 ); 327 } // if 328 if ( aggregate.actuals ) { 326 329 os << string( indent + 2, ' ' ) << "instantiated with actual parameters " << endl; 327 aggregate ->actuals->printList( os, indent + 4 );328 } // if 329 if ( aggregate ->fields ) {330 aggregate.actuals->printList( os, indent + 4 ); 331 } // if 332 if ( aggregate.fields ) { 330 333 os << string( indent + 2, ' ' ) << "with members " << endl; 331 aggregate ->fields->printList( os, indent + 4 );332 } // if 333 if ( aggregate ->body ) {334 aggregate.fields->printList( os, indent + 4 ); 335 } // if 336 if ( aggregate.body ) { 334 337 os << string( indent + 2, ' ' ) << " with body " << endl; 335 338 } // if 336 339 break; 337 340 case AggregateInst: 338 if ( aggInst ->aggregate ) {341 if ( aggInst.aggregate ) { 339 342 os << "instance of " ; 340 aggInst ->aggregate->print( os, indent );343 aggInst.aggregate->print( os, indent ); 341 344 } else { 342 345 os << "instance of an unspecified aggregate "; 343 346 } // if 344 if ( aggInst ->params ) {347 if ( aggInst.params ) { 345 348 os << string( indent + 2, ' ' ) << "with parameters " << endl; 346 aggInst ->params->printList( os, indent + 2 );349 aggInst.params->printList( os, indent + 2 ); 347 350 } // if 348 351 break; 349 352 case Enum: 350 353 os << "enumeration "; 351 if ( enumeration ->constants ) {354 if ( enumeration.constants ) { 352 355 os << "with constants" << endl; 353 enumeration ->constants->printList( os, indent + 2 );356 enumeration.constants->printList( os, indent + 2 ); 354 357 } // if 355 358 break; 356 359 case SymbolicInst: 357 os << "instance of type " << symbolic ->name;358 if ( symbolic ->actuals ) {360 os << "instance of type " << symbolic.name; 361 if ( symbolic.actuals ) { 359 362 os << " with parameters" << endl; 360 symbolic ->actuals->printList( os, indent + 2 );363 symbolic.actuals->printList( os, indent + 2 ); 361 364 } // if 362 365 break; 363 366 case Symbolic: 364 if ( symbolic ->isTypedef ) {367 if ( symbolic.isTypedef ) { 365 368 os << "typedef definition "; 366 369 } else { 367 370 os << "type definition "; 368 371 } // if 369 if ( symbolic ->params ) {372 if ( symbolic.params ) { 370 373 os << endl << string( indent + 2, ' ' ) << "with parameters" << endl; 371 symbolic ->params->printList( os, indent + 2 );372 } // if 373 if ( symbolic ->assertions ) {374 symbolic.params->printList( os, indent + 2 ); 375 } // if 376 if ( symbolic.assertions ) { 374 377 os << endl << string( indent + 2, ' ' ) << "with assertions" << endl; 375 symbolic ->assertions->printList( os, indent + 4 );378 symbolic.assertions->printList( os, indent + 4 ); 376 379 os << string( indent + 2, ' ' ); 377 380 } // if … … 382 385 break; 383 386 case Variable: 384 os << DeclarationNode::typeClassName[ variable->tyClass ] << " variable ";385 if ( variable->assertions ) {386 os << endl << string( indent + 2, ' ' ) << "with assertions" << endl;387 variable->assertions->printList( os, indent + 4 );388 os << string( indent + 2, ' ' );389 } // if387 // os << DeclarationNode::typeClassName[ variable.tyClass ] << " variable "; 388 // if ( variable.assertions ) { 389 // os << endl << string( indent + 2, ' ' ) << "with assertions" << endl; 390 // variable.assertions->printList( os, indent + 4 ); 391 // os << string( indent + 2, ' ' ); 392 // } // if 390 393 break; 391 394 case Tuple: 392 395 os << "tuple "; 393 if ( tuple ->members) {396 if ( tuple ) { 394 397 os << "with members " << endl; 395 tuple-> members->printList( os, indent + 2 );398 tuple->printList( os, indent + 2 ); 396 399 } // if 397 400 break; 398 401 case Typeof: 399 402 os << "type-of expression "; 400 if ( typeexpr ->expr) {401 typeexpr-> expr->print( os, indent + 2 );403 if ( typeexpr ) { 404 typeexpr->print( os, indent + 2 ); 402 405 } // if 403 406 break; 404 407 case Attr: 405 os << "attribute type decl " << attr->name << " applied to ";406 if ( attr->expr ) {407 attr->expr->print( os, indent + 2 );408 } // if409 if ( attr->type ) {410 attr->type->print( os, indent + 2 );411 } // if408 // os << "attribute type decl " << attr.name << " applied to "; 409 // if ( attr.expr ) { 410 // attr.expr->print( os, indent + 2 ); 411 // } // if 412 // if ( attr.type ) { 413 // attr.type->print( os, indent + 2 ); 414 // } // if 412 415 break; 413 416 case Builtin: … … 479 482 return new VarArgsType( buildQualifiers( td ) ); 480 483 case TypeData::Attr: 484 assert( false ); 481 485 return buildAttr( td ); 482 486 case TypeData::Symbolic: … … 494 498 switch ( td->kind ) { 495 499 case TypeData::Aggregate: 496 if ( ! toplevel && td->aggregate ->fields ) {500 if ( ! toplevel && td->aggregate.fields ) { 497 501 ret = td->clone(); 498 502 } // if 499 503 break; 500 504 case TypeData::Enum: 501 if ( ! toplevel && td->enumeration ->constants ) {505 if ( ! toplevel && td->enumeration.constants ) { 502 506 ret = td->clone(); 503 507 } // if 504 508 break; 505 509 case TypeData::AggregateInst: 506 if ( td->aggInst ->aggregate ) {507 ret = typeextractAggregate( td->aggInst ->aggregate, false );510 if ( td->aggInst.aggregate ) { 511 ret = typeextractAggregate( td->aggInst.aggregate, false ); 508 512 } // if 509 513 break; … … 535 539 BasicType::Kind ret; 536 540 537 for ( std::list< DeclarationNode::BasicType >::const_iterator i = td->basic ->typeSpec.begin(); i != td->basic->typeSpec.end(); ++i ) {541 for ( std::list< DeclarationNode::BasicType >::const_iterator i = td->basic.typeSpec.begin(); i != td->basic.typeSpec.end(); ++i ) { 538 542 if ( ! init ) { 539 543 init = true; 540 544 if ( *i == DeclarationNode::Void ) { 541 if ( td->basic ->typeSpec.size() != 1 || ! td->basic->modifiers.empty() ) {545 if ( td->basic.typeSpec.size() != 1 || ! td->basic.modifiers.empty() ) { 542 546 throw SemanticError( "invalid type specifier \"void\" in type: ", td ); 543 547 } else { … … 611 615 } // for 612 616 613 for ( std::list< DeclarationNode::Modifier >::const_iterator i = td->basic ->modifiers.begin(); i != td->basic->modifiers.end(); ++i ) {617 for ( std::list< DeclarationNode::Modifier >::const_iterator i = td->basic.modifiers.begin(); i != td->basic.modifiers.end(); ++i ) { 614 618 switch ( *i ) { 615 619 case DeclarationNode::Long: … … 746 750 ArrayType * at; 747 751 if ( td->base ) { 748 at = new ArrayType( buildQualifiers( td ), typebuild( td->base ), maybeBuild< Expression >( td->array ->dimension ),749 td->array ->isVarLen, td->array->isStatic );752 at = new ArrayType( buildQualifiers( td ), typebuild( td->base ), maybeBuild< Expression >( td->array.dimension ), 753 td->array.isVarLen, td->array.isStatic ); 750 754 } else { 751 755 at = new ArrayType( buildQualifiers( td ), new BasicType( Type::Qualifiers(), BasicType::SignedInt ), 752 maybeBuild< Expression >( td->array ->dimension ), td->array->isVarLen, td->array->isStatic );756 maybeBuild< Expression >( td->array.dimension ), td->array.isVarLen, td->array.isStatic ); 753 757 } // if 754 758 buildForall( td->forall, at->get_forall() ); … … 759 763 assert( td->kind == TypeData::Aggregate ); 760 764 AggregateDecl * at; 761 switch ( td->aggregate ->kind ) {765 switch ( td->aggregate.kind ) { 762 766 case DeclarationNode::Struct: 763 at = new StructDecl( td->aggregate ->name );764 buildForall( td->aggregate ->params, at->get_parameters() );767 at = new StructDecl( td->aggregate.name ); 768 buildForall( td->aggregate.params, at->get_parameters() ); 765 769 break; 766 770 case DeclarationNode::Union: 767 at = new UnionDecl( td->aggregate ->name );768 buildForall( td->aggregate ->params, at->get_parameters() );771 at = new UnionDecl( td->aggregate.name ); 772 buildForall( td->aggregate.params, at->get_parameters() ); 769 773 break; 770 774 case DeclarationNode::Trait: 771 at = new TraitDecl( td->aggregate ->name );772 buildList( td->aggregate ->params, at->get_parameters() );775 at = new TraitDecl( td->aggregate.name ); 776 buildList( td->aggregate.params, at->get_parameters() ); 773 777 break; 774 778 default: … … 776 780 } // switch 777 781 778 buildList( td->aggregate ->fields, at->get_members() );779 at->set_body( td->aggregate ->body );782 buildList( td->aggregate.fields, at->get_members() ); 783 at->set_body( td->aggregate.body ); 780 784 781 785 return at; … … 786 790 787 791 ReferenceToType * ret; 788 if ( td->aggInst ->aggregate->kind == TypeData::Enum ) {789 ret = new EnumInstType( buildQualifiers( td ), td->aggInst ->aggregate->enumeration->name );792 if ( td->aggInst.aggregate->kind == TypeData::Enum ) { 793 ret = new EnumInstType( buildQualifiers( td ), td->aggInst.aggregate->enumeration.name ); 790 794 } else { 791 assert( td->aggInst ->aggregate->kind == TypeData::Aggregate );792 switch ( td->aggInst ->aggregate->aggregate->kind ) {795 assert( td->aggInst.aggregate->kind == TypeData::Aggregate ); 796 switch ( td->aggInst.aggregate->aggregate.kind ) { 793 797 case DeclarationNode::Struct: 794 ret = new StructInstType( buildQualifiers( td ), td->aggInst ->aggregate->aggregate->name );798 ret = new StructInstType( buildQualifiers( td ), td->aggInst.aggregate->aggregate.name ); 795 799 break; 796 800 case DeclarationNode::Union: 797 ret = new UnionInstType( buildQualifiers( td ), td->aggInst ->aggregate->aggregate->name );801 ret = new UnionInstType( buildQualifiers( td ), td->aggInst.aggregate->aggregate.name ); 798 802 break; 799 803 case DeclarationNode::Trait: 800 ret = new TraitInstType( buildQualifiers( td ), td->aggInst ->aggregate->aggregate->name );804 ret = new TraitInstType( buildQualifiers( td ), td->aggInst.aggregate->aggregate.name ); 801 805 break; 802 806 default: … … 804 808 } // switch 805 809 } // if 806 buildList( td->aggInst ->params, ret->get_parameters() );810 buildList( td->aggInst.params, ret->get_parameters() ); 807 811 buildForall( td->forall, ret->get_forall() ); 808 812 return ret; … … 813 817 NamedTypeDecl * ret; 814 818 assert( td->base ); 815 if ( td->symbolic ->isTypedef ) {819 if ( td->symbolic.isTypedef ) { 816 820 ret = new TypedefDecl( name, sc, typebuild( td->base ) ); 817 821 } else { 818 822 ret = new TypeDecl( name, sc, typebuild( td->base ), TypeDecl::Any ); 819 823 } // if 820 buildList( td->symbolic ->params, ret->get_parameters() );821 buildList( td->symbolic ->assertions, ret->get_assertions() );824 buildList( td->symbolic.params, ret->get_parameters() ); 825 buildList( td->symbolic.assertions, ret->get_assertions() ); 822 826 return ret; 823 827 } // buildSymbolic 824 828 825 829 TypeDecl * buildVariable( const TypeData * td ) { 826 assert( td->kind == TypeData::Variable ); 827 static const TypeDecl::Kind kindMap[] = { TypeDecl::Any, TypeDecl::Ftype, TypeDecl::Dtype }; 828 829 TypeDecl * ret = new TypeDecl( td->variable->name, DeclarationNode::NoStorageClass, 0, kindMap[ td->variable->tyClass ] ); 830 buildList( td->variable->assertions, ret->get_assertions() ); 831 return ret; 830 assert( false ); 831 return nullptr; 832 // assert( td->kind == TypeData::Variable ); 833 // static const TypeDecl::Kind kindMap[] = { TypeDecl::Any, TypeDecl::Ftype, TypeDecl::Dtype }; 834 835 // TypeDecl * ret = new TypeDecl( td->variable.name, DeclarationNode::NoStorageClass, 0, kindMap[ td->variable.tyClass ] ); 836 // buildList( td->variable.assertions, ret->get_assertions() ); 837 // return ret; 832 838 } // buildSymbolic 833 839 834 840 EnumDecl * buildEnum( const TypeData * td ) { 835 841 assert( td->kind == TypeData::Enum ); 836 EnumDecl * ret = new EnumDecl( td->enumeration ->name );837 buildList( td->enumeration ->constants, ret->get_members() );842 EnumDecl * ret = new EnumDecl( td->enumeration.name ); 843 buildList( td->enumeration.constants, ret->get_members() ); 838 844 std::list< Declaration * >::iterator members = ret->get_members().begin(); 839 for ( const DeclarationNode * cur = td->enumeration ->constants; cur != nullptr; cur = dynamic_cast< DeclarationNode * >( cur->get_next() ), ++members ) {845 for ( const DeclarationNode * cur = td->enumeration. constants; cur != nullptr; cur = dynamic_cast< DeclarationNode * >( cur->get_next() ), ++members ) { 840 846 if ( cur->has_enumeratorValue() ) { 841 847 ObjectDecl * member = dynamic_cast< ObjectDecl * >(* members); … … 848 854 TypeInstType * buildSymbolicInst( const TypeData * td ) { 849 855 assert( td->kind == TypeData::SymbolicInst ); 850 TypeInstType * ret = new TypeInstType( buildQualifiers( td ), td->symbolic ->name, false );851 buildList( td->symbolic ->actuals, ret->get_parameters() );856 TypeInstType * ret = new TypeInstType( buildQualifiers( td ), td->symbolic.name, false ); 857 buildList( td->symbolic.actuals, ret->get_parameters() ); 852 858 buildForall( td->forall, ret->get_forall() ); 853 859 return ret; … … 857 863 assert( td->kind == TypeData::Tuple ); 858 864 TupleType * ret = new TupleType( buildQualifiers( td ) ); 859 buildTypeList( td->tuple ->members, ret->get_types() );865 buildTypeList( td->tuple, ret->get_types() ); 860 866 buildForall( td->forall, ret->get_forall() ); 861 867 return ret; … … 865 871 assert( td->kind == TypeData::Typeof ); 866 872 assert( td->typeexpr ); 867 assert( td->typeexpr->expr );868 return new TypeofType( buildQualifiers( td ), td->typeexpr-> expr->build() );873 // assert( td->typeexpr->expr ); 874 return new TypeofType( buildQualifiers( td ), td->typeexpr->build() ); 869 875 } // buildTypeof 870 876 871 877 AttrType * buildAttr( const TypeData * td ) { 872 assert( td->kind == TypeData::Attr ); 873 assert( td->attr ); 874 AttrType * ret; 875 if ( td->attr->expr ) { 876 ret = new AttrType( buildQualifiers( td ), td->attr->name, td->attr->expr->build() ); 877 } else { 878 assert( td->attr->type ); 879 ret = new AttrType( buildQualifiers( td ), td->attr->name, td->attr->type->buildType() ); 880 } // if 881 return ret; 878 assert( false ); 879 return nullptr; 880 // assert( td->kind == TypeData::Attr ); 881 // // assert( td->attr ); 882 // AttrType * ret; 883 // if ( td->attr.expr ) { 884 // ret = new AttrType( buildQualifiers( td ), td->attr.name, td->attr.expr->build() ); 885 // } else { 886 // assert( td->attr.type ); 887 // ret = new AttrType( buildQualifiers( td ), td->attr.name, td->attr.type->buildType() ); 888 // } // if 889 // return ret; 882 890 } // buildAttr 883 891 … … 885 893 if ( td->kind == TypeData::Function ) { 886 894 FunctionDecl * decl; 887 if ( td->function ->hasBody ) {888 if ( td->function ->body ) {889 Statement * stmt = td->function ->body->build();895 if ( td->function.hasBody ) { 896 if ( td->function.body ) { 897 Statement * stmt = td->function.body->build(); 890 898 CompoundStmt * body = dynamic_cast< CompoundStmt* >( stmt ); 891 899 assert( body ); … … 898 906 decl = new FunctionDecl( name, sc, linkage, buildFunction( td ), 0, isInline, isNoreturn ); 899 907 } // if 900 for ( DeclarationNode * cur = td->function ->idList; cur != 0; cur = dynamic_cast< DeclarationNode* >( cur->get_next() ) ) {908 for ( DeclarationNode * cur = td->function.idList; cur != 0; cur = dynamic_cast< DeclarationNode* >( cur->get_next() ) ) { 901 909 if ( cur->get_name() != "" ) { 902 910 decl->get_oldIdents().insert( decl->get_oldIdents().end(), cur->get_name() ); 903 911 } // if 904 912 } // for 905 buildList( td->function ->oldDeclList, decl->get_oldDecls() );913 buildList( td->function.oldDeclList, decl->get_oldDecls() ); 906 914 return decl; 907 915 } else if ( td->kind == TypeData::Aggregate ) { … … 912 920 return buildSymbolic( td, name, sc ); 913 921 } else if ( td->kind == TypeData::Variable ) { 922 assert( false ); 914 923 return buildVariable( td ); 915 924 } else { … … 921 930 FunctionType * buildFunction( const TypeData * td ) { 922 931 assert( td->kind == TypeData::Function ); 923 bool hasEllipsis = td->function ->params ? td->function->params->get_hasEllipsis() : true;924 if ( ! td->function ->params ) hasEllipsis = ! td->function->newStyle;932 bool hasEllipsis = td->function.params ? td->function.params->get_hasEllipsis() : true; 933 if ( ! td->function.params ) hasEllipsis = ! td->function.newStyle; 925 934 FunctionType * ft = new FunctionType( buildQualifiers( td ), hasEllipsis ); 926 buildList( td->function ->params, ft->get_parameters() );935 buildList( td->function.params, ft->get_parameters() ); 927 936 buildForall( td->forall, ft->get_forall() ); 928 937 if ( td->base ) { 929 938 switch ( td->base->kind ) { 930 939 case TypeData::Tuple: 931 buildList( td->base->tuple ->members, ft->get_returnVals() );940 buildList( td->base->tuple, ft->get_returnVals() ); 932 941 break; 933 942 default: -
src/Parser/TypeData.h
r1f75e2d r5fda7143 10 10 // Created On : Sat May 16 15:18:36 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sun Aug 28 22:39:00201613 // Update Count : 8512 // Last Modified On : Mon Aug 29 22:31:52 2016 13 // Update Count : 110 14 14 // 15 15 … … 24 24 struct TypeData { 25 25 enum Kind { Unknown, Basic, Pointer, Array, Function, Aggregate, AggregateInst, 26 Enum, EnumConstant, Symbolic, SymbolicInst, Variable, Tuple, Typeof, Builtin, Attr } kind;26 Enum, EnumConstant, Symbolic, SymbolicInst, Variable, Tuple, Typeof, Builtin, Attr }; 27 27 28 28 struct Basic_t { … … 73 73 }; 74 74 75 struct Variable_t { 76 DeclarationNode::TypeClass tyClass; 77 std::string name; 78 DeclarationNode * assertions; 79 }; 75 // struct Tuple_t { 76 // DeclarationNode * members; 77 // }; 78 79 // struct Typeof_t { 80 // ExpressionNode * expr; 81 // }; 80 82 81 struct Tuple_t { 82 DeclarationNode * members; 83 }; 84 85 struct Typeof_t { 86 ExpressionNode * expr; 87 }; 83 // struct Builtin_t { 84 // DeclarationNode::BuiltinType type; 85 // }; 88 86 89 struct Builtin_t { 90 DeclarationNode::BuiltinType type; 91 }; 92 93 struct Attr_t { 94 std::string name; 95 ExpressionNode * expr; 96 DeclarationNode * type; 97 }; 98 87 Kind kind; 99 88 TypeData * base; 100 89 typedef std::bitset< DeclarationNode::NoOfQualifier > Qualifiers; … … 102 91 DeclarationNode * forall; 103 92 104 union { 105 Basic_t * basic; 106 Aggregate_t * aggregate; 107 AggInst_t * aggInst; 108 Array_t * array; 109 Enumeration_t * enumeration; 110 Function_t * function; 111 Symbolic_t * symbolic; 112 Variable_t * variable; 113 Tuple_t * tuple; 114 Typeof_t * typeexpr; 115 Attr_t * attr; 116 Builtin_t * builtin; 117 }; 93 Basic_t basic; 94 Aggregate_t aggregate; 95 AggInst_t aggInst; 96 Array_t array; 97 Enumeration_t enumeration; 98 Function_t function; 99 Symbolic_t symbolic; 100 DeclarationNode * tuple; 101 ExpressionNode * typeexpr; 102 //Attr_t attr; 103 // DeclarationNode::BuiltinType builtin; 118 104 119 105 TypeData( Kind k = Unknown ); -
src/ResolvExpr/AlternativeFinder.cc
r1f75e2d r5fda7143 42 42 #include "Common/utility.h" 43 43 #include "InitTweak/InitTweak.h" 44 #include "ResolveTypeof.h" 44 45 45 46 extern bool resolvep; … … 707 708 void AlternativeFinder::visit( CastExpr *castExpr ) { 708 709 for ( std::list< Type* >::iterator i = castExpr->get_results().begin(); i != castExpr->get_results().end(); ++i ) { 710 *i = resolveTypeof( *i, indexer ); 709 711 SymTab::validateType( *i, &indexer ); 710 712 adjustExprType( *i, env, indexer ); … … 795 797 796 798 void AlternativeFinder::visit( VariableExpr *variableExpr ) { 797 alternatives.push_back( Alternative( variableExpr->clone(), env, Cost::zero ) ); 799 // not sufficient to clone here, because variable's type may have changed 800 // since the VariableExpr was originally created. 801 alternatives.push_back( Alternative( new VariableExpr( variableExpr->get_var() ), env, Cost::zero ) ); 798 802 } 799 803 … … 804 808 void AlternativeFinder::visit( SizeofExpr *sizeofExpr ) { 805 809 if ( sizeofExpr->get_isType() ) { 810 // xxx - resolveTypeof? 806 811 alternatives.push_back( Alternative( sizeofExpr->clone(), env, Cost::zero ) ); 807 812 } else { … … 823 828 void AlternativeFinder::visit( AlignofExpr *alignofExpr ) { 824 829 if ( alignofExpr->get_isType() ) { 830 // xxx - resolveTypeof? 825 831 alternatives.push_back( Alternative( alignofExpr->clone(), env, Cost::zero ) ); 826 832 } else { … … 856 862 void AlternativeFinder::visit( UntypedOffsetofExpr *offsetofExpr ) { 857 863 AlternativeFinder funcFinder( indexer, env ); 864 // xxx - resolveTypeof? 858 865 if ( StructInstType *structInst = dynamic_cast< StructInstType* >( offsetofExpr->get_type() ) ) { 859 866 addOffsetof( structInst, offsetofExpr->get_member() ); -
src/ResolvExpr/Resolver.cc
r1f75e2d r5fda7143 528 528 529 529 void Resolver::visit( ConstructorInit *ctorInit ) { 530 try { 531 maybeAccept( ctorInit->get_ctor(), *this ); 532 maybeAccept( ctorInit->get_dtor(), *this ); 533 } catch ( SemanticError ) { 534 // no alternatives for the constructor initializer - fallback on C-style initializer 535 // xxx - not sure if this makes a ton of sense - should maybe never be able to have this situation? 536 fallbackInit( ctorInit ); 537 return; 538 } 530 // xxx - fallback init has been removed => remove fallbackInit function and remove complexity from FixInit and remove C-init from ConstructorInit 531 maybeAccept( ctorInit->get_ctor(), *this ); 532 maybeAccept( ctorInit->get_dtor(), *this ); 539 533 540 534 // found a constructor - can get rid of C-style initializer -
src/SymTab/Autogen.h
r1f75e2d r5fda7143 102 102 } 103 103 104 ObjectDecl *index = new ObjectDecl( indexName.newName(), DeclarationNode::NoStorageClass, LinkageSpec::C, 0, new BasicType( Type::Qualifiers(), BasicType::SignedInt ), NULL ); 105 106 UntypedExpr *init = new UntypedExpr( new NameExpr( "?=?" ) ); 107 init->get_args().push_back( new AddressExpr( new VariableExpr( index ) ) ); 108 init->get_args().push_back( begin ); 109 index->set_init( new SingleInit( init, std::list<Expression*>() ) ); 104 ObjectDecl *index = new ObjectDecl( indexName.newName(), DeclarationNode::NoStorageClass, LinkageSpec::C, 0, new BasicType( Type::Qualifiers(), BasicType::SignedInt ), new SingleInit( begin, std::list<Expression*>() ) ); 110 105 111 106 UntypedExpr *cond = new UntypedExpr( cmp ); -
src/SymTab/Indexer.cc
r1f75e2d r5fda7143 21 21 #include <unordered_set> 22 22 #include <utility> 23 #include <algorithm> 23 24 24 25 #include "Mangler.h" … … 33 34 #include "SynTree/Initializer.h" 34 35 #include "SynTree/Statement.h" 36 37 #include "InitTweak/InitTweak.h" 35 38 36 39 #define debugPrint(x) if ( doDebug ) { std::cout << x; } … … 99 102 100 103 if ( --toFree->refCount == 0 ) delete toFree; 104 } 105 106 void Indexer::removeSpecialOverrides( const std::string &id, std::list< DeclarationWithType * > & out ) const { 107 // only need to perform this step for constructors and destructors 108 if ( ! InitTweak::isCtorDtor( id ) ) return; 109 110 // helpful data structure 111 struct ValueType { 112 struct DeclBall { 113 FunctionDecl * decl; 114 bool isUserDefinedFunc; // properties for this particular decl 115 bool isDefaultFunc; 116 bool isCopyFunc; 117 }; 118 // properties for this type 119 bool userDefinedFunc = false; // any user defined function found 120 bool userDefinedDefaultFunc = false; // user defined default ctor found 121 bool userDefinedCopyFunc = false; // user defined copy ctor found 122 std::list< DeclBall > decls; 123 124 // another FunctionDecl for the current type was found - determine 125 // if it has special properties and update data structure accordingly 126 ValueType & operator+=( FunctionDecl * function ) { 127 bool isUserDefinedFunc = ! LinkageSpec::isOverridable( function->get_linkage() ); 128 bool isDefaultFunc = function->get_functionType()->get_parameters().size() == 1; 129 bool isCopyFunc = InitTweak::isCopyConstructor( function ); 130 decls.push_back( DeclBall{ function, isUserDefinedFunc, isDefaultFunc, isCopyFunc } ); 131 userDefinedFunc = userDefinedFunc || isUserDefinedFunc; 132 userDefinedDefaultFunc = userDefinedDefaultFunc || (isUserDefinedFunc && isDefaultFunc); 133 userDefinedCopyFunc = userDefinedCopyFunc || (isUserDefinedFunc && isCopyFunc); 134 return *this; 135 } 136 }; // ValueType 137 138 std::list< DeclarationWithType * > copy; 139 copy.splice( copy.end(), out ); 140 141 // organize discovered declarations by type 142 std::unordered_map< std::string, ValueType > funcMap; 143 for ( DeclarationWithType * decl : copy ) { 144 if ( FunctionDecl * function = dynamic_cast< FunctionDecl * >( decl ) ) { 145 std::list< DeclarationWithType * > params = function->get_functionType()->get_parameters(); 146 assert( ! params.empty() ); 147 funcMap[ Mangler::mangle( params.front()->get_type() ) ] += function; 148 } else { 149 out.push_back( decl ); 150 } 151 } 152 153 // if a type contains user defined ctor/dtors, then special rules trigger, which determine 154 // the set of ctor/dtors that are seen by the requester. In particular, if the user defines 155 // a default ctor, then the generated default ctor should never be seen, likewise for copy ctor 156 // and dtor. If the user defines any ctor/dtor, then no generated field ctors should be seen. 157 for ( std::pair< const std::string, ValueType > & pair : funcMap ) { 158 ValueType & val = pair.second; 159 for ( ValueType::DeclBall ball : val.decls ) { 160 if ( ! val.userDefinedFunc || ball.isUserDefinedFunc || (! val.userDefinedDefaultFunc && ball.isDefaultFunc) || (! val.userDefinedCopyFunc && ball.isCopyFunc) ) { 161 // decl conforms to the rules described above, so it should be seen by the requester 162 out.push_back( ball.decl ); 163 } 164 } 165 } 101 166 } 102 167 … … 461 526 searchTables = searchTables->base.tables; 462 527 } 528 529 // some special functions, e.g. constructors and destructors 530 // remove autogenerated functions when they are defined so that 531 // they can never be matched 532 removeSpecialOverrides( id, out ); 463 533 } 464 534 -
src/SymTab/Indexer.h
r1f75e2d r5fda7143 128 128 static void deleteRef( Impl *toFree ); 129 129 130 // Removes matching autogenerated constructors and destructors 131 // so that they will not be selected 132 // void removeSpecialOverrides( FunctionDecl *decl ); 133 void removeSpecialOverrides( const std::string &id, std::list< DeclarationWithType * > & out ) const; 134 130 135 /// Ensures that tables variable is writable (i.e. allocated, uniquely owned by this Indexer, and at the current scope) 131 136 void makeWritable(); -
src/SynTree/Declaration.cc
r1f75e2d r5fda7143 56 56 } 57 57 58 std::ostream & operator<<( std::ostream & out, Declaration * decl ) {58 std::ostream & operator<<( std::ostream & out, const Declaration * decl ) { 59 59 decl->print( out ); 60 60 return out; -
src/SynTree/Declaration.h
r1f75e2d r5fda7143 279 279 }; 280 280 281 std::ostream & operator<<( std::ostream & out, Declaration * decl );281 std::ostream & operator<<( std::ostream & out, const Declaration * decl ); 282 282 283 283 #endif // DECLARATION_H -
src/SynTree/Expression.cc
r1f75e2d r5fda7143 358 358 assert( member ); 359 359 os << std::string( indent + 2, ' ' ); 360 os << (void*)member << " ";361 360 member->print( os, indent + 2 ); 362 361 os << std::endl; … … 541 540 } 542 541 543 std::ostream & operator<<( std::ostream & out, Expression * expr ) {542 std::ostream & operator<<( std::ostream & out, const Expression * expr ) { 544 543 expr->print( out ); 545 544 return out; -
src/SynTree/Expression.h
r1f75e2d r5fda7143 653 653 }; 654 654 655 std::ostream & operator<<( std::ostream & out, Expression * expr );655 std::ostream & operator<<( std::ostream & out, const Expression * expr ); 656 656 657 657 #endif // EXPRESSION_H -
src/SynTree/FunctionDecl.cc
r1f75e2d r5fda7143 21 21 #include "Attribute.h" 22 22 #include "Common/utility.h" 23 #include "InitTweak/InitTweak.h" 23 24 24 25 FunctionDecl::FunctionDecl( const std::string &name, DeclarationNode::StorageClass sc, LinkageSpec::Spec linkage, FunctionType *type, CompoundStmt *statements, bool isInline, bool isNoreturn, std::list< Attribute * > attributes ) -
src/SynTree/Statement.cc
r1f75e2d r5fda7143 387 387 } 388 388 389 std::ostream & operator<<( std::ostream & out, Statement * statement ) {389 std::ostream & operator<<( std::ostream & out, const Statement * statement ) { 390 390 statement->print( out ); 391 391 return out; -
src/SynTree/Statement.h
r1f75e2d r5fda7143 47 47 48 48 std::list<Statement*>& get_kids() { return kids; } 49 void push_back( Statement * stmt ) { kids.push_back( stmt ); } 50 void push_front( Statement * stmt ) { kids.push_front( stmt ); } 49 51 50 52 virtual CompoundStmt *clone() const { return new CompoundStmt( *this ); } … … 395 397 396 398 397 std::ostream & operator<<( std::ostream & out, Statement * statement );399 std::ostream & operator<<( std::ostream & out, const Statement * statement ); 398 400 399 401 #endif // STATEMENT_H -
src/SynTree/Type.cc
r1f75e2d r5fda7143 84 84 } 85 85 86 std::ostream & operator<<( std::ostream & out, Type * type ) {86 std::ostream & operator<<( std::ostream & out, const Type * type ) { 87 87 type->print( out ); 88 88 return out; -
src/SynTree/Type.h
r1f75e2d r5fda7143 481 481 } 482 482 483 std::ostream & operator<<( std::ostream & out, Type * type );483 std::ostream & operator<<( std::ostream & out, const Type * type ); 484 484 485 485 #endif // TYPE_H -
src/main.cc
r1f75e2d r5fda7143 10 10 // Created On : Fri May 15 23:12:02 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sat Aug 20 12:52:22201613 // Update Count : 4 0312 // Last Modified On : Mon Aug 29 17:34:39 2016 13 // Update Count : 426 14 14 // 15 15 … … 75 75 static void dump( list< Declaration * > & translationUnit, ostream & out = cout ); 76 76 77 void sigSegvBusHandler( int sig_num ) {77 void backtrace( int start ) { // skip first N stack frames 78 78 enum { Frames = 50 }; 79 79 void * array[Frames]; 80 80 int size = backtrace( array, Frames ); 81 82 cerr << "*CFA runtime error* program cfa-cpp terminated with "83 << (sig_num == SIGSEGV ? "segment fault" : "bus error")84 << " backtrace:" << endl;85 86 81 char ** messages = backtrace_symbols( array, size ); 87 82 88 // skip first stack frame (points here)89 for ( int i = 2; i < size - 2 && messages != nullptr; i += 1 ) {83 // skip last 2 stack frames after main 84 for ( int i = start; i < size - 2 && messages != nullptr; i += 1 ) { 90 85 char * mangled_name = nullptr, * offset_begin = nullptr, * offset_end = nullptr; 91 86 for ( char *p = messages[i]; *p; ++p ) { // find parantheses and +offset … … 101 96 102 97 // if line contains symbol, attempt to demangle 98 int frameNo = i - start; 103 99 if ( mangled_name && offset_begin && offset_end && mangled_name < offset_begin ) { 104 100 *mangled_name++ = '\0'; … … 106 102 *offset_end++ = '\0'; 107 103 108 int status ;104 int status, frameNo = i - start; 109 105 char * real_name = __cxxabiv1::__cxa_demangle( mangled_name, 0, 0, &status ); 110 106 if ( status == 0 ) { // demangling successful ? 111 cerr << "(" << i - 2<< ") " << messages[i] << " : "107 cerr << "(" << frameNo << ") " << messages[i] << " : " 112 108 << real_name << "+" << offset_begin << offset_end << endl; 113 109 114 110 } else { // otherwise, output mangled name 115 cerr << "(" << i - 2<< ") " << messages[i] << " : "111 cerr << "(" << frameNo << ") " << messages[i] << " : " 116 112 << mangled_name << "+" << offset_begin << offset_end << endl; 117 113 } // if 118 114 free( real_name ); 119 115 } else { // otherwise, print the whole line 120 cerr << "(" << i - 2<< ") " << messages[i] << endl;116 cerr << "(" << frameNo << ") " << messages[i] << endl; 121 117 } // if 122 118 } // for 119 123 120 free( messages ); 121 } // backtrace 122 123 void sigSegvBusHandler( int sig_num ) { 124 cerr << "*CFA runtime error* program cfa-cpp terminated with " 125 << (sig_num == SIGSEGV ? "segment fault" : "bus error") 126 << " backtrace:" << endl; 127 backtrace( 2 ); // skip first 2 stack frames 124 128 exit( EXIT_FAILURE ); 125 129 } // sigSegvBusHandler 130 131 void sigAbortHandler( int sig_num ) { 132 backtrace( 6 ); // skip first 6 stack frames 133 signal( SIGABRT, SIG_DFL); // reset default signal handler 134 raise( SIGABRT ); // reraise SIGABRT 135 } // sigAbortHandler 136 126 137 127 138 int main( int argc, char * argv[] ) { … … 133 144 signal( SIGSEGV, sigSegvBusHandler ); 134 145 signal( SIGBUS, sigSegvBusHandler ); 146 signal( SIGABRT, sigAbortHandler ); 135 147 136 148 parse_cmdline( argc, argv, filename ); // process command-line arguments -
src/tests/.expect/32/declarationSpecifier.txt
r1f75e2d r5fda7143 530 530 return ((int )_retVal0); 531 531 } 532 __attribute__ ((constructor(),)) static void _init_declarationSpecifier(void){533 ((void)___constructor__F_P13s__anonymous0_autogen___1(((struct __anonymous0 *)(&__x10__CV13s__anonymous0_1))));534 ((void)___constructor__F_P13s__anonymous1_autogen___1(((struct __anonymous1 *)(&__x11__CV13s__anonymous1_1))));535 ((void)___constructor__F_P13s__anonymous2_autogen___1(((struct __anonymous2 *)(&__x12__CV13s__anonymous2_1))));536 ((void)___constructor__F_P13s__anonymous3_autogen___1(((struct __anonymous3 *)(&__x13__CV13s__anonymous3_1))));537 ((void)___constructor__F_P13s__anonymous4_autogen___1(((struct __anonymous4 *)(&__x14__CV13s__anonymous4_1))));538 ((void)___constructor__F_P13s__anonymous5_autogen___1(((struct __anonymous5 *)(&__x15__CV13s__anonymous5_1))));539 ((void)___constructor__F_P13s__anonymous6_autogen___1(((struct __anonymous6 *)(&__x16__CV13s__anonymous6_1))));540 ((void)___constructor__F_P13s__anonymous7_autogen___1(((struct __anonymous7 *)(&__x17__CV13s__anonymous7_1))));541 ((void)___constructor__F_P13s__anonymous8_autogen___1(((struct __anonymous8 *)(&__x29__CV13s__anonymous8_1))));542 ((void)___constructor__F_P13s__anonymous9_autogen___1(((struct __anonymous9 *)(&__x30__CV13s__anonymous9_1))));543 ((void)___constructor__F_P14s__anonymous10_autogen___1(((struct __anonymous10 *)(&__x31__CV14s__anonymous10_1))));544 ((void)___constructor__F_P14s__anonymous11_autogen___1(((struct __anonymous11 *)(&__x32__CV14s__anonymous11_1))));545 ((void)___constructor__F_P14s__anonymous12_autogen___1(((struct __anonymous12 *)(&__x33__CV14s__anonymous12_1))));546 ((void)___constructor__F_P14s__anonymous13_autogen___1(((struct __anonymous13 *)(&__x34__CV14s__anonymous13_1))));547 ((void)___constructor__F_P14s__anonymous14_autogen___1(((struct __anonymous14 *)(&__x35__CV14s__anonymous14_1))));548 ((void)___constructor__F_P14s__anonymous15_autogen___1(((struct __anonymous15 *)(&__x36__CV14s__anonymous15_1))));549 }550 __attribute__ ((destructor(),)) static void _destroy_declarationSpecifier(void){551 ((void)___destructor__F_P14s__anonymous15_autogen___1(((struct __anonymous15 *)(&__x36__CV14s__anonymous15_1))));552 ((void)___destructor__F_P14s__anonymous14_autogen___1(((struct __anonymous14 *)(&__x35__CV14s__anonymous14_1))));553 ((void)___destructor__F_P14s__anonymous13_autogen___1(((struct __anonymous13 *)(&__x34__CV14s__anonymous13_1))));554 ((void)___destructor__F_P14s__anonymous12_autogen___1(((struct __anonymous12 *)(&__x33__CV14s__anonymous12_1))));555 ((void)___destructor__F_P14s__anonymous11_autogen___1(((struct __anonymous11 *)(&__x32__CV14s__anonymous11_1))));556 ((void)___destructor__F_P14s__anonymous10_autogen___1(((struct __anonymous10 *)(&__x31__CV14s__anonymous10_1))));557 ((void)___destructor__F_P13s__anonymous9_autogen___1(((struct __anonymous9 *)(&__x30__CV13s__anonymous9_1))));558 ((void)___destructor__F_P13s__anonymous8_autogen___1(((struct __anonymous8 *)(&__x29__CV13s__anonymous8_1))));559 ((void)___destructor__F_P13s__anonymous7_autogen___1(((struct __anonymous7 *)(&__x17__CV13s__anonymous7_1))));560 ((void)___destructor__F_P13s__anonymous6_autogen___1(((struct __anonymous6 *)(&__x16__CV13s__anonymous6_1))));561 ((void)___destructor__F_P13s__anonymous5_autogen___1(((struct __anonymous5 *)(&__x15__CV13s__anonymous5_1))));562 ((void)___destructor__F_P13s__anonymous4_autogen___1(((struct __anonymous4 *)(&__x14__CV13s__anonymous4_1))));563 ((void)___destructor__F_P13s__anonymous3_autogen___1(((struct __anonymous3 *)(&__x13__CV13s__anonymous3_1))));564 ((void)___destructor__F_P13s__anonymous2_autogen___1(((struct __anonymous2 *)(&__x12__CV13s__anonymous2_1))));565 ((void)___destructor__F_P13s__anonymous1_autogen___1(((struct __anonymous1 *)(&__x11__CV13s__anonymous1_1))));566 ((void)___destructor__F_P13s__anonymous0_autogen___1(((struct __anonymous0 *)(&__x10__CV13s__anonymous0_1))));567 } -
src/tests/.expect/32/extension.txt
r1f75e2d r5fda7143 86 86 __extension__ int __c__i_2; 87 87 }; 88 int __i__i_2; 89 ((void)((*((int *)(&__i__i_2)))=(__extension__ __a__i_1+__extension__ 3)) /* ?{} */); 88 int __i__i_2 = ((int )(__extension__ __a__i_1+__extension__ 3)); 90 89 ((void)__extension__ 3); 91 90 ((void)__extension__ __a__i_1); -
src/tests/.expect/32/gccExtensions.txt
r1f75e2d r5fda7143 76 76 ((void)((*((int *)(&(*___dst__P2sS_2).__c__i_2)))=__c__i_2) /* ?{} */); 77 77 } 78 int __i__i_2; 79 ((void)((*((int *)(&__i__i_2)))=__extension__ 3) /* ?{} */); 78 int __i__i_2 = ((int )__extension__ 3); 80 79 __extension__ int __a__i_2; 81 80 __extension__ int __b__i_2; … … 133 132 } 134 133 struct s3 __x1__3ss3_2; 135 ((void)___constructor__F_P3ss3_autogen___2(((struct s3 *)(&__x1__3ss3_2))));136 134 struct s3 __y1__3ss3_2; 137 ((void)___constructor__F_P3ss3_autogen___2(((struct s3 *)(&__y1__3ss3_2))));138 135 struct s4 { 139 136 int __i__i_2; … … 141 138 inline struct s4 ___operator_assign__F3ss4_P3ss43ss4_autogen___2(struct s4 *___dst__P3ss4_2, struct s4 ___src__3ss4_2){ 142 139 ((void)((*___dst__P3ss4_2).__i__i_2=___src__3ss4_2.__i__i_2)); 143 ((void)___destructor__F_P3ss3_autogen___2(((struct s3 *)(&__y1__3ss3_2))));144 ((void)___destructor__F_P3ss3_autogen___2(((struct s3 *)(&__x1__3ss3_2))));145 140 return ((struct s4 )___src__3ss4_2); 146 141 } … … 158 153 } 159 154 struct s4 __x2__3ss4_2; 160 ((void)___constructor__F_P3ss4_autogen___2(((struct s4 *)(&__x2__3ss4_2))));161 155 struct s4 __y2__3ss4_2; 162 ((void)___constructor__F_P3ss4_autogen___2(((struct s4 *)(&__y2__3ss4_2))));163 156 int __m1__A0i_2[((unsigned int )10)]; 164 157 int __m2__A0A0i_2[((unsigned int )10)][((unsigned int )10)]; … … 166 159 int _retVal0 = { 0 }; 167 160 ((void)(_retVal0=0) /* ?{} */); 168 ((void)___destructor__F_P3ss4_autogen___2(((struct s4 *)(&__y2__3ss4_2))));169 ((void)___destructor__F_P3ss4_autogen___2(((struct s4 *)(&__x2__3ss4_2))));170 ((void)___destructor__F_P3ss3_autogen___2(((struct s3 *)(&__y1__3ss3_2))));171 ((void)___destructor__F_P3ss3_autogen___2(((struct s3 *)(&__x1__3ss3_2))));172 161 return ((int )_retVal0); 173 ((void)___destructor__F_P3ss4_autogen___2(((struct s4 *)(&__y2__3ss4_2))));174 ((void)___destructor__F_P3ss4_autogen___2(((struct s4 *)(&__x2__3ss4_2))));175 ((void)___destructor__F_P3ss3_autogen___2(((struct s3 *)(&__y1__3ss3_2))));176 ((void)___destructor__F_P3ss3_autogen___2(((struct s3 *)(&__x1__3ss3_2))));177 162 } -
src/tests/.expect/64/declarationSpecifier.txt
r1f75e2d r5fda7143 530 530 return ((int )_retVal0); 531 531 } 532 __attribute__ ((constructor(),)) static void _init_declarationSpecifier(void){533 ((void)___constructor__F_P13s__anonymous0_autogen___1(((struct __anonymous0 *)(&__x10__CV13s__anonymous0_1))));534 ((void)___constructor__F_P13s__anonymous1_autogen___1(((struct __anonymous1 *)(&__x11__CV13s__anonymous1_1))));535 ((void)___constructor__F_P13s__anonymous2_autogen___1(((struct __anonymous2 *)(&__x12__CV13s__anonymous2_1))));536 ((void)___constructor__F_P13s__anonymous3_autogen___1(((struct __anonymous3 *)(&__x13__CV13s__anonymous3_1))));537 ((void)___constructor__F_P13s__anonymous4_autogen___1(((struct __anonymous4 *)(&__x14__CV13s__anonymous4_1))));538 ((void)___constructor__F_P13s__anonymous5_autogen___1(((struct __anonymous5 *)(&__x15__CV13s__anonymous5_1))));539 ((void)___constructor__F_P13s__anonymous6_autogen___1(((struct __anonymous6 *)(&__x16__CV13s__anonymous6_1))));540 ((void)___constructor__F_P13s__anonymous7_autogen___1(((struct __anonymous7 *)(&__x17__CV13s__anonymous7_1))));541 ((void)___constructor__F_P13s__anonymous8_autogen___1(((struct __anonymous8 *)(&__x29__CV13s__anonymous8_1))));542 ((void)___constructor__F_P13s__anonymous9_autogen___1(((struct __anonymous9 *)(&__x30__CV13s__anonymous9_1))));543 ((void)___constructor__F_P14s__anonymous10_autogen___1(((struct __anonymous10 *)(&__x31__CV14s__anonymous10_1))));544 ((void)___constructor__F_P14s__anonymous11_autogen___1(((struct __anonymous11 *)(&__x32__CV14s__anonymous11_1))));545 ((void)___constructor__F_P14s__anonymous12_autogen___1(((struct __anonymous12 *)(&__x33__CV14s__anonymous12_1))));546 ((void)___constructor__F_P14s__anonymous13_autogen___1(((struct __anonymous13 *)(&__x34__CV14s__anonymous13_1))));547 ((void)___constructor__F_P14s__anonymous14_autogen___1(((struct __anonymous14 *)(&__x35__CV14s__anonymous14_1))));548 ((void)___constructor__F_P14s__anonymous15_autogen___1(((struct __anonymous15 *)(&__x36__CV14s__anonymous15_1))));549 }550 __attribute__ ((destructor(),)) static void _destroy_declarationSpecifier(void){551 ((void)___destructor__F_P14s__anonymous15_autogen___1(((struct __anonymous15 *)(&__x36__CV14s__anonymous15_1))));552 ((void)___destructor__F_P14s__anonymous14_autogen___1(((struct __anonymous14 *)(&__x35__CV14s__anonymous14_1))));553 ((void)___destructor__F_P14s__anonymous13_autogen___1(((struct __anonymous13 *)(&__x34__CV14s__anonymous13_1))));554 ((void)___destructor__F_P14s__anonymous12_autogen___1(((struct __anonymous12 *)(&__x33__CV14s__anonymous12_1))));555 ((void)___destructor__F_P14s__anonymous11_autogen___1(((struct __anonymous11 *)(&__x32__CV14s__anonymous11_1))));556 ((void)___destructor__F_P14s__anonymous10_autogen___1(((struct __anonymous10 *)(&__x31__CV14s__anonymous10_1))));557 ((void)___destructor__F_P13s__anonymous9_autogen___1(((struct __anonymous9 *)(&__x30__CV13s__anonymous9_1))));558 ((void)___destructor__F_P13s__anonymous8_autogen___1(((struct __anonymous8 *)(&__x29__CV13s__anonymous8_1))));559 ((void)___destructor__F_P13s__anonymous7_autogen___1(((struct __anonymous7 *)(&__x17__CV13s__anonymous7_1))));560 ((void)___destructor__F_P13s__anonymous6_autogen___1(((struct __anonymous6 *)(&__x16__CV13s__anonymous6_1))));561 ((void)___destructor__F_P13s__anonymous5_autogen___1(((struct __anonymous5 *)(&__x15__CV13s__anonymous5_1))));562 ((void)___destructor__F_P13s__anonymous4_autogen___1(((struct __anonymous4 *)(&__x14__CV13s__anonymous4_1))));563 ((void)___destructor__F_P13s__anonymous3_autogen___1(((struct __anonymous3 *)(&__x13__CV13s__anonymous3_1))));564 ((void)___destructor__F_P13s__anonymous2_autogen___1(((struct __anonymous2 *)(&__x12__CV13s__anonymous2_1))));565 ((void)___destructor__F_P13s__anonymous1_autogen___1(((struct __anonymous1 *)(&__x11__CV13s__anonymous1_1))));566 ((void)___destructor__F_P13s__anonymous0_autogen___1(((struct __anonymous0 *)(&__x10__CV13s__anonymous0_1))));567 } -
src/tests/.expect/64/extension.txt
r1f75e2d r5fda7143 86 86 __extension__ int __c__i_2; 87 87 }; 88 int __i__i_2; 89 ((void)((*((int *)(&__i__i_2)))=(__extension__ __a__i_1+__extension__ 3)) /* ?{} */); 88 int __i__i_2 = ((int )(__extension__ __a__i_1+__extension__ 3)); 90 89 ((void)__extension__ 3); 91 90 ((void)__extension__ __a__i_1); -
src/tests/.expect/64/gccExtensions.txt
r1f75e2d r5fda7143 76 76 ((void)((*((int *)(&(*___dst__P2sS_2).__c__i_2)))=__c__i_2) /* ?{} */); 77 77 } 78 int __i__i_2; 79 ((void)((*((int *)(&__i__i_2)))=__extension__ 3) /* ?{} */); 78 int __i__i_2 = ((int )__extension__ 3); 80 79 __extension__ int __a__i_2; 81 80 __extension__ int __b__i_2; … … 133 132 } 134 133 struct s3 __x1__3ss3_2; 135 ((void)___constructor__F_P3ss3_autogen___2(((struct s3 *)(&__x1__3ss3_2))));136 134 struct s3 __y1__3ss3_2; 137 ((void)___constructor__F_P3ss3_autogen___2(((struct s3 *)(&__y1__3ss3_2))));138 135 struct s4 { 139 136 int __i__i_2; … … 141 138 inline struct s4 ___operator_assign__F3ss4_P3ss43ss4_autogen___2(struct s4 *___dst__P3ss4_2, struct s4 ___src__3ss4_2){ 142 139 ((void)((*___dst__P3ss4_2).__i__i_2=___src__3ss4_2.__i__i_2)); 143 ((void)___destructor__F_P3ss3_autogen___2(((struct s3 *)(&__y1__3ss3_2))));144 ((void)___destructor__F_P3ss3_autogen___2(((struct s3 *)(&__x1__3ss3_2))));145 140 return ((struct s4 )___src__3ss4_2); 146 141 } … … 158 153 } 159 154 struct s4 __x2__3ss4_2; 160 ((void)___constructor__F_P3ss4_autogen___2(((struct s4 *)(&__x2__3ss4_2))));161 155 struct s4 __y2__3ss4_2; 162 ((void)___constructor__F_P3ss4_autogen___2(((struct s4 *)(&__y2__3ss4_2))));163 156 int __m1__A0i_2[((long unsigned int )10)]; 164 157 int __m2__A0A0i_2[((long unsigned int )10)][((long unsigned int )10)]; … … 166 159 int _retVal0 = { 0 }; 167 160 ((void)(_retVal0=0) /* ?{} */); 168 ((void)___destructor__F_P3ss4_autogen___2(((struct s4 *)(&__y2__3ss4_2))));169 ((void)___destructor__F_P3ss4_autogen___2(((struct s4 *)(&__x2__3ss4_2))));170 ((void)___destructor__F_P3ss3_autogen___2(((struct s3 *)(&__y1__3ss3_2))));171 ((void)___destructor__F_P3ss3_autogen___2(((struct s3 *)(&__x1__3ss3_2))));172 161 return ((int )_retVal0); 173 ((void)___destructor__F_P3ss4_autogen___2(((struct s4 *)(&__y2__3ss4_2))));174 ((void)___destructor__F_P3ss4_autogen___2(((struct s4 *)(&__x2__3ss4_2))));175 ((void)___destructor__F_P3ss3_autogen___2(((struct s3 *)(&__y1__3ss3_2))));176 ((void)___destructor__F_P3ss3_autogen___2(((struct s3 *)(&__x1__3ss3_2))));177 162 } -
src/tests/Makefile.am
r1f75e2d r5fda7143 62 62 ${CC} ${CFLAGS} -CFA -XCFA -p ${<} -o ${@} 63 63 64 ctorWarnings: ctorWarnings.c65 ${CC} ${CFALGS} - CFA -XCFA -p ${<} -o /dev/null 2>${@}64 memberCtors-ERR1: memberCtors.c 65 ${CC} ${CFALGS} -DERR1 ${<} -o ${@} 66 66 -
src/tests/Makefile.in
r1f75e2d r5fda7143 670 670 ${CC} ${CFLAGS} -CFA -XCFA -p ${<} -o ${@} 671 671 672 ctorWarnings: ctorWarnings.c673 ${CC} ${CFALGS} - CFA -XCFA -p ${<} -o /dev/null 2>${@}672 memberCtors-ERR1: memberCtors.c 673 ${CC} ${CFALGS} -DERR1 ${<} -o ${@} 674 674 675 675 # Tell versions [3.59,3.63) of GNU make to not export all variables. -
src/tests/typeof.c
r1f75e2d r5fda7143 8 8 typeof( int ( int, int p ) ) *v7; 9 9 typeof( [int] ( int, int p ) ) *v8; 10 (typeof(v1)) v2; // cast with typeof 10 11 }
Note: See TracChangeset
for help on using the changeset viewer.