Changes in / [5fda7143:1f75e2d]
- Location:
- src
- Files:
-
- 2 added
- 3 deleted
- 39 edited
-
Common/SemanticError.cc (modified) (2 diffs)
-
Common/SemanticError.h (modified) (3 diffs)
-
Common/utility.h (modified) (1 diff)
-
GenPoly/Box.cc (modified) (9 diffs)
-
GenPoly/PolyMutator.cc (modified) (2 diffs)
-
GenPoly/PolyMutator.h (modified) (5 diffs)
-
InitTweak/FixInit.cc (modified) (15 diffs)
-
InitTweak/GenInit.cc (modified) (9 diffs)
-
InitTweak/InitTweak.cc (modified) (6 diffs)
-
InitTweak/InitTweak.h (modified) (2 diffs)
-
Parser/DeclarationNode.cc (modified) (34 diffs)
-
Parser/ParseNode.cc (modified) (3 diffs)
-
Parser/ParseNode.h (modified) (3 diffs)
-
Parser/TypeData.cc (modified) (25 diffs)
-
Parser/TypeData.h (modified) (4 diffs)
-
ResolvExpr/AlternativeFinder.cc (modified) (6 diffs)
-
ResolvExpr/Resolver.cc (modified) (1 diff)
-
SymTab/Autogen.h (modified) (1 diff)
-
SymTab/Indexer.cc (modified) (4 diffs)
-
SymTab/Indexer.h (modified) (1 diff)
-
SynTree/Declaration.cc (modified) (1 diff)
-
SynTree/Declaration.h (modified) (1 diff)
-
SynTree/Expression.cc (modified) (2 diffs)
-
SynTree/Expression.h (modified) (1 diff)
-
SynTree/FunctionDecl.cc (modified) (1 diff)
-
SynTree/Statement.cc (modified) (1 diff)
-
SynTree/Statement.h (modified) (2 diffs)
-
SynTree/Type.cc (modified) (1 diff)
-
SynTree/Type.h (modified) (1 diff)
-
main.cc (modified) (5 diffs)
-
tests/.expect/32/declarationSpecifier.txt (modified) (1 diff)
-
tests/.expect/32/extension.txt (modified) (1 diff)
-
tests/.expect/32/gccExtensions.txt (modified) (5 diffs)
-
tests/.expect/64/declarationSpecifier.txt (modified) (1 diff)
-
tests/.expect/64/extension.txt (modified) (1 diff)
-
tests/.expect/64/gccExtensions.txt (modified) (5 diffs)
-
tests/.expect/ctorWarnings.txt (added)
-
tests/.expect/memberCtors-ERR1.txt (deleted)
-
tests/.expect/memberCtors.txt (deleted)
-
tests/Makefile.am (modified) (1 diff)
-
tests/Makefile.in (modified) (1 diff)
-
tests/ctorWarnings.c (added)
-
tests/memberCtors.c (deleted)
-
tests/typeof.c (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
src/Common/SemanticError.cc
r5fda7143 r1f75e2d 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 append(error );28 errors.push_back( std::string( "Error: " ) + error ); 29 29 } 30 30 31 31 void SemanticError::append( SemanticError &other ) { 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 ); 32 errors.splice( errors.end(), other.errors ); 37 33 } 38 34 -
src/Common/SemanticError.h
r5fda7143 r1f75e2d 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 & );34 33 bool isEmpty() const; 35 34 void print( std::ostream &os ); … … 43 42 template< typename T > 44 43 SemanticError::SemanticError( const std::string &error, const T *obj ) { 45 append( toString( error, obj ) ); 44 std::ostringstream os; 45 os << "Error: " << error; 46 obj->print( os ); 47 errors.push_back( os.str() ); 46 48 } 47 48 49 49 50 #endif // SEMANTICERROR_H -
src/Common/utility.h
r5fda7143 r1f75e2d 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 Foo270 // var = ...;271 // } // var's original value is restored272 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 297 267 #endif // _UTILITY_H 298 268 -
src/GenPoly/Box.cc
r5fda7143 r1f75e2d 158 158 class PolyGenericCalculator : public PolyMutator { 159 159 public: 160 typedef PolyMutator Parent;161 using Parent::mutate;162 163 160 template< typename DeclClass > 164 161 DeclClass *handleDecl( DeclClass *decl, Type *type ); … … 1678 1675 DeclClass * PolyGenericCalculator::handleDecl( DeclClass *decl, Type *type ) { 1679 1676 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();1677 knownLayouts.beginScope(); 1678 knownOffsets.beginScope(); 1679 1680 DeclClass *ret = static_cast< DeclClass *>( Mutator::mutate( decl ) ); 1681 1682 knownOffsets.endScope(); 1683 knownLayouts.endScope(); 1687 1684 endTypeScope(); 1688 1685 return ret; … … 1694 1691 1695 1692 DeclarationWithType * PolyGenericCalculator::mutate( FunctionDecl *functionDecl ) { 1696 knownLayouts.beginScope(); 1697 knownOffsets.beginScope(); 1698 1699 DeclarationWithType * decl = handleDecl( functionDecl, functionDecl->get_functionType() ); 1700 knownOffsets.endScope(); 1701 knownLayouts.endScope(); 1702 return decl; 1693 return handleDecl( functionDecl, functionDecl->get_functionType() ); 1703 1694 } 1704 1695 … … 1709 1700 TypeDecl * PolyGenericCalculator::mutate( TypeDecl *typeDecl ) { 1710 1701 scopeTyVars[ typeDecl->get_name() ] = typeDecl->get_kind(); 1711 return Parent::mutate( typeDecl );1702 return Mutator::mutate( typeDecl ); 1712 1703 } 1713 1704 … … 1715 1706 beginTypeScope( pointerType ); 1716 1707 1717 Type *ret = Parent::mutate( pointerType );1708 Type *ret = Mutator::mutate( pointerType ); 1718 1709 1719 1710 endTypeScope(); … … 1733 1724 } 1734 1725 1735 Type *ret = Parent::mutate( funcType );1726 Type *ret = Mutator::mutate( funcType ); 1736 1727 1737 1728 endTypeScope(); … … 1754 1745 } 1755 1746 } 1756 return Parent::mutate( declStmt );1747 return Mutator::mutate( declStmt ); 1757 1748 } 1758 1749 … … 1796 1787 Expression *PolyGenericCalculator::mutate( MemberExpr *memberExpr ) { 1797 1788 // mutate, exiting early if no longer MemberExpr 1798 Expression *expr = Parent::mutate( memberExpr );1789 Expression *expr = Mutator::mutate( memberExpr ); 1799 1790 memberExpr = dynamic_cast< MemberExpr* >( expr ); 1800 1791 if ( ! memberExpr ) return expr; … … 1981 1972 Expression *PolyGenericCalculator::mutate( OffsetofExpr *offsetofExpr ) { 1982 1973 // mutate, exiting early if no longer OffsetofExpr 1983 Expression *expr = Parent::mutate( offsetofExpr );1974 Expression *expr = Mutator::mutate( offsetofExpr ); 1984 1975 offsetofExpr = dynamic_cast< OffsetofExpr* >( expr ); 1985 1976 if ( ! offsetofExpr ) return expr; -
src/GenPoly/PolyMutator.cc
r5fda7143 r1f75e2d 30 30 31 31 void PolyMutator::mutateStatementList( std::list< Statement* > &statements ) { 32 SemanticError errors;33 34 32 for ( std::list< Statement* >::iterator i = statements.begin(); i != statements.end(); ++i ) { 35 33 if ( ! stmtsToAddAfter.empty() ) { 36 34 statements.splice( i, stmtsToAddAfter ); 37 35 } // if 38 try { 39 *i = (*i)->acceptMutator( *this ); 40 } catch ( SemanticError &e ) { 41 errors.append( e ); 42 } // try 36 *i = (*i)->acceptMutator( *this ); 43 37 if ( ! stmtsToAdd.empty() ) { 44 38 statements.splice( i, stmtsToAdd ); … … 48 42 statements.splice( statements.end(), stmtsToAddAfter ); 49 43 } // if 50 if ( ! errors.isEmpty() ) {51 throw errors;52 }53 44 } 54 45 -
src/GenPoly/PolyMutator.h
r5fda7143 r1f75e2d 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 35 32 PolyMutator(); 36 33 … … 45 42 virtual Statement* mutate(ExprStmt *catchStmt); 46 43 virtual Statement* mutate(ReturnStmt *catchStmt); 47 44 48 45 virtual Expression* mutate(UntypedExpr *untypedExpr); 49 46 … … 57 54 Statement* mutateStatement( Statement *stmt ); 58 55 Expression* mutateExpression( Expression *expr ); 59 56 60 57 TyVarMap scopeTyVars; 61 58 TypeSubstitution *env; … … 63 60 std::list< Statement* > stmtsToAddAfter; 64 61 }; 65 } // namespace 62 } // namespace 66 63 67 64 #endif // _POLYMUTATOR_H -
src/InitTweak/FixInit.cc
r5fda7143 r1f75e2d 31 31 #include "SynTree/Mutator.h" 32 32 #include "SymTab/Indexer.h" 33 #include "SymTab/Autogen.h"34 33 #include "GenPoly/PolyMutator.h" 35 34 #include "SynTree/AddStmtVisitor.h" … … 177 176 }; 178 177 179 class GenStructMemberCalls : public SymTab::Indexer {178 class WarnStructMembers : public Visitor { 180 179 public: 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 ); 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 ); 186 184 187 185 virtual void visit( FunctionDecl * funcDecl ); … … 190 188 virtual void visit( ApplicationExpr * appExpr ); 191 189 192 SemanticError errors;193 190 private: 194 191 void handleFirstParam( Expression * firstParam ); 195 template< typename... Params >196 void emit( const Params &... params );197 192 198 193 FunctionDecl * function = 0; 199 std::set< DeclarationWithType * > unhandled , usedUninit;194 std::set< DeclarationWithType * > unhandled; 200 195 ObjectDecl * thisParam = 0; 201 bool isCtor = false; // true if current function is a constructor202 StructDecl * structDecl = 0;203 };204 205 // very simple resolver-like mutator class - used to206 // resolve UntypedExprs that are found within newly207 // generated constructor/destructor calls208 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;217 196 }; 218 197 } // namespace … … 230 209 FixCopyCtors::fixCopyCtors( translationUnit ); 231 210 232 GenStructMemberCalls::generate( translationUnit );211 WarnStructMembers::warnings( translationUnit ); 233 212 } 234 213 … … 275 254 } 276 255 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; 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 ); 284 260 } 285 261 } … … 552 528 FunctionDecl * dtorCaller = new FunctionDecl( objDecl->get_mangleName() + dtorCallerNamer.newName(), DeclarationNode::Static, LinkageSpec::C, new FunctionType( Type::Qualifiers(), false ), new CompoundStmt( noLabels ), false, false ); 553 529 dtorCaller->fixUniqueId(); 554 dtorCaller->get_statements()-> push_back( dtorStmt );530 dtorCaller->get_statements()->get_kids().push_back( dtorStmt ); 555 531 556 532 // atexit(dtor_atexit); … … 567 543 // at global scope and there could be multiple function-scoped 568 544 // static variables with the same name in different functions. 569 // Note: it isn't sufficient to modify only the mangleName, because570 // then subsequent Indexer passes can choke on seeing the object's name571 // if another object has the same name and type. An unfortunate side-effect572 // of renaming the object is that subsequent NameExprs may fail to resolve,573 // but there shouldn't be any remaining past this point.574 545 static UniqueName staticNamer( "_static_var" ); 575 objDecl->set_name( objDecl->get_name() + staticNamer.newName() ); 576 objDecl->set_mangleName( SymTab::Mangler::mangle( objDecl ) ); 546 objDecl->set_mangleName( objDecl->get_mangleName() + staticNamer.newName() ); 577 547 578 548 objDecl->set_init( NULL ); … … 739 709 } 740 710 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(); 711 void WarnStructMembers::visit( FunctionDecl * funcDecl ) { 712 WarnStructMembers old = *this; 713 *this = WarnStructMembers(); 752 714 753 715 function = funcDecl; 754 isCtor = isConstructor( function->get_name() ); 755 if ( checkWarnings( function ) ) { 756 FunctionType * type = function->get_functionType(); 716 if ( checkWarnings( funcDecl ) ) { 717 FunctionType * type = funcDecl->get_functionType(); 757 718 assert( ! type->get_parameters().empty() ); 758 719 thisParam = safe_dynamic_cast< ObjectDecl * >( type->get_parameters().front() ); … … 760 721 StructInstType * structType = dynamic_cast< StructInstType * >( ptrType->get_base() ); 761 722 if ( structType ) { 762 structDecl = structType->get_baseStruct();723 StructDecl * structDecl = structType->get_baseStruct(); 763 724 for ( Declaration * member : structDecl->get_members() ) { 764 725 if ( ObjectDecl * field = dynamic_cast< ObjectDecl * >( member ) ) { … … 770 731 } 771 732 } 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" ); 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" ); 780 738 } 781 739 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 ) { 740 *this = old; 741 } 742 743 void WarnStructMembers::visit( ApplicationExpr * appExpr ) { 834 744 if ( ! checkWarnings( function ) ) return; 835 745 … … 850 760 handleFirstParam( firstParam ); 851 761 } 762 } else if ( fname == "?=?" && isIntrinsicCallExpr( appExpr ) ) { 763 // forgive use of intrinsic assignment to construct, since instrinsic constructors 764 // codegen as assignment anyway. 765 assert( appExpr->get_args().size() == 2 ); 766 handleFirstParam( appExpr->get_args().front() ); 852 767 } 853 768 … … 855 770 } 856 771 857 void GenStructMemberCalls::handleFirstParam( Expression * firstParam ) {772 void WarnStructMembers::handleFirstParam( Expression * firstParam ) { 858 773 using namespace std; 859 774 if ( AddressExpr * addrExpr = dynamic_cast< AddressExpr * >( firstParam ) ) { … … 872 787 } 873 788 874 void GenStructMemberCalls::visit( MemberExpr * memberExpr ) {789 void WarnStructMembers::visit( MemberExpr * memberExpr ) { 875 790 if ( ! checkWarnings( function ) ) return; 876 if ( ! isC tor) return;791 if ( ! isConstructor( function->get_name() ) ) return; 877 792 878 793 if ( ApplicationExpr * deref = dynamic_cast< ApplicationExpr * >( memberExpr->get_aggregate() ) ) { … … 882 797 if ( unhandled.count( memberExpr->get_member() ) ) { 883 798 // emit a warning because a member was used before it was constructed 884 usedUninit.insert( memberExpr->get_member());799 warn( "in ", CodeGen::genType( function->get_functionType(), function->get_name(), false ), ", member ", memberExpr->get_member()->get_name(), " used before being constructed" ); 885 800 } 886 801 } … … 890 805 Parent::visit( memberExpr ); 891 806 } 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 collisions907 // in generated code. If this changes, add mutate methods for entities with908 // 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 }916 807 } // namespace 917 808 } // namespace InitTweak -
src/InitTweak/GenInit.cc
r5fda7143 r1f75e2d 25 25 #include "SynTree/Mutator.h" 26 26 #include "SymTab/Autogen.h" 27 #include "SymTab/Mangler.h"28 27 #include "GenPoly/PolyMutator.h" 29 28 #include "GenPoly/DeclMutator.h" 30 #include "GenPoly/ScopedSet.h"31 29 32 30 namespace InitTweak { … … 57 55 class CtorDtor : public GenPoly::PolyMutator { 58 56 public: 59 typedef GenPoly::PolyMutator Parent;60 using Parent::mutate;61 57 /// create constructor and destructor statements for object declarations. 62 58 /// the actual call statements will be added in after the resolver has run … … 69 65 // should not traverse into any of these declarations to find objects 70 66 // that need to be constructed or destructed 71 virtual Declaration* mutate( StructDecl *aggregateDecl ) ;67 virtual Declaration* mutate( StructDecl *aggregateDecl ) { return aggregateDecl; } 72 68 virtual Declaration* mutate( UnionDecl *aggregateDecl ) { return aggregateDecl; } 73 69 virtual Declaration* mutate( EnumDecl *aggregateDecl ) { return aggregateDecl; } … … 78 74 virtual Type * mutate( FunctionType *funcType ) { return funcType; } 79 75 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; 76 protected: 91 77 }; 92 78 … … 156 142 157 143 DeclarationWithType* ReturnFixer::mutate( FunctionDecl *functionDecl ) { 158 ValueGuard< std::list<DeclarationWithType*> > oldReturnVals( returnVals );159 ValueGuard< std::string > oldFuncName( funcName );144 std::list<DeclarationWithType*> oldReturnVals = returnVals; 145 std::string oldFuncName = funcName; 160 146 161 147 FunctionType * type = functionDecl->get_functionType(); … … 163 149 funcName = functionDecl->get_name(); 164 150 DeclarationWithType * decl = Mutator::mutate( functionDecl ); 151 returnVals = oldReturnVals; 152 funcName = oldFuncName; 165 153 return decl; 166 154 } … … 209 197 210 198 DeclarationWithType * HoistArrayDimension::mutate( FunctionDecl *functionDecl ) { 211 ValueGuard< bool > oldInFunc( inFunction );199 bool oldInFunc = inFunction; 212 200 inFunction = true; 213 201 DeclarationWithType * decl = Parent::mutate( functionDecl ); 202 inFunction = oldInFunc; 214 203 return decl; 215 204 } … … 220 209 } 221 210 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 240 211 DeclarationWithType * CtorDtor::mutate( ObjectDecl * 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 212 // hands off if designated, if @=, or if extern 213 if ( tryConstruct( objDecl ) ) { 250 214 // call into genImplicitCall from Autogen.h to generate calls to ctor/dtor 251 215 // for each constructable object … … 277 241 } 278 242 } 279 return Parent::mutate( objDecl );243 return Mutator::mutate( objDecl ); 280 244 } 281 245 282 246 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/dtors290 for ( TypeDecl * tyDecl : functionDecl->get_functionType()->get_forall() ) {291 for ( DeclarationWithType *& assertion : tyDecl->get_assertions() ) {292 assertion = assertion->acceptMutator( *this );293 }294 }295 247 // parameters should not be constructed and destructed, so don't mutate FunctionType 296 248 mutateAll( functionDecl->get_oldDecls(), *this ); 297 249 functionDecl->set_statements( maybeMutate( functionDecl->get_statements(), *this ) ); 298 299 managedTypes.endScope();300 250 return functionDecl; 301 251 } 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 managed306 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 324 252 } // namespace InitTweak 325 253 -
src/InitTweak/InitTweak.cc
r5fda7143 r1f75e2d 7 7 #include "SynTree/Attribute.h" 8 8 #include "GenPoly/GenPoly.h" 9 #include "ResolvExpr/typeops.h"10 9 11 10 namespace InitTweak { … … 23 22 }; 24 23 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 46 24 class InitFlattener : public Visitor { 47 25 public: … … 74 52 maybeAccept( init, finder ); 75 53 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;82 54 } 83 55 … … 259 231 return ! LinkageSpec::isBuiltin( objDecl->get_linkage() ) && 260 232 (objDecl->get_init() == NULL || 261 ( objDecl->get_init() != NULL && objDecl->get_init()->get_maybeConstructed() )) 233 ( objDecl->get_init() != NULL && objDecl->get_init()->get_maybeConstructed() )) && 234 ! isDesignated( objDecl->get_init() ) 262 235 && objDecl->get_storageClass() != DeclarationNode::Extern; 263 236 } … … 417 390 virtual void visit( ApplicationExpr *applicationExpr ) { isConstExpr = false; } 418 391 virtual void visit( UntypedExpr *untypedExpr ) { 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 } 392 virtual void visit( NameExpr *nameExpr ) { isConstExpr = false; } 393 virtual void visit( CastExpr *castExpr ) { isConstExpr = false; } 429 394 virtual void visit( LabelAddressExpr *labAddressExpr ) { isConstExpr = false; } 430 395 virtual void visit( UntypedMemberExpr *memberExpr ) { isConstExpr = false; } 431 396 virtual void visit( MemberExpr *memberExpr ) { isConstExpr = false; } 432 397 virtual void visit( VariableExpr *variableExpr ) { isConstExpr = false; } 398 virtual void visit( ConstantExpr *constantExpr ) { /* bottom out */ } 433 399 // these might be okay? 434 400 // virtual void visit( SizeofExpr *sizeofExpr ); … … 473 439 bool isDestructor( const std::string & str ) { return str == "^?{}"; } 474 440 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 }494 441 } -
src/InitTweak/InitTweak.h
r5fda7143 r1f75e2d 30 30 bool isCtorDtor( const std::string & ); 31 31 32 FunctionDecl * isCopyConstructor( Declaration * decl );33 34 32 /// transform Initializer into an argument list that can be passed to a call expression 35 33 std::list< Expression * > makeInitList( Initializer * init ); … … 40 38 /// True if the Initializer contains designations 41 39 bool isDesignated( Initializer * init ); 42 43 /// True if the ObjectDecl's Initializer nesting level is not deeper than the depth of its44 /// type, where the depth of its type is the number of nested ArrayTypes + 145 bool checkInitDepth( ObjectDecl * objDecl );46 40 47 41 /// Non-Null if expr is a call expression whose target function is intrinsic -
src/Parser/DeclarationNode.cc
r5fda7143 r1f75e2d 10 10 // Created On : Sat May 16 12:34:05 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon Aug 29 22:30:56201613 // Update Count : 32712 // Last Modified On : Sun Aug 28 22:12:44 2016 13 // Update Count : 278 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 }70 44 71 45 DeclarationNode *DeclarationNode::clone() const { … … 81 55 newnode->set_next( maybeClone( get_next() ) ); 82 56 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 );90 57 return newnode; 91 58 } // 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 } 92 78 93 79 bool DeclarationNode::get_hasEllipsis() const { … … 143 129 144 130 newnode->type = new TypeData( TypeData::Function ); 145 newnode->type->function .params = param;146 newnode->type->function .newStyle = newStyle;147 newnode->type->function .body = body;131 newnode->type->function->params = param; 132 newnode->type->function->newStyle = newStyle; 133 newnode->type->function->body = body; 148 134 typedefTable.addToEnclosingScope( newnode->name, TypedefTable::ID ); 149 135 150 136 if ( body ) { 151 newnode->type->function .hasBody = true;137 newnode->type->function->hasBody = true; 152 138 } // if 153 139 … … 189 175 DeclarationNode *newnode = new DeclarationNode; 190 176 newnode->type = new TypeData( TypeData::Basic ); 191 newnode->type->basic .typeSpec.push_back( bt );177 newnode->type->basic->typeSpec.push_back( bt ); 192 178 return newnode; 193 179 } // DeclarationNode::newBasicType … … 196 182 DeclarationNode *newnode = new DeclarationNode; 197 183 newnode->type = new TypeData( TypeData::Basic ); 198 newnode->type->basic .modifiers.push_back( mod );184 newnode->type->basic->modifiers.push_back( mod ); 199 185 return newnode; 200 186 } // DeclarationNode::newModifier 201 187 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::newBuiltinType 194 202 195 DeclarationNode * DeclarationNode::newFromTypedef( std::string *name ) { 203 196 DeclarationNode *newnode = new DeclarationNode; 204 197 newnode->type = new TypeData( TypeData::SymbolicInst ); 205 newnode->type->symbolic .name = assign_strptr( name );206 newnode->type->symbolic .isTypedef = true;207 newnode->type->symbolic .params = 0;198 newnode->type->symbolic->name = assign_strptr( name ); 199 newnode->type->symbolic->isTypedef = true; 200 newnode->type->symbolic->params = 0; 208 201 return newnode; 209 202 } // DeclarationNode::newFromTypedef … … 212 205 DeclarationNode *newnode = new DeclarationNode; 213 206 newnode->type = new TypeData( TypeData::Aggregate ); 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;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; 222 215 return newnode; 223 216 } // DeclarationNode::newAggregate … … 227 220 newnode->name = assign_strptr( name ); 228 221 newnode->type = new TypeData( TypeData::Enum ); 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;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; 234 227 return newnode; 235 228 } // DeclarationNode::newEnum … … 252 245 DeclarationNode *newnode = new DeclarationNode; 253 246 newnode->type = new TypeData( TypeData::SymbolicInst ); 254 newnode->type->symbolic .name = assign_strptr( name );255 newnode->type->symbolic .isTypedef = false;256 newnode->type->symbolic .actuals = params;247 newnode->type->symbolic->name = assign_strptr( name ); 248 newnode->type->symbolic->isTypedef = false; 249 newnode->type->symbolic->actuals = params; 257 250 return newnode; 258 251 } // DeclarationNode::newFromTypeGen … … 262 255 newnode->name = assign_strptr( name ); 263 256 newnode->type = new TypeData( TypeData::Variable ); 264 newnode-> variable.tyClass = tc;265 newnode-> variable.name = newnode->name;257 newnode->type->variable->tyClass = tc; 258 newnode->type->variable->name = newnode->name; 266 259 return newnode; 267 260 } // DeclarationNode::newTypeParam … … 270 263 DeclarationNode *newnode = new DeclarationNode; 271 264 newnode->type = new TypeData( TypeData::Aggregate ); 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 );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 ); 276 269 return newnode; 277 270 } // DeclarationNode::newTrait … … 280 273 DeclarationNode *newnode = new DeclarationNode; 281 274 newnode->type = new TypeData( TypeData::AggregateInst ); 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;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; 286 279 return newnode; 287 280 } // DeclarationNode::newTraitUse … … 291 284 newnode->name = assign_strptr( name ); 292 285 newnode->type = new TypeData( TypeData::Symbolic ); 293 newnode->type->symbolic .isTypedef = false;294 newnode->type->symbolic .params = typeParams;295 newnode->type->symbolic .name = newnode->name;286 newnode->type->symbolic->isTypedef = false; 287 newnode->type->symbolic->params = typeParams; 288 newnode->type->symbolic->name = newnode->name; 296 289 return newnode; 297 290 } // DeclarationNode::newTypeDecl … … 306 299 DeclarationNode *newnode = new DeclarationNode; 307 300 newnode->type = new TypeData( TypeData::Array ); 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;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; 312 305 } else { 313 newnode->type->array .isVarLen = true;306 newnode->type->array->isVarLen = true; 314 307 } // if 315 308 return newnode->addQualifiers( qualifiers ); … … 319 312 DeclarationNode *newnode = new DeclarationNode; 320 313 newnode->type = new TypeData( TypeData::Array ); 321 newnode->type->array .dimension = 0;322 newnode->type->array .isStatic = false;323 newnode->type->array .isVarLen = true;314 newnode->type->array->dimension = 0; 315 newnode->type->array->isStatic = false; 316 newnode->type->array->isVarLen = true; 324 317 return newnode->addQualifiers( qualifiers ); 325 318 } … … 334 327 DeclarationNode *newnode = new DeclarationNode; 335 328 newnode->type = new TypeData( TypeData::Tuple ); 336 newnode->type->tuple = members;329 newnode->type->tuple->members = members; 337 330 return newnode; 338 331 } … … 341 334 DeclarationNode *newnode = new DeclarationNode; 342 335 newnode->type = new TypeData( TypeData::Typeof ); 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 336 newnode->type->typeexpr->expr = expr; 337 return newnode; 338 } 353 339 354 340 DeclarationNode *DeclarationNode::newAttr( std::string *name, ExpressionNode *expr ) { 355 341 DeclarationNode *newnode = new DeclarationNode; 356 342 newnode->type = new TypeData( TypeData::Attr ); 357 newnode-> attr.name = assign_strptr( name );358 newnode-> attr.expr = expr;343 newnode->type->attr->name = assign_strptr( name ); 344 newnode->type->attr->expr = expr; 359 345 return newnode; 360 346 } … … 363 349 DeclarationNode *newnode = new DeclarationNode; 364 350 newnode->type = new TypeData( TypeData::Attr ); 365 newnode-> attr.name = assign_strptr( name );366 newnode-> attr.type = type;351 newnode->type->attr->name = assign_strptr( name ); 352 newnode->type->attr->type = type; 367 353 return newnode; 368 354 } … … 421 407 } else { 422 408 if ( type->kind == TypeData::Aggregate ) { 423 type->aggregate .params = q->type->forall;409 type->aggregate->params = q->type->forall; 424 410 // change implicit typedef from TYPEDEFname to TYPEGENname 425 typedefTable.changeKind( type->aggregate .name, TypedefTable::TG );411 typedefTable.changeKind( type->aggregate->name, TypedefTable::TG ); 426 412 } else { 427 413 type->forall = q->type->forall; … … 471 457 if ( src->kind != TypeData::Unknown ) { 472 458 assert( src->kind == TypeData::Basic ); 473 dst->basic .modifiers.splice( dst->basic.modifiers.end(), src->basic.modifiers );474 dst->basic .typeSpec.splice( dst->basic.typeSpec.end(), src->basic.typeSpec );459 dst->basic->modifiers.splice( dst->basic->modifiers.end(), src->basic->modifiers ); 460 dst->basic->typeSpec.splice( dst->basic->typeSpec.end(), src->basic->typeSpec ); 475 461 } // if 476 462 break; … … 480 466 case TypeData::Enum: 481 467 dst->base = new TypeData( TypeData::AggregateInst ); 482 dst->base->aggInst .aggregate = src;468 dst->base->aggInst->aggregate = src; 483 469 if ( src->kind == TypeData::Aggregate ) { 484 dst->base->aggInst .params = maybeClone( src->aggregate.actuals );470 dst->base->aggInst->params = maybeClone( src->aggregate->actuals ); 485 471 } // if 486 472 dst->base->qualifiers |= src->qualifiers; … … 509 495 if ( o->type->kind == TypeData::Aggregate || o->type->kind == TypeData::Enum ) { 510 496 type = new TypeData( TypeData::AggregateInst ); 511 type->aggInst .aggregate = o->type;497 type->aggInst->aggregate = o->type; 512 498 if ( o->type->kind == TypeData::Aggregate ) { 513 type->aggInst .params = maybeClone( o->type->aggregate.actuals );499 type->aggInst->params = maybeClone( o->type->aggregate->actuals ); 514 500 } // if 515 501 type->qualifiers |= o->type->qualifiers; … … 537 523 DeclarationNode *DeclarationNode::addTypedef() { 538 524 TypeData *newtype = new TypeData( TypeData::Symbolic ); 539 newtype->symbolic .params = 0;540 newtype->symbolic .isTypedef = true;541 newtype->symbolic .name = name;525 newtype->symbolic->params = 0; 526 newtype->symbolic->isTypedef = true; 527 newtype->symbolic->name = name; 542 528 newtype->base = type; 543 529 type = newtype; … … 549 535 switch ( type->kind ) { 550 536 case TypeData::Symbolic: 551 if ( type->symbolic .assertions ) {552 type->symbolic .assertions->appendList( assertions );537 if ( type->symbolic->assertions ) { 538 type->symbolic->assertions->appendList( assertions ); 553 539 } else { 554 type->symbolic .assertions = assertions;540 type->symbolic->assertions = assertions; 555 541 } // if 556 542 break; 557 543 case TypeData::Variable: 558 if ( variable.assertions ) {559 variable.assertions->appendList( assertions );544 if ( type->variable->assertions ) { 545 type->variable->assertions->appendList( assertions ); 560 546 } else { 561 variable.assertions = assertions;547 type->variable->assertions = assertions; 562 548 } // if 563 549 break; … … 588 574 assert( type ); 589 575 assert( type->kind == TypeData::Function ); 590 assert( type->function .body == 0 );591 type->function .body = body;592 type->function .hasBody = true;576 assert( type->function->body == 0 ); 577 type->function->body = body; 578 type->function->hasBody = true; 593 579 return this; 594 580 } … … 597 583 assert( type ); 598 584 assert( type->kind == TypeData::Function ); 599 assert( type->function .oldDeclList == 0 );600 type->function .oldDeclList = list;585 assert( type->function->oldDeclList == 0 ); 586 type->function->oldDeclList = list; 601 587 return this; 602 588 } … … 644 630 case TypeData::Enum: 645 631 p->type->base = new TypeData( TypeData::AggregateInst ); 646 p->type->base->aggInst .aggregate = type;632 p->type->base->aggInst->aggregate = type; 647 633 if ( type->kind == TypeData::Aggregate ) { 648 p->type->base->aggInst .params = maybeClone( type->aggregate.actuals );634 p->type->base->aggInst->params = maybeClone( type->aggregate->actuals ); 649 635 } // if 650 636 p->type->base->qualifiers |= type->qualifiers; … … 681 667 case TypeData::Enum: 682 668 lastArray->base = new TypeData( TypeData::AggregateInst ); 683 lastArray->base->aggInst .aggregate = type;669 lastArray->base->aggInst->aggregate = type; 684 670 if ( type->kind == TypeData::Aggregate ) { 685 lastArray->base->aggInst .params = maybeClone( type->aggregate.actuals );671 lastArray->base->aggInst->params = maybeClone( type->aggregate->actuals ); 686 672 } // if 687 673 lastArray->base->qualifiers |= type->qualifiers; … … 701 687 DeclarationNode *DeclarationNode::addParamList( DeclarationNode *params ) { 702 688 TypeData *ftype = new TypeData( TypeData::Function ); 703 ftype->function .params = params;689 ftype->function->params = params; 704 690 setBase( type, ftype ); 705 691 return this; … … 711 697 type->base = addIdListToType( type->base, ids ); 712 698 } else { 713 type->function .idList = ids;699 type->function->idList = ids; 714 700 } // if 715 701 return type; 716 702 } else { 717 703 TypeData *newtype = new TypeData( TypeData::Function ); 718 newtype->function .idList = ids;704 newtype->function->idList = ids; 719 705 return newtype; 720 706 } // if … … 741 727 if ( newnode->type->kind == TypeData::AggregateInst ) { 742 728 // don't duplicate members 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;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; 746 732 } else { 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;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; 750 736 } // if 751 737 } // if … … 767 753 if ( newType->kind == TypeData::AggregateInst ) { 768 754 // don't duplicate members 769 if ( newType->aggInst .aggregate->kind == TypeData::Enum ) {770 delete newType->aggInst .aggregate->enumeration.constants;771 newType->aggInst .aggregate->enumeration.constants = 0;755 if ( newType->aggInst->aggregate->kind == TypeData::Enum ) { 756 delete newType->aggInst->aggregate->enumeration->constants; 757 newType->aggInst->aggregate->enumeration->constants = 0; 772 758 } else { 773 assert( newType->aggInst .aggregate->kind == TypeData::Aggregate );774 delete newType->aggInst .aggregate->aggregate.fields;775 newType->aggInst .aggregate->aggregate.fields = 0;759 assert( newType->aggInst->aggregate->kind == TypeData::Aggregate ); 760 delete newType->aggInst->aggregate->aggregate->fields; 761 newType->aggInst->aggregate->aggregate->fields = 0; 776 762 } // if 777 763 } // if … … 910 896 if ( ! error.empty() ) throw SemanticError( error, this ); 911 897 if ( type ) { 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 898 return buildDecl( type, name, storageClass, maybeBuild< Expression >( bitfieldWidth ), isInline, isNoreturn, linkage, maybeBuild< Initializer >(initializer) )->set_extension( extension ); 920 899 } // if 921 900 if ( ! isInline && ! isNoreturn ) { … … 930 909 switch ( type->kind ) { 931 910 case TypeData::Enum: 932 return new EnumInstType( buildQualifiers( type ), type->enumeration .name );911 return new EnumInstType( buildQualifiers( type ), type->enumeration->name ); 933 912 case TypeData::Aggregate: { 934 913 ReferenceToType *ret; 935 switch ( type->aggregate .kind ) {914 switch ( type->aggregate->kind ) { 936 915 case DeclarationNode::Struct: 937 ret = new StructInstType( buildQualifiers( type ), type->aggregate .name );916 ret = new StructInstType( buildQualifiers( type ), type->aggregate->name ); 938 917 break; 939 918 case DeclarationNode::Union: 940 ret = new UnionInstType( buildQualifiers( type ), type->aggregate .name );919 ret = new UnionInstType( buildQualifiers( type ), type->aggregate->name ); 941 920 break; 942 921 case DeclarationNode::Trait: 943 ret = new TraitInstType( buildQualifiers( type ), type->aggregate .name );922 ret = new TraitInstType( buildQualifiers( type ), type->aggregate->name ); 944 923 break; 945 924 default: 946 925 assert( false ); 947 926 } // switch 948 buildList( type->aggregate .actuals, ret->get_parameters() );927 buildList( type->aggregate->actuals, ret->get_parameters() ); 949 928 return ret; 950 929 } 951 930 case TypeData::Symbolic: { 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 931 TypeInstType *ret = new TypeInstType( buildQualifiers( type ), type->symbolic->name, false ); 932 buildList( type->symbolic->actuals, ret->get_parameters() ); 966 933 return ret; 967 934 } -
src/Parser/ParseNode.cc
r5fda7143 r1f75e2d 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 26 21 // Local Variables: // 27 22 // tab-width: 4 // -
src/Parser/ParseNode.h
r5fda7143 r1f75e2d 10 10 // Created On : Sat May 16 13:28:16 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon Aug 29 21:45:43201613 // Update Count : 5 8312 // Last Modified On : Sun Aug 28 21:14:51 2016 13 // Update Count : 575 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 314 292 TypeData *type; 315 293 std::string name; … … 431 409 } 432 410 433 // in ParseNode.cc434 std::ostream & operator<<( std::ostream & out, const ParseNode * node );435 411 436 412 #endif // PARSENODE_H -
src/Parser/TypeData.cc
r5fda7143 r1f75e2d 10 10 // Created On : Sat May 16 15:12:51 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon Aug 29 22:31:53201613 // Update Count : 2 7712 // Last Modified On : Sun Aug 28 18:28:58 2016 13 // Update Count : 223 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 = nullptr;80 tuple = new Tuple_t; 81 tuple->members = 0; 82 82 break; 83 83 case Typeof: 84 // typeexpr = new Typeof_t; 85 typeexpr = nullptr; 84 typeexpr = new Typeof_t; 85 typeexpr->expr = 0; 86 break; 87 case Builtin: 88 builtin = new Builtin_t; 86 89 break; 87 90 case Attr: 88 // attr = new Attr_t; 89 // attr.expr = nullptr; 90 // attr.type = nullptr; 91 break; 92 case Builtin: 93 // builtin = new Builtin_t; 91 attr = new Attr_t; 92 attr->expr = 0; 93 attr->type = 0; 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 Builtin: 157 delete builtin; 158 break; 156 159 case Attr: 157 // delete attr.expr; 158 // delete attr.type; 159 // delete attr; 160 break; 161 case Builtin: 162 // delete builtin; 160 delete attr->expr; 161 delete attr->type; 162 delete attr; 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 assert( false ); 222 // newtype->variable.assertions = maybeClone( variable.assertions ); 223 // newtype->variable.name = variable.name; 224 // newtype->variable.tyClass = variable.tyClass; 221 newtype->variable->assertions = maybeClone( variable->assertions ); 222 newtype->variable->name = variable->name; 223 newtype->variable->tyClass = variable->tyClass; 225 224 break; 226 225 case Tuple: 227 newtype->tuple = maybeClone( tuple);226 newtype->tuple->members = maybeClone( tuple->members ); 228 227 break; 229 228 case Typeof: 230 newtype->typeexpr = maybeClone( typeexpr ); 229 newtype->typeexpr->expr = maybeClone( typeexpr->expr ); 230 break; 231 case Builtin: 232 newtype->builtin->type = builtin->type; 231 233 break; 232 234 case Attr: 233 assert( false ); 234 // newtype->attr.expr = maybeClone( attr.expr ); 235 // newtype->attr.type = maybeClone( attr.type ); 236 break; 237 case Builtin: 238 assert( false ); 239 // newtype->builtin = builtin; 235 newtype->attr->expr = maybeClone( attr->expr ); 236 newtype->attr->type = maybeClone( attr->type ); 240 237 break; 241 238 } // switch … … 271 268 break; 272 269 case Basic: 273 printEnums( basic .modifiers.begin(), basic.modifiers.end(), DeclarationNode::modifierName, os );274 printEnums( basic .typeSpec.begin(), basic.typeSpec.end(), DeclarationNode::basicTypeName, os );270 printEnums( basic->modifiers.begin(), basic->modifiers.end(), DeclarationNode::modifierName, os ); 271 printEnums( basic->typeSpec.begin(), basic->typeSpec.end(), DeclarationNode::basicTypeName, os ); 275 272 break; 276 273 case Array: 277 if ( array .isStatic ) {274 if ( array->isStatic ) { 278 275 os << "static "; 279 276 } // if 280 if ( array .dimension ) {277 if ( array->dimension ) { 281 278 os << "array of "; 282 array .dimension->printOneLine( os, indent );283 } else if ( array .isVarLen ) {279 array->dimension->printOneLine( os, indent ); 280 } else if ( array->isVarLen ) { 284 281 os << "variable-length array of "; 285 282 } else { … … 292 289 case Function: 293 290 os << "function" << endl; 294 if ( function .params ) {291 if ( function->params ) { 295 292 os << string( indent + 2, ' ' ) << "with parameters " << endl; 296 function .params->printList( os, indent + 4 );293 function->params->printList( os, indent + 4 ); 297 294 } else { 298 295 os << string( indent + 2, ' ' ) << "with no parameters " << endl; 299 296 } // if 300 if ( function .idList ) {297 if ( function->idList ) { 301 298 os << string( indent + 2, ' ' ) << "with old-style identifier list " << endl; 302 function .idList->printList( os, indent + 4 );303 } // if 304 if ( function .oldDeclList ) {299 function->idList->printList( os, indent + 4 ); 300 } // if 301 if ( function->oldDeclList ) { 305 302 os << string( indent + 2, ' ' ) << "with old-style declaration list " << endl; 306 function .oldDeclList->printList( os, indent + 4 );303 function->oldDeclList->printList( os, indent + 4 ); 307 304 } // if 308 305 os << string( indent + 2, ' ' ) << "returning "; … … 313 310 } // if 314 311 os << endl; 315 if ( function .hasBody ) {312 if ( function->hasBody ) { 316 313 os << string( indent + 2, ' ' ) << "with body " << endl; 317 314 } // if 318 if ( function .body ) {319 function .body->printList( os, indent + 2 );315 if ( function->body ) { 316 function->body->printList( os, indent + 2 ); 320 317 } // if 321 318 break; 322 319 case Aggregate: 323 os << DeclarationNode::aggregateName[ aggregate .kind ] << ' ' << aggregate.name << endl;324 if ( aggregate .params ) {320 os << DeclarationNode::aggregateName[ aggregate->kind ] << ' ' << aggregate->name << endl; 321 if ( aggregate->params ) { 325 322 os << string( indent + 2, ' ' ) << "with type parameters " << endl; 326 aggregate .params->printList( os, indent + 4 );327 } // if 328 if ( aggregate .actuals ) {323 aggregate->params->printList( os, indent + 4 ); 324 } // if 325 if ( aggregate->actuals ) { 329 326 os << string( indent + 2, ' ' ) << "instantiated with actual parameters " << endl; 330 aggregate .actuals->printList( os, indent + 4 );331 } // if 332 if ( aggregate .fields ) {327 aggregate->actuals->printList( os, indent + 4 ); 328 } // if 329 if ( aggregate->fields ) { 333 330 os << string( indent + 2, ' ' ) << "with members " << endl; 334 aggregate .fields->printList( os, indent + 4 );335 } // if 336 if ( aggregate .body ) {331 aggregate->fields->printList( os, indent + 4 ); 332 } // if 333 if ( aggregate->body ) { 337 334 os << string( indent + 2, ' ' ) << " with body " << endl; 338 335 } // if 339 336 break; 340 337 case AggregateInst: 341 if ( aggInst .aggregate ) {338 if ( aggInst->aggregate ) { 342 339 os << "instance of " ; 343 aggInst .aggregate->print( os, indent );340 aggInst->aggregate->print( os, indent ); 344 341 } else { 345 342 os << "instance of an unspecified aggregate "; 346 343 } // if 347 if ( aggInst .params ) {344 if ( aggInst->params ) { 348 345 os << string( indent + 2, ' ' ) << "with parameters " << endl; 349 aggInst .params->printList( os, indent + 2 );346 aggInst->params->printList( os, indent + 2 ); 350 347 } // if 351 348 break; 352 349 case Enum: 353 350 os << "enumeration "; 354 if ( enumeration .constants ) {351 if ( enumeration->constants ) { 355 352 os << "with constants" << endl; 356 enumeration .constants->printList( os, indent + 2 );353 enumeration->constants->printList( os, indent + 2 ); 357 354 } // if 358 355 break; 359 356 case SymbolicInst: 360 os << "instance of type " << symbolic .name;361 if ( symbolic .actuals ) {357 os << "instance of type " << symbolic->name; 358 if ( symbolic->actuals ) { 362 359 os << " with parameters" << endl; 363 symbolic .actuals->printList( os, indent + 2 );360 symbolic->actuals->printList( os, indent + 2 ); 364 361 } // if 365 362 break; 366 363 case Symbolic: 367 if ( symbolic .isTypedef ) {364 if ( symbolic->isTypedef ) { 368 365 os << "typedef definition "; 369 366 } else { 370 367 os << "type definition "; 371 368 } // if 372 if ( symbolic .params ) {369 if ( symbolic->params ) { 373 370 os << endl << string( indent + 2, ' ' ) << "with parameters" << endl; 374 symbolic .params->printList( os, indent + 2 );375 } // if 376 if ( symbolic .assertions ) {371 symbolic->params->printList( os, indent + 2 ); 372 } // if 373 if ( symbolic->assertions ) { 377 374 os << endl << string( indent + 2, ' ' ) << "with assertions" << endl; 378 symbolic .assertions->printList( os, indent + 4 );375 symbolic->assertions->printList( os, indent + 4 ); 379 376 os << string( indent + 2, ' ' ); 380 377 } // if … … 385 382 break; 386 383 case Variable: 387 // 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 //} // if384 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 } // if 393 390 break; 394 391 case Tuple: 395 392 os << "tuple "; 396 if ( tuple ) {393 if ( tuple->members ) { 397 394 os << "with members " << endl; 398 tuple-> printList( os, indent + 2 );395 tuple->members->printList( os, indent + 2 ); 399 396 } // if 400 397 break; 401 398 case Typeof: 402 399 os << "type-of expression "; 403 if ( typeexpr ) {404 typeexpr-> print( os, indent + 2 );400 if ( typeexpr->expr ) { 401 typeexpr->expr->print( os, indent + 2 ); 405 402 } // if 406 403 break; 407 404 case Attr: 408 // os << "attribute type decl " << attr.name << " applied to ";409 // if ( attr.expr ) {410 // attr.expr->print( os, indent + 2 );411 //} // if412 // if ( attr.type ) {413 // attr.type->print( os, indent + 2 );414 //} // if405 os << "attribute type decl " << attr->name << " applied to "; 406 if ( attr->expr ) { 407 attr->expr->print( os, indent + 2 ); 408 } // if 409 if ( attr->type ) { 410 attr->type->print( os, indent + 2 ); 411 } // if 415 412 break; 416 413 case Builtin: … … 482 479 return new VarArgsType( buildQualifiers( td ) ); 483 480 case TypeData::Attr: 484 assert( false );485 481 return buildAttr( td ); 486 482 case TypeData::Symbolic: … … 498 494 switch ( td->kind ) { 499 495 case TypeData::Aggregate: 500 if ( ! toplevel && td->aggregate .fields ) {496 if ( ! toplevel && td->aggregate->fields ) { 501 497 ret = td->clone(); 502 498 } // if 503 499 break; 504 500 case TypeData::Enum: 505 if ( ! toplevel && td->enumeration .constants ) {501 if ( ! toplevel && td->enumeration->constants ) { 506 502 ret = td->clone(); 507 503 } // if 508 504 break; 509 505 case TypeData::AggregateInst: 510 if ( td->aggInst .aggregate ) {511 ret = typeextractAggregate( td->aggInst .aggregate, false );506 if ( td->aggInst->aggregate ) { 507 ret = typeextractAggregate( td->aggInst->aggregate, false ); 512 508 } // if 513 509 break; … … 539 535 BasicType::Kind ret; 540 536 541 for ( std::list< DeclarationNode::BasicType >::const_iterator i = td->basic .typeSpec.begin(); i != td->basic.typeSpec.end(); ++i ) {537 for ( std::list< DeclarationNode::BasicType >::const_iterator i = td->basic->typeSpec.begin(); i != td->basic->typeSpec.end(); ++i ) { 542 538 if ( ! init ) { 543 539 init = true; 544 540 if ( *i == DeclarationNode::Void ) { 545 if ( td->basic .typeSpec.size() != 1 || ! td->basic.modifiers.empty() ) {541 if ( td->basic->typeSpec.size() != 1 || ! td->basic->modifiers.empty() ) { 546 542 throw SemanticError( "invalid type specifier \"void\" in type: ", td ); 547 543 } else { … … 615 611 } // for 616 612 617 for ( std::list< DeclarationNode::Modifier >::const_iterator i = td->basic .modifiers.begin(); i != td->basic.modifiers.end(); ++i ) {613 for ( std::list< DeclarationNode::Modifier >::const_iterator i = td->basic->modifiers.begin(); i != td->basic->modifiers.end(); ++i ) { 618 614 switch ( *i ) { 619 615 case DeclarationNode::Long: … … 750 746 ArrayType * at; 751 747 if ( td->base ) { 752 at = new ArrayType( buildQualifiers( td ), typebuild( td->base ), maybeBuild< Expression >( td->array .dimension ),753 td->array .isVarLen, td->array.isStatic );748 at = new ArrayType( buildQualifiers( td ), typebuild( td->base ), maybeBuild< Expression >( td->array->dimension ), 749 td->array->isVarLen, td->array->isStatic ); 754 750 } else { 755 751 at = new ArrayType( buildQualifiers( td ), new BasicType( Type::Qualifiers(), BasicType::SignedInt ), 756 maybeBuild< Expression >( td->array .dimension ), td->array.isVarLen, td->array.isStatic );752 maybeBuild< Expression >( td->array->dimension ), td->array->isVarLen, td->array->isStatic ); 757 753 } // if 758 754 buildForall( td->forall, at->get_forall() ); … … 763 759 assert( td->kind == TypeData::Aggregate ); 764 760 AggregateDecl * at; 765 switch ( td->aggregate .kind ) {761 switch ( td->aggregate->kind ) { 766 762 case DeclarationNode::Struct: 767 at = new StructDecl( td->aggregate .name );768 buildForall( td->aggregate .params, at->get_parameters() );763 at = new StructDecl( td->aggregate->name ); 764 buildForall( td->aggregate->params, at->get_parameters() ); 769 765 break; 770 766 case DeclarationNode::Union: 771 at = new UnionDecl( td->aggregate .name );772 buildForall( td->aggregate .params, at->get_parameters() );767 at = new UnionDecl( td->aggregate->name ); 768 buildForall( td->aggregate->params, at->get_parameters() ); 773 769 break; 774 770 case DeclarationNode::Trait: 775 at = new TraitDecl( td->aggregate .name );776 buildList( td->aggregate .params, at->get_parameters() );771 at = new TraitDecl( td->aggregate->name ); 772 buildList( td->aggregate->params, at->get_parameters() ); 777 773 break; 778 774 default: … … 780 776 } // switch 781 777 782 buildList( td->aggregate .fields, at->get_members() );783 at->set_body( td->aggregate .body );778 buildList( td->aggregate->fields, at->get_members() ); 779 at->set_body( td->aggregate->body ); 784 780 785 781 return at; … … 790 786 791 787 ReferenceToType * ret; 792 if ( td->aggInst .aggregate->kind == TypeData::Enum ) {793 ret = new EnumInstType( buildQualifiers( td ), td->aggInst .aggregate->enumeration.name );788 if ( td->aggInst->aggregate->kind == TypeData::Enum ) { 789 ret = new EnumInstType( buildQualifiers( td ), td->aggInst->aggregate->enumeration->name ); 794 790 } else { 795 assert( td->aggInst .aggregate->kind == TypeData::Aggregate );796 switch ( td->aggInst .aggregate->aggregate.kind ) {791 assert( td->aggInst->aggregate->kind == TypeData::Aggregate ); 792 switch ( td->aggInst->aggregate->aggregate->kind ) { 797 793 case DeclarationNode::Struct: 798 ret = new StructInstType( buildQualifiers( td ), td->aggInst .aggregate->aggregate.name );794 ret = new StructInstType( buildQualifiers( td ), td->aggInst->aggregate->aggregate->name ); 799 795 break; 800 796 case DeclarationNode::Union: 801 ret = new UnionInstType( buildQualifiers( td ), td->aggInst .aggregate->aggregate.name );797 ret = new UnionInstType( buildQualifiers( td ), td->aggInst->aggregate->aggregate->name ); 802 798 break; 803 799 case DeclarationNode::Trait: 804 ret = new TraitInstType( buildQualifiers( td ), td->aggInst .aggregate->aggregate.name );800 ret = new TraitInstType( buildQualifiers( td ), td->aggInst->aggregate->aggregate->name ); 805 801 break; 806 802 default: … … 808 804 } // switch 809 805 } // if 810 buildList( td->aggInst .params, ret->get_parameters() );806 buildList( td->aggInst->params, ret->get_parameters() ); 811 807 buildForall( td->forall, ret->get_forall() ); 812 808 return ret; … … 817 813 NamedTypeDecl * ret; 818 814 assert( td->base ); 819 if ( td->symbolic .isTypedef ) {815 if ( td->symbolic->isTypedef ) { 820 816 ret = new TypedefDecl( name, sc, typebuild( td->base ) ); 821 817 } else { 822 818 ret = new TypeDecl( name, sc, typebuild( td->base ), TypeDecl::Any ); 823 819 } // if 824 buildList( td->symbolic .params, ret->get_parameters() );825 buildList( td->symbolic .assertions, ret->get_assertions() );820 buildList( td->symbolic->params, ret->get_parameters() ); 821 buildList( td->symbolic->assertions, ret->get_assertions() ); 826 822 return ret; 827 823 } // buildSymbolic 828 824 829 825 TypeDecl * buildVariable( const TypeData * td ) { 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; 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; 838 832 } // buildSymbolic 839 833 840 834 EnumDecl * buildEnum( const TypeData * td ) { 841 835 assert( td->kind == TypeData::Enum ); 842 EnumDecl * ret = new EnumDecl( td->enumeration .name );843 buildList( td->enumeration .constants, ret->get_members() );836 EnumDecl * ret = new EnumDecl( td->enumeration->name ); 837 buildList( td->enumeration->constants, ret->get_members() ); 844 838 std::list< Declaration * >::iterator members = ret->get_members().begin(); 845 for ( const DeclarationNode * cur = td->enumeration .constants; cur != nullptr; cur = dynamic_cast< DeclarationNode * >( cur->get_next() ), ++members ) {839 for ( const DeclarationNode * cur = td->enumeration-> constants; cur != nullptr; cur = dynamic_cast< DeclarationNode * >( cur->get_next() ), ++members ) { 846 840 if ( cur->has_enumeratorValue() ) { 847 841 ObjectDecl * member = dynamic_cast< ObjectDecl * >(* members); … … 854 848 TypeInstType * buildSymbolicInst( const TypeData * td ) { 855 849 assert( td->kind == TypeData::SymbolicInst ); 856 TypeInstType * ret = new TypeInstType( buildQualifiers( td ), td->symbolic .name, false );857 buildList( td->symbolic .actuals, ret->get_parameters() );850 TypeInstType * ret = new TypeInstType( buildQualifiers( td ), td->symbolic->name, false ); 851 buildList( td->symbolic->actuals, ret->get_parameters() ); 858 852 buildForall( td->forall, ret->get_forall() ); 859 853 return ret; … … 863 857 assert( td->kind == TypeData::Tuple ); 864 858 TupleType * ret = new TupleType( buildQualifiers( td ) ); 865 buildTypeList( td->tuple , ret->get_types() );859 buildTypeList( td->tuple->members, ret->get_types() ); 866 860 buildForall( td->forall, ret->get_forall() ); 867 861 return ret; … … 871 865 assert( td->kind == TypeData::Typeof ); 872 866 assert( td->typeexpr ); 873 //assert( td->typeexpr->expr );874 return new TypeofType( buildQualifiers( td ), td->typeexpr-> build() );867 assert( td->typeexpr->expr ); 868 return new TypeofType( buildQualifiers( td ), td->typeexpr->expr->build() ); 875 869 } // buildTypeof 876 870 877 871 AttrType * buildAttr( const TypeData * td ) { 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; 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; 890 882 } // buildAttr 891 883 … … 893 885 if ( td->kind == TypeData::Function ) { 894 886 FunctionDecl * decl; 895 if ( td->function .hasBody ) {896 if ( td->function .body ) {897 Statement * stmt = td->function .body->build();887 if ( td->function->hasBody ) { 888 if ( td->function->body ) { 889 Statement * stmt = td->function->body->build(); 898 890 CompoundStmt * body = dynamic_cast< CompoundStmt* >( stmt ); 899 891 assert( body ); … … 906 898 decl = new FunctionDecl( name, sc, linkage, buildFunction( td ), 0, isInline, isNoreturn ); 907 899 } // if 908 for ( DeclarationNode * cur = td->function .idList; cur != 0; cur = dynamic_cast< DeclarationNode* >( cur->get_next() ) ) {900 for ( DeclarationNode * cur = td->function->idList; cur != 0; cur = dynamic_cast< DeclarationNode* >( cur->get_next() ) ) { 909 901 if ( cur->get_name() != "" ) { 910 902 decl->get_oldIdents().insert( decl->get_oldIdents().end(), cur->get_name() ); 911 903 } // if 912 904 } // for 913 buildList( td->function .oldDeclList, decl->get_oldDecls() );905 buildList( td->function->oldDeclList, decl->get_oldDecls() ); 914 906 return decl; 915 907 } else if ( td->kind == TypeData::Aggregate ) { … … 920 912 return buildSymbolic( td, name, sc ); 921 913 } else if ( td->kind == TypeData::Variable ) { 922 assert( false );923 914 return buildVariable( td ); 924 915 } else { … … 930 921 FunctionType * buildFunction( const TypeData * td ) { 931 922 assert( td->kind == TypeData::Function ); 932 bool hasEllipsis = td->function .params ? td->function.params->get_hasEllipsis() : true;933 if ( ! td->function .params ) hasEllipsis = ! td->function.newStyle;923 bool hasEllipsis = td->function->params ? td->function->params->get_hasEllipsis() : true; 924 if ( ! td->function->params ) hasEllipsis = ! td->function->newStyle; 934 925 FunctionType * ft = new FunctionType( buildQualifiers( td ), hasEllipsis ); 935 buildList( td->function .params, ft->get_parameters() );926 buildList( td->function->params, ft->get_parameters() ); 936 927 buildForall( td->forall, ft->get_forall() ); 937 928 if ( td->base ) { 938 929 switch ( td->base->kind ) { 939 930 case TypeData::Tuple: 940 buildList( td->base->tuple , ft->get_returnVals() );931 buildList( td->base->tuple->members, ft->get_returnVals() ); 941 932 break; 942 933 default: -
src/Parser/TypeData.h
r5fda7143 r1f75e2d 10 10 // Created On : Sat May 16 15:18:36 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon Aug 29 22:31:52201613 // Update Count : 11012 // Last Modified On : Sun Aug 28 22:39:00 2016 13 // Update Count : 85 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 } ;26 Enum, EnumConstant, Symbolic, SymbolicInst, Variable, Tuple, Typeof, Builtin, Attr } kind; 27 27 28 28 struct Basic_t { … … 73 73 }; 74 74 75 // struct Tuple_t { 76 // DeclarationNode * members; 77 // }; 75 struct Variable_t { 76 DeclarationNode::TypeClass tyClass; 77 std::string name; 78 DeclarationNode * assertions; 79 }; 80 81 struct Tuple_t { 82 DeclarationNode * members; 83 }; 78 84 79 //struct Typeof_t {80 //ExpressionNode * expr;81 //};85 struct Typeof_t { 86 ExpressionNode * expr; 87 }; 82 88 83 //struct Builtin_t {84 //DeclarationNode::BuiltinType type;85 //};89 struct Builtin_t { 90 DeclarationNode::BuiltinType type; 91 }; 86 92 87 Kind kind; 93 struct Attr_t { 94 std::string name; 95 ExpressionNode * expr; 96 DeclarationNode * type; 97 }; 98 88 99 TypeData * base; 89 100 typedef std::bitset< DeclarationNode::NoOfQualifier > Qualifiers; … … 91 102 DeclarationNode * forall; 92 103 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; 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 }; 104 118 105 119 TypeData( Kind k = Unknown ); -
src/ResolvExpr/AlternativeFinder.cc
r5fda7143 r1f75e2d 42 42 #include "Common/utility.h" 43 43 #include "InitTweak/InitTweak.h" 44 #include "ResolveTypeof.h"45 44 46 45 extern bool resolvep; … … 708 707 void AlternativeFinder::visit( CastExpr *castExpr ) { 709 708 for ( std::list< Type* >::iterator i = castExpr->get_results().begin(); i != castExpr->get_results().end(); ++i ) { 710 *i = resolveTypeof( *i, indexer );711 709 SymTab::validateType( *i, &indexer ); 712 710 adjustExprType( *i, env, indexer ); … … 797 795 798 796 void AlternativeFinder::visit( VariableExpr *variableExpr ) { 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 ) ); 797 alternatives.push_back( Alternative( variableExpr->clone(), env, Cost::zero ) ); 802 798 } 803 799 … … 808 804 void AlternativeFinder::visit( SizeofExpr *sizeofExpr ) { 809 805 if ( sizeofExpr->get_isType() ) { 810 // xxx - resolveTypeof?811 806 alternatives.push_back( Alternative( sizeofExpr->clone(), env, Cost::zero ) ); 812 807 } else { … … 828 823 void AlternativeFinder::visit( AlignofExpr *alignofExpr ) { 829 824 if ( alignofExpr->get_isType() ) { 830 // xxx - resolveTypeof?831 825 alternatives.push_back( Alternative( alignofExpr->clone(), env, Cost::zero ) ); 832 826 } else { … … 862 856 void AlternativeFinder::visit( UntypedOffsetofExpr *offsetofExpr ) { 863 857 AlternativeFinder funcFinder( indexer, env ); 864 // xxx - resolveTypeof?865 858 if ( StructInstType *structInst = dynamic_cast< StructInstType* >( offsetofExpr->get_type() ) ) { 866 859 addOffsetof( structInst, offsetofExpr->get_member() ); -
src/ResolvExpr/Resolver.cc
r5fda7143 r1f75e2d 528 528 529 529 void Resolver::visit( ConstructorInit *ctorInit ) { 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 ); 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 } 533 539 534 540 // found a constructor - can get rid of C-style initializer -
src/SymTab/Autogen.h
r5fda7143 r1f75e2d 102 102 } 103 103 104 ObjectDecl *index = new ObjectDecl( indexName.newName(), DeclarationNode::NoStorageClass, LinkageSpec::C, 0, new BasicType( Type::Qualifiers(), BasicType::SignedInt ), new SingleInit( begin, std::list<Expression*>() ) ); 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*>() ) ); 105 110 106 111 UntypedExpr *cond = new UntypedExpr( cmp ); -
src/SymTab/Indexer.cc
r5fda7143 r1f75e2d 21 21 #include <unordered_set> 22 22 #include <utility> 23 #include <algorithm>24 23 25 24 #include "Mangler.h" … … 34 33 #include "SynTree/Initializer.h" 35 34 #include "SynTree/Statement.h" 36 37 #include "InitTweak/InitTweak.h"38 35 39 36 #define debugPrint(x) if ( doDebug ) { std::cout << x; } … … 104 101 } 105 102 106 void Indexer::removeSpecialOverrides( const std::string &id, std::list< DeclarationWithType * > & out ) const {107 // only need to perform this step for constructors and destructors108 if ( ! InitTweak::isCtorDtor( id ) ) return;109 110 // helpful data structure111 struct ValueType {112 struct DeclBall {113 FunctionDecl * decl;114 bool isUserDefinedFunc; // properties for this particular decl115 bool isDefaultFunc;116 bool isCopyFunc;117 };118 // properties for this type119 bool userDefinedFunc = false; // any user defined function found120 bool userDefinedDefaultFunc = false; // user defined default ctor found121 bool userDefinedCopyFunc = false; // user defined copy ctor found122 std::list< DeclBall > decls;123 124 // another FunctionDecl for the current type was found - determine125 // if it has special properties and update data structure accordingly126 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 }; // ValueType137 138 std::list< DeclarationWithType * > copy;139 copy.splice( copy.end(), out );140 141 // organize discovered declarations by type142 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 determine154 // the set of ctor/dtors that are seen by the requester. In particular, if the user defines155 // a default ctor, then the generated default ctor should never be seen, likewise for copy ctor156 // 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 requester162 out.push_back( ball.decl );163 }164 }165 }166 }167 168 103 void Indexer::makeWritable() { 169 104 if ( ! tables ) { … … 526 461 searchTables = searchTables->base.tables; 527 462 } 528 529 // some special functions, e.g. constructors and destructors530 // remove autogenerated functions when they are defined so that531 // they can never be matched532 removeSpecialOverrides( id, out );533 463 } 534 464 -
src/SymTab/Indexer.h
r5fda7143 r1f75e2d 128 128 static void deleteRef( Impl *toFree ); 129 129 130 // Removes matching autogenerated constructors and destructors131 // so that they will not be selected132 // void removeSpecialOverrides( FunctionDecl *decl );133 void removeSpecialOverrides( const std::string &id, std::list< DeclarationWithType * > & out ) const;134 135 130 /// Ensures that tables variable is writable (i.e. allocated, uniquely owned by this Indexer, and at the current scope) 136 131 void makeWritable(); -
src/SynTree/Declaration.cc
r5fda7143 r1f75e2d 56 56 } 57 57 58 std::ostream & operator<<( std::ostream & out, constDeclaration * decl ) {58 std::ostream & operator<<( std::ostream & out, Declaration * decl ) { 59 59 decl->print( out ); 60 60 return out; -
src/SynTree/Declaration.h
r5fda7143 r1f75e2d 279 279 }; 280 280 281 std::ostream & operator<<( std::ostream & out, constDeclaration * decl );281 std::ostream & operator<<( std::ostream & out, Declaration * decl ); 282 282 283 283 #endif // DECLARATION_H -
src/SynTree/Expression.cc
r5fda7143 r1f75e2d 358 358 assert( member ); 359 359 os << std::string( indent + 2, ' ' ); 360 os << (void*)member << " "; 360 361 member->print( os, indent + 2 ); 361 362 os << std::endl; … … 540 541 } 541 542 542 std::ostream & operator<<( std::ostream & out, constExpression * expr ) {543 std::ostream & operator<<( std::ostream & out, Expression * expr ) { 543 544 expr->print( out ); 544 545 return out; -
src/SynTree/Expression.h
r5fda7143 r1f75e2d 653 653 }; 654 654 655 std::ostream & operator<<( std::ostream & out, constExpression * expr );655 std::ostream & operator<<( std::ostream & out, Expression * expr ); 656 656 657 657 #endif // EXPRESSION_H -
src/SynTree/FunctionDecl.cc
r5fda7143 r1f75e2d 21 21 #include "Attribute.h" 22 22 #include "Common/utility.h" 23 #include "InitTweak/InitTweak.h"24 23 25 24 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
r5fda7143 r1f75e2d 387 387 } 388 388 389 std::ostream & operator<<( std::ostream & out, constStatement * statement ) {389 std::ostream & operator<<( std::ostream & out, Statement * statement ) { 390 390 statement->print( out ); 391 391 return out; -
src/SynTree/Statement.h
r5fda7143 r1f75e2d 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 ); }51 49 52 50 virtual CompoundStmt *clone() const { return new CompoundStmt( *this ); } … … 397 395 398 396 399 std::ostream & operator<<( std::ostream & out, constStatement * statement );397 std::ostream & operator<<( std::ostream & out, Statement * statement ); 400 398 401 399 #endif // STATEMENT_H -
src/SynTree/Type.cc
r5fda7143 r1f75e2d 84 84 } 85 85 86 std::ostream & operator<<( std::ostream & out, constType * type ) {86 std::ostream & operator<<( std::ostream & out, Type * type ) { 87 87 type->print( out ); 88 88 return out; -
src/SynTree/Type.h
r5fda7143 r1f75e2d 481 481 } 482 482 483 std::ostream & operator<<( std::ostream & out, constType * type );483 std::ostream & operator<<( std::ostream & out, Type * type ); 484 484 485 485 #endif // TYPE_H -
src/main.cc
r5fda7143 r1f75e2d 10 10 // Created On : Fri May 15 23:12:02 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon Aug 29 17:34:39201613 // Update Count : 4 2612 // Last Modified On : Sat Aug 20 12:52:22 2016 13 // Update Count : 403 14 14 // 15 15 … … 75 75 static void dump( list< Declaration * > & translationUnit, ostream & out = cout ); 76 76 77 void backtrace( int start ) { // skip first N stack frames77 void sigSegvBusHandler( int sig_num ) { 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 81 86 char ** messages = backtrace_symbols( array, size ); 82 87 83 // skip last 2 stack frames after main84 for ( int i = start; i < size - 2 && messages != nullptr; i += 1 ) {88 // skip first stack frame (points here) 89 for ( int i = 2; i < size - 2 && messages != nullptr; i += 1 ) { 85 90 char * mangled_name = nullptr, * offset_begin = nullptr, * offset_end = nullptr; 86 91 for ( char *p = messages[i]; *p; ++p ) { // find parantheses and +offset … … 96 101 97 102 // if line contains symbol, attempt to demangle 98 int frameNo = i - start;99 103 if ( mangled_name && offset_begin && offset_end && mangled_name < offset_begin ) { 100 104 *mangled_name++ = '\0'; … … 102 106 *offset_end++ = '\0'; 103 107 104 int status , frameNo = i - start;108 int status; 105 109 char * real_name = __cxxabiv1::__cxa_demangle( mangled_name, 0, 0, &status ); 106 110 if ( status == 0 ) { // demangling successful ? 107 cerr << "(" << frameNo<< ") " << messages[i] << " : "111 cerr << "(" << i - 2 << ") " << messages[i] << " : " 108 112 << real_name << "+" << offset_begin << offset_end << endl; 109 113 110 114 } else { // otherwise, output mangled name 111 cerr << "(" << frameNo<< ") " << messages[i] << " : "115 cerr << "(" << i - 2 << ") " << messages[i] << " : " 112 116 << mangled_name << "+" << offset_begin << offset_end << endl; 113 117 } // if 114 118 free( real_name ); 115 119 } else { // otherwise, print the whole line 116 cerr << "(" << frameNo<< ") " << messages[i] << endl;120 cerr << "(" << i - 2 << ") " << messages[i] << endl; 117 121 } // if 118 122 } // for 119 120 123 free( messages ); 121 } // backtrace122 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 frames128 124 exit( EXIT_FAILURE ); 129 125 } // sigSegvBusHandler 130 131 void sigAbortHandler( int sig_num ) {132 backtrace( 6 ); // skip first 6 stack frames133 signal( SIGABRT, SIG_DFL); // reset default signal handler134 raise( SIGABRT ); // reraise SIGABRT135 } // sigAbortHandler136 137 126 138 127 int main( int argc, char * argv[] ) { … … 144 133 signal( SIGSEGV, sigSegvBusHandler ); 145 134 signal( SIGBUS, sigSegvBusHandler ); 146 signal( SIGABRT, sigAbortHandler );147 135 148 136 parse_cmdline( argc, argv, filename ); // process command-line arguments -
src/tests/.expect/32/declarationSpecifier.txt
r5fda7143 r1f75e2d 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
r5fda7143 r1f75e2d 86 86 __extension__ int __c__i_2; 87 87 }; 88 int __i__i_2 = ((int )(__extension__ __a__i_1+__extension__ 3)); 88 int __i__i_2; 89 ((void)((*((int *)(&__i__i_2)))=(__extension__ __a__i_1+__extension__ 3)) /* ?{} */); 89 90 ((void)__extension__ 3); 90 91 ((void)__extension__ __a__i_1); -
src/tests/.expect/32/gccExtensions.txt
r5fda7143 r1f75e2d 76 76 ((void)((*((int *)(&(*___dst__P2sS_2).__c__i_2)))=__c__i_2) /* ?{} */); 77 77 } 78 int __i__i_2 = ((int )__extension__ 3); 78 int __i__i_2; 79 ((void)((*((int *)(&__i__i_2)))=__extension__ 3) /* ?{} */); 79 80 __extension__ int __a__i_2; 80 81 __extension__ int __b__i_2; … … 132 133 } 133 134 struct s3 __x1__3ss3_2; 135 ((void)___constructor__F_P3ss3_autogen___2(((struct s3 *)(&__x1__3ss3_2)))); 134 136 struct s3 __y1__3ss3_2; 137 ((void)___constructor__F_P3ss3_autogen___2(((struct s3 *)(&__y1__3ss3_2)))); 135 138 struct s4 { 136 139 int __i__i_2; … … 138 141 inline struct s4 ___operator_assign__F3ss4_P3ss43ss4_autogen___2(struct s4 *___dst__P3ss4_2, struct s4 ___src__3ss4_2){ 139 142 ((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)))); 140 145 return ((struct s4 )___src__3ss4_2); 141 146 } … … 153 158 } 154 159 struct s4 __x2__3ss4_2; 160 ((void)___constructor__F_P3ss4_autogen___2(((struct s4 *)(&__x2__3ss4_2)))); 155 161 struct s4 __y2__3ss4_2; 162 ((void)___constructor__F_P3ss4_autogen___2(((struct s4 *)(&__y2__3ss4_2)))); 156 163 int __m1__A0i_2[((unsigned int )10)]; 157 164 int __m2__A0A0i_2[((unsigned int )10)][((unsigned int )10)]; … … 159 166 int _retVal0 = { 0 }; 160 167 ((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)))); 161 172 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)))); 162 177 } -
src/tests/.expect/64/declarationSpecifier.txt
r5fda7143 r1f75e2d 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
r5fda7143 r1f75e2d 86 86 __extension__ int __c__i_2; 87 87 }; 88 int __i__i_2 = ((int )(__extension__ __a__i_1+__extension__ 3)); 88 int __i__i_2; 89 ((void)((*((int *)(&__i__i_2)))=(__extension__ __a__i_1+__extension__ 3)) /* ?{} */); 89 90 ((void)__extension__ 3); 90 91 ((void)__extension__ __a__i_1); -
src/tests/.expect/64/gccExtensions.txt
r5fda7143 r1f75e2d 76 76 ((void)((*((int *)(&(*___dst__P2sS_2).__c__i_2)))=__c__i_2) /* ?{} */); 77 77 } 78 int __i__i_2 = ((int )__extension__ 3); 78 int __i__i_2; 79 ((void)((*((int *)(&__i__i_2)))=__extension__ 3) /* ?{} */); 79 80 __extension__ int __a__i_2; 80 81 __extension__ int __b__i_2; … … 132 133 } 133 134 struct s3 __x1__3ss3_2; 135 ((void)___constructor__F_P3ss3_autogen___2(((struct s3 *)(&__x1__3ss3_2)))); 134 136 struct s3 __y1__3ss3_2; 137 ((void)___constructor__F_P3ss3_autogen___2(((struct s3 *)(&__y1__3ss3_2)))); 135 138 struct s4 { 136 139 int __i__i_2; … … 138 141 inline struct s4 ___operator_assign__F3ss4_P3ss43ss4_autogen___2(struct s4 *___dst__P3ss4_2, struct s4 ___src__3ss4_2){ 139 142 ((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)))); 140 145 return ((struct s4 )___src__3ss4_2); 141 146 } … … 153 158 } 154 159 struct s4 __x2__3ss4_2; 160 ((void)___constructor__F_P3ss4_autogen___2(((struct s4 *)(&__x2__3ss4_2)))); 155 161 struct s4 __y2__3ss4_2; 162 ((void)___constructor__F_P3ss4_autogen___2(((struct s4 *)(&__y2__3ss4_2)))); 156 163 int __m1__A0i_2[((long unsigned int )10)]; 157 164 int __m2__A0A0i_2[((long unsigned int )10)][((long unsigned int )10)]; … … 159 166 int _retVal0 = { 0 }; 160 167 ((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)))); 161 172 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)))); 162 177 } -
src/tests/Makefile.am
r5fda7143 r1f75e2d 62 62 ${CC} ${CFLAGS} -CFA -XCFA -p ${<} -o ${@} 63 63 64 memberCtors-ERR1: memberCtors.c65 ${CC} ${CFALGS} - DERR1 ${<} -o${@}64 ctorWarnings: ctorWarnings.c 65 ${CC} ${CFALGS} -CFA -XCFA -p ${<} -o /dev/null 2> ${@} 66 66 -
src/tests/Makefile.in
r5fda7143 r1f75e2d 670 670 ${CC} ${CFLAGS} -CFA -XCFA -p ${<} -o ${@} 671 671 672 memberCtors-ERR1: memberCtors.c673 ${CC} ${CFALGS} - DERR1 ${<} -o${@}672 ctorWarnings: ctorWarnings.c 673 ${CC} ${CFALGS} -CFA -XCFA -p ${<} -o /dev/null 2> ${@} 674 674 675 675 # Tell versions [3.59,3.63) of GNU make to not export all variables. -
src/tests/typeof.c
r5fda7143 r1f75e2d 8 8 typeof( int ( int, int p ) ) *v7; 9 9 typeof( [int] ( int, int p ) ) *v8; 10 (typeof(v1)) v2; // cast with typeof11 10 }
Note:
See TracChangeset
for help on using the changeset viewer.