Changes in / [685a5e8:d5f1cfc]
- Location:
- src
- Files:
-
- 32 edited
-
ArgTweak/FunctionFixer.cc (modified) (2 diffs)
-
CodeGen/CodeGenerator.cc (modified) (9 diffs)
-
CodeGen/CodeGenerator.h (modified) (5 diffs)
-
GenPoly/Box.cc (modified) (1 diff)
-
GenPoly/Specialize.cc (modified) (2 diffs)
-
InitTweak/FixGlobalInit.cc (modified) (4 diffs)
-
InitTweak/FixInit.cc (modified) (1 diff)
-
InitTweak/GenInit.cc (modified) (2 diffs)
-
InitTweak/InitTweak.cc (modified) (1 diff)
-
InitTweak/InitTweak.h (modified) (1 diff)
-
Makefile.in (modified) (7 diffs)
-
ResolvExpr/AlternativeFinder.cc (modified) (2 diffs)
-
ResolvExpr/Resolver.cc (modified) (3 diffs)
-
SymTab/Autogen.cc (modified) (2 diffs)
-
SynTree/Declaration.h (modified) (3 diffs)
-
SynTree/FunctionDecl.cc (modified) (5 diffs)
-
SynTree/Initializer.cc (modified) (4 diffs)
-
SynTree/Initializer.h (modified) (6 diffs)
-
SynTree/Mutator.cc (modified) (1 diff)
-
SynTree/Mutator.h (modified) (1 diff)
-
SynTree/Statement.cc (modified) (3 diffs)
-
SynTree/Statement.h (modified) (3 diffs)
-
SynTree/SynTree.h (modified) (2 diffs)
-
SynTree/Type.cc (modified) (3 diffs)
-
SynTree/Type.h (modified) (1 diff)
-
SynTree/Visitor.cc (modified) (1 diff)
-
SynTree/Visitor.h (modified) (1 diff)
-
SynTree/module.mk (modified) (2 diffs)
-
driver/Makefile.in (modified) (1 diff)
-
examples/Makefile.in (modified) (1 diff)
-
examples/avltree/avl-private.h (modified) (2 diffs)
-
libcfa/Makefile.in (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
src/ArgTweak/FunctionFixer.cc
r685a5e8 rd5f1cfc 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // FunctionFixer.cc -- 7 // FunctionFixer.cc -- 8 8 // 9 9 // Author : Rodolfo G. Esteves … … 42 42 Expression *FunctionFixer::mutate( UntypedExpr *untypedExpr ) throw ( SemanticError ) { 43 43 assert( untypedExpr != 0 ); 44 NameExpr *function; 44 45 45 if ( NameExpr * function = dynamic_cast< NameExpr *>(untypedExpr->get_function() )) {46 if ( ( function = dynamic_cast< NameExpr *>(untypedExpr->get_function()) ) != 0 ) { 46 47 std::list < DeclarationWithType * > options; 47 48 index->lookupId ( function->get_name(), options ); 48 49 for ( std::list < DeclarationWithType * >::iterator i = options.begin(); i != options.end(); i++ ) { 49 if ( FunctionType * f = dynamic_cast< FunctionType * > ( (*i)->get_type() ) ) { 50 FunctionType *f; 51 if ( ( f = dynamic_cast< FunctionType * > ( (*i)->get_type() ) ) != 0 ) { 50 52 std::list < DeclarationWithType * > &pars = f->get_parameters(); 53 51 54 bool candidateExists ; 52 for ( std::list < DeclarationWithType * >::iterator p = pars.begin(); p != pars.end(); p++ ) {55 for ( std::list < DeclarationWithType * >::iterator p = pars.begin(); p != pars.end(); p++ ) 53 56 if ( ( candidateExists = align( f->get_parameters(), untypedExpr->get_args(), Matcher() ) ) ) break; 54 } 57 55 58 if ( ! candidateExists ) throw SemanticError("Error in function call"); 56 59 } // if -
src/CodeGen/CodeGenerator.cc
r685a5e8 rd5f1cfc 26 26 #include "SynTree/Statement.h" 27 27 #include "SynTree/Type.h" 28 #include "SynTree/Attribute.h"29 28 30 29 #include "Common/utility.h" … … 34 33 #include "OperatorTable.h" 35 34 #include "GenType.h" 36 37 #include "InitTweak/InitTweak.h"38 35 39 36 using namespace std; … … 77 74 } 78 75 79 void CodeGenerator::genAttributes( std::list< Attribute * > & attributes ) {80 if ( ! attributes.empty() ) {81 output << "__attribute__ ((";82 for ( Attribute *& attr : attributes ) {83 if ( ! attr->empty() ) {84 output << attr->get_name() << "(";85 genCommaList( attr->get_parameters().begin(), attr->get_parameters().end() );86 output << ")";87 }88 output << ",";89 }90 output << ")) ";91 }92 }93 94 95 76 //*** Declarations 96 77 void CodeGenerator::visit( FunctionDecl *functionDecl ) { 97 genAttributes( functionDecl->get_attributes() ); 98 78 // generalize this 79 FunctionDecl::Attribute attr = functionDecl->get_attribute(); 80 switch ( attr.type ) { 81 case FunctionDecl::Attribute::Constructor: 82 output << "__attribute__ ((constructor"; 83 if ( attr.priority != FunctionDecl::Attribute::Default ) { 84 output << "(" << attr.priority << ")"; 85 } 86 output << ")) "; 87 break; 88 case FunctionDecl::Attribute::Destructor: 89 output << "__attribute__ ((destructor"; 90 if ( attr.priority != FunctionDecl::Attribute::Default ) { 91 output << "(" << attr.priority << ")"; 92 } 93 output << ")) "; 94 break; 95 default: 96 break; 97 } 99 98 handleStorageClass( functionDecl ); 100 99 if ( functionDecl->get_isInline() ) { … … 270 269 UntypedExpr *newExpr = new UntypedExpr( new NameExpr( "*?" ) ); 271 270 newExpr->get_args().push_back( *arg ); 272 assert( (*arg)->get_results().size() == 1 );273 Type * type = InitTweak::getPointerBase( (*arg)->get_results().front() );274 assert( type );275 newExpr->get_results().push_back( type );276 271 *arg = newExpr; 277 272 } // if … … 302 297 if ( applicationExpr->get_args().size() == 1 ) { 303 298 // the expression fed into a single parameter constructor or destructor 304 // may contain side effects , so must still output thisexpression305 output << "( ";299 // may contain side effects - output as a void expression 300 output << "((void)("; 306 301 (*arg++)->accept( *this ); 307 output << ") /* " << opInfo.inputName << " */";302 output << ")) /* " << opInfo.inputName << " */"; 308 303 } else if ( applicationExpr->get_args().size() == 2 ) { 309 304 // intrinsic two parameter constructors are essentially bitwise assignment … … 387 382 if ( untypedExpr->get_args().size() == 1 ) { 388 383 // the expression fed into a single parameter constructor or destructor 389 // may contain side effects , so must still output thisexpression390 output << "( ";384 // may contain side effects - output as a void expression 385 output << "((void)("; 391 386 (*arg++)->accept( *this ); 392 output << ") /* " << opInfo.inputName << " */";387 output << ")) /* " << opInfo.inputName << " */"; 393 388 } else if ( untypedExpr->get_args().size() == 2 ) { 394 389 // intrinsic two parameter constructors are essentially bitwise assignment … … 616 611 617 612 void CodeGenerator::visit( ExprStmt *exprStmt ) { 613 // I don't see why this check is necessary. 614 // If this starts to cause problems then put it back in, 615 // with an explanation 618 616 assert( exprStmt ); 619 // cast the top-level expression to void to reduce gcc warnings. 620 Expression * expr = new CastExpr( exprStmt->get_expr() ); 621 expr->accept( *this ); 622 output << ";"; 617 618 // if ( exprStmt != 0 ) { 619 exprStmt->get_expr()->accept( *this ); 620 output << ";" ; 621 // } // if 623 622 } 624 623 … … 729 728 730 729 void CodeGenerator::visit( WhileStmt *whileStmt ) { 731 if ( whileStmt->get_isDoWhile() ) {730 if ( whileStmt->get_isDoWhile() ) 732 731 output << "do" ; 733 }else {732 else { 734 733 output << "while (" ; 735 734 whileStmt->get_condition()->accept( *this ); … … 755 754 output << "for (;"; 756 755 757 if ( forStmt->get_condition() != 0 ) {756 if ( forStmt->get_condition() != 0 ) 758 757 forStmt->get_condition()->accept( *this ); 759 }760 758 output << ";"; 761 759 762 if ( forStmt->get_increment() != 0 ) { 763 // cast the top-level expression to void to reduce gcc warnings. 764 Expression * expr = new CastExpr( forStmt->get_increment() ); 765 expr->accept( *this ); 766 } 760 if ( forStmt->get_increment() != 0 ) 761 forStmt->get_increment()->accept( *this ); 767 762 output << ") "; 768 763 -
src/CodeGen/CodeGenerator.h
r685a5e8 rd5f1cfc 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // CodeGenerator.h -- 7 // CodeGenerator.h -- 8 8 // 9 9 // Author : Richard C. Bilson … … 60 60 virtual void visit( MemberExpr *memberExpr ); 61 61 virtual void visit( VariableExpr *variableExpr ); 62 virtual void visit( ConstantExpr *constantExpr ); 62 virtual void visit( ConstantExpr *constantExpr ); 63 63 virtual void visit( SizeofExpr *sizeofExpr ); 64 64 virtual void visit( AlignofExpr *alignofExpr ); … … 85 85 virtual void visit( ForStmt * ); 86 86 virtual void visit( NullStmt * ); 87 virtual void visit( DeclStmt * ); 88 89 void genAttributes( std::list< Attribute * > & attributes ); 87 virtual void visit( DeclStmt * ); 90 88 91 89 template< class Iterator > void genCommaList( Iterator begin, Iterator end ); … … 110 108 111 109 }; 112 110 113 111 template< class Iterator > 114 112 void CodeGenerator::genCommaList( Iterator begin, Iterator end ) { … … 121 119 } // for 122 120 } 123 121 124 122 inline bool doSemicolon( Declaration* decl ) { 125 123 if ( FunctionDecl* func = dynamic_cast< FunctionDecl* >( decl ) ) { -
src/GenPoly/Box.cc
r685a5e8 rd5f1cfc 1947 1947 UntypedExpr *derefExpr = new UntypedExpr( new NameExpr( "*?" ) ); 1948 1948 derefExpr->get_args().push_back( derefdVar ); 1949 // xxx - should set results on derefExpr1950 1949 derefdVar = derefExpr; 1951 1950 } -
src/GenPoly/Specialize.cc
r685a5e8 rd5f1cfc 25 25 #include "SynTree/Statement.h" 26 26 #include "SynTree/Type.h" 27 #include "SynTree/Attribute.h"28 27 #include "SynTree/TypeSubstitution.h" 29 28 #include "SynTree/Mutator.h" … … 102 101 thunkFunc->fixUniqueId(); 103 102 104 // thunks may be generated and not used - silence warning with attribute105 thunkFunc->get_attributes().push_back( new Attribute( "unused" ) );106 107 103 // thread thunk parameters into call to actual function, naming thunk parameters as we go 108 104 UniqueName paramNamer( paramPrefix ); -
src/InitTweak/FixGlobalInit.cc
r685a5e8 rd5f1cfc 22 22 #include "SynTree/Initializer.h" 23 23 #include "SynTree/Visitor.h" 24 #include "SynTree/Attribute.h"25 24 #include <algorithm> 26 25 … … 117 116 GlobalFixer::GlobalFixer( const std::string & name, bool inLibrary ) : tempNamer( "_global_init" ) { 118 117 std::string fixedName = globalFunctionName( name ); 119 std::list< Expression * > ctorParameters; 120 std::list< Expression * > dtorParameters; 121 if ( inLibrary ) { 122 // Constructor/destructor attributes take a single parameter which 123 // is the priority, with lower numbers meaning higher priority. 124 // Functions specified with priority are guaranteed to run before 125 // functions without a priority. To ensure that constructors and destructors 126 // for library code are run before constructors and destructors for user code, 127 // specify a priority when building the library. Priorities 0-100 are reserved by gcc. 128 ctorParameters.push_back( new ConstantExpr( Constant::from_int( 101 ) ) ); 129 dtorParameters.push_back( new ConstantExpr( Constant::from_int( 101 ) ) ); 130 } 131 initFunction = new FunctionDecl( "_init_" + fixedName, DeclarationNode::Static, LinkageSpec::C, new FunctionType( Type::Qualifiers(), false ), new CompoundStmt( noLabels ), false, false ); 132 initFunction->get_attributes().push_back( new Attribute( "constructor", ctorParameters ) ); 133 destroyFunction = new FunctionDecl( "_destroy_" + fixedName, DeclarationNode::Static, LinkageSpec::C, new FunctionType( Type::Qualifiers(), false ), new CompoundStmt( noLabels ), false, false ); 134 destroyFunction->get_attributes().push_back( new Attribute( "destructor", dtorParameters ) ); 118 initFunction = new FunctionDecl( "_init_" + fixedName, DeclarationNode::Static, LinkageSpec::C, new FunctionType( Type::Qualifiers(), false ), new CompoundStmt( noLabels ), false, false, FunctionDecl::Attribute( FunctionDecl::Attribute::Constructor, inLibrary ? FunctionDecl::Attribute::High : FunctionDecl::Attribute::Default ) ); 119 120 destroyFunction = new FunctionDecl( "_destroy_" + fixedName, DeclarationNode::Static, LinkageSpec::C, new FunctionType( Type::Qualifiers(), false ), new CompoundStmt( noLabels ), false, false, FunctionDecl::Attribute( FunctionDecl::Attribute::Destructor, inLibrary ? FunctionDecl::Attribute::High : FunctionDecl::Attribute::Default ) ); 135 121 } 136 122 … … 139 125 std::list< Statement * > & destroyStatements = destroyFunction->get_statements()->get_kids(); 140 126 127 // if ( objDecl->get_init() == NULL ) return; 141 128 if ( ! tryConstruct( objDecl ) ) return; // don't construct @= or designated objects 129 if ( objDecl->get_type()->get_isConst() ) return; // temporary: can't assign to a const variable 142 130 if ( objDecl->get_storageClass() == DeclarationNode::Extern ) return; 143 131 // C allows you to initialize objects with constant expressions … … 158 146 init->get_args().push_back( new AddressExpr( new VariableExpr( objDecl ) ) ); 159 147 init->get_args().push_back( new VariableExpr( newObj ) ); 160 initStatements.push_back( new ImplicitCtorDtorStmt( new ExprStmt( noLabels, init )) );148 initStatements.push_back( new ExprStmt( noLabels, init ) ); 161 149 162 150 // add destructor calls to global destroy function 163 151 UntypedExpr * destroy = new UntypedExpr( new NameExpr( "^?{}" ) ); 164 152 destroy->get_args().push_back( new AddressExpr( new VariableExpr( objDecl ) ) ); 165 destroyStatements.push_front( new ImplicitCtorDtorStmt( new ExprStmt( noLabels, destroy )) );153 destroyStatements.push_front( new ExprStmt( noLabels, destroy ) ); 166 154 } 167 155 } -
src/InitTweak/FixInit.cc
r685a5e8 rd5f1cfc 132 132 return appExpr; 133 133 } else if ( DeclarationWithType * funcDecl = dynamic_cast< DeclarationWithType * > ( function->get_var() ) ) { 134 // FunctionType * ftype = funcDecl->get_functionType(); 134 135 FunctionType * ftype = dynamic_cast< FunctionType * >( GenPoly::getFunctionType( funcDecl->get_type() ) ); 135 136 assert( ftype ); -
src/InitTweak/GenInit.cc
r685a5e8 rd5f1cfc 164 164 assert( ctor.size() == 1 ); 165 165 assert( dtor.size() == 1 ); 166 objDecl->set_init( new ConstructorInit( new ImplicitCtorDtorStmt( ctor.front() ), new ImplicitCtorDtorStmt( dtor.front() ), objDecl->get_init() ) ); 166 167 objDecl->set_init( new ConstructorInit( ctor.front(), dtor.front(), objDecl->get_init() ) ); 167 168 } else { 168 169 // array came with an initializer list: initialize each element … … 184 185 ExprStmt * ctorStmt = new ExprStmt( noLabels, ctor ); 185 186 ExprStmt * dtorStmt = new ExprStmt( noLabels, dtor ); 186 objDecl->set_init( new ConstructorInit( new ImplicitCtorDtorStmt( ctorStmt ), new ImplicitCtorDtorStmt( dtorStmt ), objDecl->get_init() ) );187 objDecl->set_init( new ConstructorInit( ctorStmt, dtorStmt, objDecl->get_init() ) ); 187 188 } 188 189 } -
src/InitTweak/InitTweak.cc
r685a5e8 rd5f1cfc 7 7 8 8 namespace InitTweak { 9 namespace {10 class HasDesignations : public Visitor {11 public:12 bool hasDesignations = false;13 template<typename Init>14 void handleInit( Init * init ) {15 if ( ! init->get_designators().empty() ) hasDesignations = true;16 else Visitor::visit( init );17 }18 virtual void visit( SingleInit * singleInit ) { handleInit( singleInit); }19 virtual void visit( ListInit * listInit ) { handleInit( listInit); }20 };9 namespace { 10 class HasDesignations : public Visitor { 11 public: 12 bool hasDesignations = false; 13 template<typename Init> 14 void handleInit( Init * init ) { 15 if ( ! init->get_designators().empty() ) hasDesignations = true; 16 else Visitor::visit( init ); 17 } 18 virtual void visit( SingleInit * singleInit ) { handleInit( singleInit); } 19 virtual void visit( ListInit * listInit ) { handleInit( listInit); } 20 }; 21 21 22 class InitExpander : public Visitor {23 public:24 InitExpander() {}25 virtual void visit( SingleInit * singleInit );26 virtual void visit( ListInit * listInit );27 std::list< Expression * > argList;28 };22 class InitExpander : public Visitor { 23 public: 24 InitExpander() {} 25 virtual void visit( SingleInit * singleInit ); 26 virtual void visit( ListInit * listInit ); 27 std::list< Expression * > argList; 28 }; 29 29 30 void InitExpander::visit( SingleInit * singleInit ) {31 argList.push_back( singleInit->get_value()->clone() );32 }30 void InitExpander::visit( SingleInit * singleInit ) { 31 argList.push_back( singleInit->get_value()->clone() ); 32 } 33 33 34 void InitExpander::visit( ListInit * listInit ) {35 // xxx - for now, assume no nested list inits36 std::list<Initializer*>::iterator it = listInit->begin_initializers();37 for ( ; it != listInit->end_initializers(); ++it ) {38 (*it)->accept( *this );39 }40 }41 }34 void InitExpander::visit( ListInit * listInit ) { 35 // xxx - for now, assume no nested list inits 36 std::list<Initializer*>::iterator it = listInit->begin_initializers(); 37 for ( ; it != listInit->end_initializers(); ++it ) { 38 (*it)->accept( *this ); 39 } 40 } 41 } 42 42 43 std::list< Expression * > makeInitList( Initializer * init ) {44 InitExpander expander;45 maybeAccept( init, expander );46 return expander.argList;47 }43 std::list< Expression * > makeInitList( Initializer * init ) { 44 InitExpander expander; 45 maybeAccept( init, expander ); 46 return expander.argList; 47 } 48 48 49 bool isDesignated( Initializer * init ) {50 HasDesignations finder;51 maybeAccept( init, finder );52 return finder.hasDesignations;53 }49 bool isDesignated( Initializer * init ) { 50 HasDesignations finder; 51 maybeAccept( init, finder ); 52 return finder.hasDesignations; 53 } 54 54 55 bool tryConstruct( ObjectDecl * objDecl ) {56 return ! LinkageSpec::isBuiltin( objDecl->get_linkage() ) &&57 (objDecl->get_init() == NULL ||58 ( objDecl->get_init() != NULL && objDecl->get_init()->get_maybeConstructed() )) &&59 ! isDesignated( objDecl->get_init() );60 }55 bool tryConstruct( ObjectDecl * objDecl ) { 56 return ! LinkageSpec::isBuiltin( objDecl->get_linkage() ) && 57 (objDecl->get_init() == NULL || 58 ( objDecl->get_init() != NULL && objDecl->get_init()->get_maybeConstructed() )) && 59 ! isDesignated( objDecl->get_init() ); 60 } 61 61 62 Expression * getCtorDtorCall( Statement * stmt ) { 63 if ( stmt == NULL ) return NULL; 64 if ( ExprStmt * exprStmt = dynamic_cast< ExprStmt * >( stmt ) ) { 65 return exprStmt->get_expr(); 66 } else if ( CompoundStmt * compoundStmt = dynamic_cast< CompoundStmt * >( stmt ) ) { 67 // could also be a compound statement with a loop, in the case of an array 68 assert( compoundStmt->get_kids().size() == 2 ); // loop variable and loop 69 ForStmt * forStmt = dynamic_cast< ForStmt * >( compoundStmt->get_kids().back() ); 70 assert( forStmt && forStmt->get_body() ); 71 return getCtorDtorCall( forStmt->get_body() ); 72 } if ( ImplicitCtorDtorStmt * impCtorDtorStmt = dynamic_cast< ImplicitCtorDtorStmt * > ( stmt ) ) { 73 return getCtorDtorCall( impCtorDtorStmt->get_callStmt() ); 74 } else { 75 // should never get here 76 assert( false && "encountered unknown call statement" ); 77 } 78 } 79 80 bool isInstrinsicSingleArgCallStmt( Statement * stmt ) { 81 Expression * callExpr = getCtorDtorCall( stmt ); 82 if ( ! callExpr ) return false; 83 ApplicationExpr * appExpr = dynamic_cast< ApplicationExpr * >( callExpr ); 84 assert( appExpr ); 85 VariableExpr * function = dynamic_cast< VariableExpr * >( appExpr->get_function() ); 86 assert( function ); 87 // check for Intrinsic only - don't want to remove all overridable ctor/dtors because autogenerated ctor/dtor 88 // will call all member dtors, and some members may have a user defined dtor. 89 FunctionType * funcType = GenPoly::getFunctionType( function->get_var()->get_type() ); 90 assert( funcType ); 91 return function->get_var()->get_linkage() == LinkageSpec::Intrinsic && funcType->get_parameters().size() == 1; 92 } 93 94 namespace { 95 template<typename CallExpr> 96 Expression *& callArg( CallExpr * callExpr, unsigned int pos ) { 97 if ( pos >= callExpr->get_args().size() ) assert( false && "asking for argument that doesn't exist. Return NULL/throw exception?" ); 98 for ( Expression *& arg : callExpr->get_args() ) { 99 if ( pos == 0 ) return arg; 100 pos--; 101 } 102 assert( false ); 103 } 104 } 105 106 Expression *& getCallArg( Expression * callExpr, unsigned int pos ) { 107 if ( ApplicationExpr * appExpr = dynamic_cast< ApplicationExpr * >( callExpr ) ) { 108 return callArg( appExpr, pos ); 109 } else if ( UntypedExpr * untypedExpr = dynamic_cast< UntypedExpr * >( callExpr ) ) { 110 return callArg( untypedExpr, pos ); 111 } else { 112 assert( false && "Unexpected expression type passed to getCallArg" ); 113 } 114 } 115 116 namespace { 117 template<typename CallExpr> 118 std::string funcName( CallExpr * expr ) { 119 Expression * func = expr->get_function(); 120 if ( NameExpr * nameExpr = dynamic_cast< NameExpr * >( func ) ) { 121 return nameExpr->get_name(); 122 } else if ( VariableExpr * varExpr = dynamic_cast< VariableExpr * >( func ) ) { 123 return varExpr->get_var()->get_name(); 124 } else { 125 assert( false && "Unexpected expression type being called as a function in call expression" ); 126 } 127 } 128 } 129 130 std::string getFunctionName( Expression * expr ) { 131 if ( ApplicationExpr * appExpr = dynamic_cast< ApplicationExpr * >( expr ) ) { 132 return funcName( appExpr ); 133 } else if ( UntypedExpr * untypedExpr = dynamic_cast< UntypedExpr * > ( expr ) ) { 134 return funcName( untypedExpr ); 135 } else { 136 assert( false && "Unexpected expression type passed to getFunctionName" ); 137 } 138 } 139 140 Type * getPointerBase( Type * type ) { 141 if ( PointerType * ptrType = dynamic_cast< PointerType * >( type ) ) { 142 return ptrType->get_base(); 143 } else if ( ArrayType * arrayType = dynamic_cast< ArrayType * >( type ) ) { 144 return arrayType->get_base(); 145 } else { 146 return NULL; 147 } 148 } 149 150 Type * isPointerType( Type * type ) { 151 if ( getPointerBase( type ) ) return type; 152 else return NULL; 153 } 62 bool isInstrinsicSingleArgCallStmt( Statement * stmt ) { 63 if ( stmt == NULL ) return false; 64 if ( ExprStmt * exprStmt = dynamic_cast< ExprStmt * >( stmt ) ) { 65 ApplicationExpr * appExpr = dynamic_cast< ApplicationExpr * >( exprStmt->get_expr() ); 66 assert( appExpr ); 67 VariableExpr * function = dynamic_cast< VariableExpr * >( appExpr->get_function() ); 68 assert( function ); 69 // check for Intrinsic only - don't want to remove all overridable ctor/dtors because autogenerated ctor/dtor 70 // will call all member dtors, and some members may have a user defined dtor. 71 FunctionType * funcType = GenPoly::getFunctionType( function->get_var()->get_type() ); 72 assert( funcType ); 73 return function->get_var()->get_linkage() == LinkageSpec::Intrinsic && funcType->get_parameters().size() == 1; 74 } else if ( CompoundStmt * compoundStmt = dynamic_cast< CompoundStmt * >( stmt ) ) { 75 // could also be a compound statement with a loop, in the case of an array 76 assert( compoundStmt->get_kids().size() == 2 ); // loop variable and loop 77 ForStmt * forStmt = dynamic_cast< ForStmt * >( compoundStmt->get_kids().back() ); 78 assert( forStmt && forStmt->get_body() ); 79 return isInstrinsicSingleArgCallStmt( forStmt->get_body() ); 80 } else { 81 // should never get here 82 assert( false && "encountered unknown call statement" ); 83 } 84 } 154 85 } -
src/InitTweak/InitTweak.h
r685a5e8 rd5f1cfc 39 39 /// Currently has assertions that make it less than fully general. 40 40 bool isInstrinsicSingleArgCallStmt( Statement * expr ); 41 42 /// get the Ctor/Dtor call expression from a Statement that looks like a generated ctor/dtor call43 Expression * getCtorDtorCall( Statement * stmt );44 45 /// returns the name of the function being called46 std::string getFunctionName( Expression * expr );47 48 /// returns the argument to a call expression in position N indexed from 049 Expression *& getCallArg( Expression * callExpr, unsigned int pos );50 51 /// returns the base type of a PointerType or ArrayType, else returns NULL52 Type * getPointerBase( Type * );53 54 /// returns the argument if it is a PointerType or ArrayType, else returns NULL55 Type * isPointerType( Type * );56 41 } // namespace 57 42 -
src/Makefile.in
r685a5e8 rd5f1cfc 195 195 SynTree/driver_cfa_cpp-Mutator.$(OBJEXT) \ 196 196 SynTree/driver_cfa_cpp-TypeSubstitution.$(OBJEXT) \ 197 SynTree/driver_cfa_cpp-Attribute.$(OBJEXT) \198 197 Tuples/driver_cfa_cpp-Mutate.$(OBJEXT) \ 199 198 Tuples/driver_cfa_cpp-AssignExpand.$(OBJEXT) \ … … 384 383 SynTree/NamedTypeDecl.cc SynTree/TypeDecl.cc \ 385 384 SynTree/Initializer.cc SynTree/Visitor.cc SynTree/Mutator.cc \ 386 SynTree/TypeSubstitution.cc SynTree/Attribute.cc \387 Tuples/ Mutate.cc Tuples/AssignExpand.cc \388 Tuples/ FunctionFixer.cc Tuples/TupleAssignment.cc \389 Tuples/ FunctionChecker.cc Tuples/NameMatcher.cc385 SynTree/TypeSubstitution.cc Tuples/Mutate.cc \ 386 Tuples/AssignExpand.cc Tuples/FunctionFixer.cc \ 387 Tuples/TupleAssignment.cc Tuples/FunctionChecker.cc \ 388 Tuples/NameMatcher.cc 390 389 MAINTAINERCLEANFILES = Parser/parser.output ${libdir}/${notdir \ 391 390 ${cfa_cpplib_PROGRAMS}} … … 415 414 esac; \ 416 415 done; \ 417 echo ' cd $(top_srcdir) && $(AUTOMAKE) -- foreignsrc/Makefile'; \416 echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu src/Makefile'; \ 418 417 $(am__cd) $(top_srcdir) && \ 419 $(AUTOMAKE) -- foreignsrc/Makefile418 $(AUTOMAKE) --gnu src/Makefile 420 419 .PRECIOUS: Makefile 421 420 Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status … … 756 755 SynTree/driver_cfa_cpp-TypeSubstitution.$(OBJEXT): \ 757 756 SynTree/$(am__dirstamp) SynTree/$(DEPDIR)/$(am__dirstamp) 758 SynTree/driver_cfa_cpp-Attribute.$(OBJEXT): SynTree/$(am__dirstamp) \759 SynTree/$(DEPDIR)/$(am__dirstamp)760 757 Tuples/$(am__dirstamp): 761 758 @$(MKDIR_P) Tuples … … 855 852 -rm -f SynTree/driver_cfa_cpp-ArrayType.$(OBJEXT) 856 853 -rm -f SynTree/driver_cfa_cpp-AttrType.$(OBJEXT) 857 -rm -f SynTree/driver_cfa_cpp-Attribute.$(OBJEXT)858 854 -rm -f SynTree/driver_cfa_cpp-BasicType.$(OBJEXT) 859 855 -rm -f SynTree/driver_cfa_cpp-CommaExpr.$(OBJEXT) … … 965 961 @AMDEP_TRUE@@am__include@ @am__quote@SynTree/$(DEPDIR)/driver_cfa_cpp-ArrayType.Po@am__quote@ 966 962 @AMDEP_TRUE@@am__include@ @am__quote@SynTree/$(DEPDIR)/driver_cfa_cpp-AttrType.Po@am__quote@ 967 @AMDEP_TRUE@@am__include@ @am__quote@SynTree/$(DEPDIR)/driver_cfa_cpp-Attribute.Po@am__quote@968 963 @AMDEP_TRUE@@am__include@ @am__quote@SynTree/$(DEPDIR)/driver_cfa_cpp-BasicType.Po@am__quote@ 969 964 @AMDEP_TRUE@@am__include@ @am__quote@SynTree/$(DEPDIR)/driver_cfa_cpp-CommaExpr.Po@am__quote@ … … 2401 2396 @AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ 2402 2397 @am__fastdepCXX_FALSE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(driver_cfa_cpp_CXXFLAGS) $(CXXFLAGS) -c -o SynTree/driver_cfa_cpp-TypeSubstitution.obj `if test -f 'SynTree/TypeSubstitution.cc'; then $(CYGPATH_W) 'SynTree/TypeSubstitution.cc'; else $(CYGPATH_W) '$(srcdir)/SynTree/TypeSubstitution.cc'; fi` 2403 2404 SynTree/driver_cfa_cpp-Attribute.o: SynTree/Attribute.cc2405 @am__fastdepCXX_TRUE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(driver_cfa_cpp_CXXFLAGS) $(CXXFLAGS) -MT SynTree/driver_cfa_cpp-Attribute.o -MD -MP -MF SynTree/$(DEPDIR)/driver_cfa_cpp-Attribute.Tpo -c -o SynTree/driver_cfa_cpp-Attribute.o `test -f 'SynTree/Attribute.cc' || echo '$(srcdir)/'`SynTree/Attribute.cc2406 @am__fastdepCXX_TRUE@ $(am__mv) SynTree/$(DEPDIR)/driver_cfa_cpp-Attribute.Tpo SynTree/$(DEPDIR)/driver_cfa_cpp-Attribute.Po2407 @AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='SynTree/Attribute.cc' object='SynTree/driver_cfa_cpp-Attribute.o' libtool=no @AMDEPBACKSLASH@2408 @AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@2409 @am__fastdepCXX_FALSE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(driver_cfa_cpp_CXXFLAGS) $(CXXFLAGS) -c -o SynTree/driver_cfa_cpp-Attribute.o `test -f 'SynTree/Attribute.cc' || echo '$(srcdir)/'`SynTree/Attribute.cc2410 2411 SynTree/driver_cfa_cpp-Attribute.obj: SynTree/Attribute.cc2412 @am__fastdepCXX_TRUE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(driver_cfa_cpp_CXXFLAGS) $(CXXFLAGS) -MT SynTree/driver_cfa_cpp-Attribute.obj -MD -MP -MF SynTree/$(DEPDIR)/driver_cfa_cpp-Attribute.Tpo -c -o SynTree/driver_cfa_cpp-Attribute.obj `if test -f 'SynTree/Attribute.cc'; then $(CYGPATH_W) 'SynTree/Attribute.cc'; else $(CYGPATH_W) '$(srcdir)/SynTree/Attribute.cc'; fi`2413 @am__fastdepCXX_TRUE@ $(am__mv) SynTree/$(DEPDIR)/driver_cfa_cpp-Attribute.Tpo SynTree/$(DEPDIR)/driver_cfa_cpp-Attribute.Po2414 @AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='SynTree/Attribute.cc' object='SynTree/driver_cfa_cpp-Attribute.obj' libtool=no @AMDEPBACKSLASH@2415 @AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@2416 @am__fastdepCXX_FALSE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(driver_cfa_cpp_CXXFLAGS) $(CXXFLAGS) -c -o SynTree/driver_cfa_cpp-Attribute.obj `if test -f 'SynTree/Attribute.cc'; then $(CYGPATH_W) 'SynTree/Attribute.cc'; else $(CYGPATH_W) '$(srcdir)/SynTree/Attribute.cc'; fi`2417 2398 2418 2399 Tuples/driver_cfa_cpp-Mutate.o: Tuples/Mutate.cc -
src/ResolvExpr/AlternativeFinder.cc
r685a5e8 rd5f1cfc 39 39 #include "Tuples/NameMatcher.h" 40 40 #include "Common/utility.h" 41 #include "InitTweak/InitTweak.h"42 41 43 42 extern bool resolvep; … … 547 546 548 547 { 549 std::string fname = InitTweak::getFunctionName( untypedExpr ); 550 if ( fname == "&&" ) { 548 NameExpr *fname = 0;; 549 if ( ( fname = dynamic_cast<NameExpr *>( untypedExpr->get_function())) 550 && ( fname->get_name() == std::string("&&")) ) { 551 551 VoidType v = Type::Qualifiers(); // resolve to type void * 552 552 PointerType pt( Type::Qualifiers(), v.clone() ); -
src/ResolvExpr/Resolver.cc
r685a5e8 rd5f1cfc 52 52 virtual void visit( BranchStmt *branchStmt ); 53 53 virtual void visit( ReturnStmt *returnStmt ); 54 virtual void visit( ImplicitCtorDtorStmt * impCtorDtorStmt );55 54 56 55 virtual void visit( SingleInit *singleInit ); … … 493 492 } catch ( SemanticError ) { 494 493 // no alternatives for the constructor initializer - fallback on C-style initializer 495 // xxx - not sure if this makes a ton of sense - should maybe never be able to have this situation?494 // xxx- not sure if this makes a ton of sense - should maybe never be able to have this situation? 496 495 fallbackInit( ctorInit ); 497 496 return; … … 514 513 } 515 514 } 516 517 void Resolver::visit( ImplicitCtorDtorStmt * impCtorDtorStmt ) {518 // before resolving ctor/dtor, need to remove type qualifiers from the first argument (the object being constructed).519 // Do this through a cast expression to greatly simplify the code.520 Expression * callExpr = InitTweak::getCtorDtorCall( impCtorDtorStmt );521 assert( callExpr );522 Expression *& constructee = InitTweak::getCallArg( callExpr, 0 );523 Type * type = 0;524 525 // need to find the type of the first argument, which is unfortunately not uniform since array construction526 // includes an untyped '+' expression.527 if ( UntypedExpr * plusExpr = dynamic_cast< UntypedExpr * >( constructee ) ) {528 // constructee is <array>+<index>529 // get Variable <array>, then get the base type of the VariableExpr - this is the type that needs to be fixed530 Expression * arr = InitTweak::getCallArg( plusExpr, 0 );531 assert( dynamic_cast< VariableExpr * >( arr ) );532 assert( arr && arr->get_results().size() == 1 );533 type = arr->get_results().front()->clone();534 } else {535 // otherwise, constructing a plain object, which means the object's address is being taken.536 // Need to get the type of the VariableExpr object, because the AddressExpr is rebuilt and uses the537 // type of the VariableExpr to do so.538 assert( constructee->get_results().size() == 1 );539 AddressExpr * addrExpr = dynamic_cast< AddressExpr * > ( constructee );540 assert( addrExpr && addrExpr->get_results().size() == 1);541 type = addrExpr->get_results().front()->clone();542 }543 // cast to T* with qualifiers removed.544 // unfortunately, lvalue is considered a qualifier. For AddressExpr to resolve, its argument545 // must have an lvalue qualified type, so remove all qualifiers except lvalue. If we ever546 // remove lvalue as a qualifier, this can change to547 // type->get_qualifiers() = Type::Qualifiers();548 Type * base = InitTweak::getPointerBase( type );549 assert( base );550 base->get_qualifiers() -= Type::Qualifiers(true, true, true, false, true, true);551 // if pointer has lvalue qualifier, cast won't appear in output552 type->set_isLvalue( false );553 constructee = new CastExpr( constructee, type );554 555 // finally, resolve the ctor/dtor556 impCtorDtorStmt->get_callStmt()->accept( *this );557 }558 515 } // namespace ResolvExpr 559 516 -
src/SymTab/Autogen.cc
r685a5e8 rd5f1cfc 129 129 // since there is no definition, these should not be inline 130 130 // make these intrinsic so that the code generator does not make use of them 131 FunctionDecl *assignDecl = new FunctionDecl( "?=?", functionNesting > 0 ? DeclarationNode::NoStorageClass : DeclarationNode::Static, LinkageSpec::Intrinsic, assignType, 0, true, false );131 FunctionDecl *assignDecl = new FunctionDecl( "?=?", functionNesting > 0 ? DeclarationNode::NoStorageClass : DeclarationNode::Static, LinkageSpec::Intrinsic, assignType, 0, false, false ); 132 132 assignDecl->fixUniqueId(); 133 FunctionDecl *assignDecl2 = new FunctionDecl( "?=?", functionNesting > 0 ? DeclarationNode::NoStorageClass : DeclarationNode::Static, LinkageSpec::Intrinsic, assignType2, 0, true, false );133 FunctionDecl *assignDecl2 = new FunctionDecl( "?=?", functionNesting > 0 ? DeclarationNode::NoStorageClass : DeclarationNode::Static, LinkageSpec::Intrinsic, assignType2, 0, false, false ); 134 134 assignDecl2->fixUniqueId(); 135 135 … … 488 488 type->get_parameters().push_back( dst ); 489 489 type->get_parameters().push_back( src ); 490 FunctionDecl *func = new FunctionDecl( "?=?", DeclarationNode::NoStorageClass, LinkageSpec::AutoGen, type, stmts, true, false );490 FunctionDecl *func = new FunctionDecl( "?=?", DeclarationNode::NoStorageClass, LinkageSpec::AutoGen, type, stmts, false, false ); 491 491 declsToAdd.push_back( func ); 492 492 } -
src/SynTree/Declaration.h
r685a5e8 rd5f1cfc 115 115 typedef DeclarationWithType Parent; 116 116 public: 117 FunctionDecl( const std::string &name, DeclarationNode::StorageClass sc, LinkageSpec::Type linkage, FunctionType *type, CompoundStmt *statements, bool isInline, bool isNoreturn, const std::list< Attribute * > attributes = std::list< Attribute * >() ); 117 // temporary - merge this into general GCC attributes 118 struct Attribute { 119 enum Type { 120 NoAttribute, Constructor, Destructor, 121 } type; 122 enum Priority { 123 // priorities 0-100 are reserved by gcc, so it's okay to use 100 an exceptional case 124 Default = 100, High, 125 } priority; 126 Attribute(Type t = NoAttribute, Priority p = Default) : type(t), priority(p) {}; 127 }; 128 129 FunctionDecl( const std::string &name, DeclarationNode::StorageClass sc, LinkageSpec::Type linkage, FunctionType *type, CompoundStmt *statements, bool isInline, bool isNoreturn, Attribute attribute = Attribute() ); 118 130 FunctionDecl( const FunctionDecl &other ); 119 131 virtual ~FunctionDecl(); … … 128 140 std::list< std::string >& get_oldIdents() { return oldIdents; } 129 141 std::list< Declaration* >& get_oldDecls() { return oldDecls; } 130 std::list< Attribute * >& get_attributes() { return attributes; } 142 Attribute get_attribute() const { return attribute; } 143 void set_attribute( Attribute newValue ) { attribute = newValue; } 131 144 132 145 virtual FunctionDecl *clone() const { return new FunctionDecl( *this ); } … … 140 153 std::list< std::string > oldIdents; 141 154 std::list< Declaration* > oldDecls; 142 std::list< Attribute * > attributes;155 Attribute attribute; 143 156 }; 144 157 -
src/SynTree/FunctionDecl.cc
r685a5e8 rd5f1cfc 19 19 #include "Statement.h" 20 20 #include "Type.h" 21 #include "Attribute.h"22 21 #include "Common/utility.h" 23 22 24 FunctionDecl::FunctionDecl( const std::string &name, DeclarationNode::StorageClass sc, LinkageSpec::Type linkage, FunctionType *type, CompoundStmt *statements, bool isInline, bool isNoreturn, std::list< Attribute * > attributes)25 : Parent( name, sc, linkage ), type( type ), statements( statements ), attribute s( attributes) {23 FunctionDecl::FunctionDecl( const std::string &name, DeclarationNode::StorageClass sc, LinkageSpec::Type linkage, FunctionType *type, CompoundStmt *statements, bool isInline, bool isNoreturn, Attribute attribute ) 24 : Parent( name, sc, linkage ), type( type ), statements( statements ), attribute( attribute ) { 26 25 set_isInline( isInline ); 27 26 set_isNoreturn( isNoreturn ); … … 33 32 34 33 FunctionDecl::FunctionDecl( const FunctionDecl &other ) 35 : Parent( other ), type( maybeClone( other.type ) ), statements( maybeClone( other.statements ) ) { 36 cloneAll( other.attributes, attributes ); 34 : Parent( other ), type( maybeClone( other.type ) ), statements( maybeClone( other.statements ) ), attribute( other.attribute ) { 37 35 } 38 36 … … 40 38 delete type; 41 39 delete statements; 42 deleteAll( attributes );43 40 } 44 41 … … 68 65 os << "_Noreturn "; 69 66 } // if 70 71 printAll( attributes, os, indent ); 72 67 switch ( attribute.type ) { 68 case Attribute::Constructor: 69 os << "Global Constructor "; 70 break; 71 case Attribute::Destructor: 72 os << "Global Destructor "; 73 break; 74 default: 75 break; 76 } 77 if ( attribute.priority != Attribute::Default ) { 78 os << "with priority " << attribute.priority << " "; 79 } 73 80 if ( get_storageClass() != DeclarationNode::NoStorageClass ) { 74 81 os << DeclarationNode::storageName[ get_storageClass() ] << ' '; … … 111 118 os << "_Noreturn "; 112 119 } // if 113 114 // xxx - should printShort print attributes? 115 120 switch ( attribute.type ) { 121 case Attribute::Constructor: 122 os << " Global Constructor "; 123 break; 124 case Attribute::Destructor: 125 os << " Global Destructor "; 126 break; 127 default: 128 break; 129 } 130 if ( attribute.priority != Attribute::Default ) { 131 os << "with priority " << attribute.priority << " "; 132 } 116 133 if ( get_storageClass() != DeclarationNode::NoStorageClass ) { 117 134 os << DeclarationNode::storageName[ get_storageClass() ] << ' '; -
src/SynTree/Initializer.cc
r685a5e8 rd5f1cfc 20 20 21 21 Initializer::Initializer( bool maybeConstructed ) : maybeConstructed( maybeConstructed ) {} 22 Initializer::Initializer( const Initializer & other ) : maybeConstructed( other.maybeConstructed ) {23 }24 25 22 26 23 Initializer::~Initializer() {} … … 42 39 } 43 40 44 SingleInit::~SingleInit() { 45 deleteAll(designators); 46 }41 SingleInit::~SingleInit() {} 42 43 SingleInit *SingleInit::clone() const { return new SingleInit( *this); } 47 44 48 45 void SingleInit::print( std::ostream &os, int indent ) { … … 61 58 62 59 ListInit::ListInit( const std::list<Initializer*> &_initializers, const std::list<Expression *> &_designators, bool maybeConstructed ) 63 : Initializer( maybeConstructed ), initializers( _initializers ), designators( _designators ) {60 : Initializer( maybeConstructed), initializers( _initializers ), designators( _designators ) { 64 61 } 65 62 66 ListInit::~ListInit() { 67 deleteAll( initializers ); 68 deleteAll( designators ); 63 ListInit::~ListInit() {} 64 65 ListInit *ListInit::clone() const { 66 return new ListInit( *this ); 69 67 } 70 68 … … 87 85 88 86 ConstructorInit::ConstructorInit( Statement * ctor, Statement * dtor, Initializer * init ) : Initializer( true ), ctor( ctor ), dtor( dtor ), init( init ) {} 89 ConstructorInit::ConstructorInit( const ConstructorInit &other ) : Initializer( other ), ctor( maybeClone( other.ctor ) ), dtor( maybeClone( other.dtor ) ), init( maybeClone( other.init ) ) { 87 ConstructorInit::~ConstructorInit() { 88 delete ctor; 89 delete init; 90 90 } 91 91 92 ConstructorInit::~ConstructorInit() { 93 delete ctor; 94 delete dtor; 95 delete init; 92 ConstructorInit *ConstructorInit::clone() const { 93 return new ConstructorInit( *this ); 96 94 } 97 95 -
src/SynTree/Initializer.h
r685a5e8 rd5f1cfc 20 20 #include "Visitor.h" 21 21 #include "Mutator.h" 22 #include "Type.h"23 22 24 23 #include <cassert> … … 29 28 // Initializer( std::string _name = std::string(""), int _pos = 0 ); 30 29 Initializer( bool maybeConstructed ); 31 Initializer( const Initializer & other );32 30 virtual ~Initializer(); 33 31 … … 70 68 std::list<Expression *> &get_designators() { return designators; } 71 69 72 virtual SingleInit *clone() const { return new SingleInit( *this); }70 virtual SingleInit *clone() const; 73 71 virtual void accept( Visitor &v ) { v.visit( this ); } 74 72 virtual Initializer *acceptMutator( Mutator &m ) { return m.mutate( this ); } … … 96 94 std::list<Initializer*>::iterator end_initializers() { return initializers.end(); } 97 95 98 virtual ListInit *clone() const { return new ListInit( *this ); }96 virtual ListInit *clone() const; 99 97 virtual void accept( Visitor &v ) { v.visit( this ); } 100 98 virtual Initializer *acceptMutator( Mutator &m ) { return m.mutate( this ); } … … 110 108 public: 111 109 ConstructorInit( Statement * ctor, Statement * dtor, Initializer * init ); 112 ConstructorInit( const ConstructorInit &other );113 110 virtual ~ConstructorInit(); 114 111 … … 120 117 Initializer * get_init() const { return init; } 121 118 122 ConstructorInit *clone() const { return new ConstructorInit( *this ); }119 virtual ConstructorInit *clone() const; 123 120 virtual void accept( Visitor &v ) { v.visit( this ); } 124 121 virtual Initializer *acceptMutator( Mutator &m ) { return m.mutate( this ); } -
src/SynTree/Mutator.cc
r685a5e8 rd5f1cfc 182 182 } 183 183 184 Statement *Mutator::mutate( ImplicitCtorDtorStmt *impCtorDtorStmt ) {185 impCtorDtorStmt->set_callStmt( maybeMutate( impCtorDtorStmt->get_callStmt(), *this ) );186 return impCtorDtorStmt;187 }188 189 184 Expression *Mutator::mutate( ApplicationExpr *applicationExpr ) { 190 185 mutateAll( applicationExpr->get_results(), *this ); -
src/SynTree/Mutator.h
r685a5e8 rd5f1cfc 52 52 virtual NullStmt* mutate( NullStmt *nullStmt ); 53 53 virtual Statement* mutate( DeclStmt *declStmt ); 54 virtual Statement* mutate( ImplicitCtorDtorStmt *impCtorDtorStmt );55 54 56 55 virtual Expression* mutate( ApplicationExpr *applicationExpr ); -
src/SynTree/Statement.cc
r685a5e8 rd5f1cfc 358 358 359 359 void CatchStmt::print( std::ostream &os, int indent ) const { 360 os << "Catch Statement" << endl;360 os << string( indent, ' ' ) << "Catch Statement" << endl; 361 361 362 362 os << string( indent, ' ' ) << "... catching" << endl; … … 383 383 384 384 void FinallyStmt::print( std::ostream &os, int indent ) const { 385 os << "Finally Statement" << endl;385 os << string( indent, ' ' ) << "Finally Statement" << endl; 386 386 os << string( indent + 2, ' ' ) << "with block: " << endl; 387 387 block->print( os, indent + 4 ); … … 393 393 void NullStmt::print( std::ostream &os, int indent ) const { 394 394 os << "Null Statement" << endl ; 395 }396 397 ImplicitCtorDtorStmt::ImplicitCtorDtorStmt( Statement * callStmt ) : Statement( std::list<Label>() ), callStmt( callStmt ) {398 assert( callStmt );399 }400 401 ImplicitCtorDtorStmt::ImplicitCtorDtorStmt( const ImplicitCtorDtorStmt & other ) : Statement( other ), callStmt( other.callStmt ) {402 }403 404 ImplicitCtorDtorStmt::~ImplicitCtorDtorStmt() {405 }406 407 void ImplicitCtorDtorStmt::print( std::ostream &os, int indent ) const {408 os << "Implicit Ctor Dtor Statement" << endl;409 os << string( indent + 2, ' ' ) << "with Ctor/Dtor: ";410 callStmt->print( os, indent + 2);411 os << endl;412 395 } 413 396 -
src/SynTree/Statement.h
r685a5e8 rd5f1cfc 21 21 #include "Mutator.h" 22 22 #include "Common/SemanticError.h" 23 #include "Type.h"24 23 25 24 class Statement { … … 395 394 virtual ~DeclStmt(); 396 395 397 Declaration *get_decl() const{ return decl; }396 Declaration *get_decl() { return decl; } 398 397 void set_decl( Declaration *newValue ) { decl = newValue; } 399 398 … … 405 404 Declaration *decl; 406 405 }; 407 408 409 /// represents an implicit application of a constructor or destructor. Qualifiers are replaced410 /// immediately before and after the call so that qualified objects can be constructed411 /// with the same functions as unqualified objects.412 class ImplicitCtorDtorStmt : public Statement {413 public:414 ImplicitCtorDtorStmt( Statement * callStmt );415 ImplicitCtorDtorStmt( const ImplicitCtorDtorStmt & other );416 virtual ~ImplicitCtorDtorStmt();417 418 Statement *get_callStmt() const { return callStmt; }419 void set_callStmt( Statement * newValue ) { callStmt = newValue; }420 421 virtual ImplicitCtorDtorStmt *clone() const { return new ImplicitCtorDtorStmt( *this ); }422 virtual void accept( Visitor &v ) { v.visit( this ); }423 virtual Statement *acceptMutator( Mutator &m ) { return m.mutate( this ); }424 virtual void print( std::ostream &os, int indent = 0 ) const;425 426 private:427 // Non-owned pointer to the constructor/destructor statement428 Statement * callStmt;429 };430 431 406 432 407 std::ostream & operator<<( std::ostream & out, Statement * statement ); -
src/SynTree/SynTree.h
r685a5e8 rd5f1cfc 56 56 class DeclStmt; 57 57 class NullStmt; 58 class ImplicitCtorDtorStmt;59 58 60 59 class Expression; … … 118 117 class TypeSubstitution; 119 118 120 // gcc attribute121 class Attribute;122 123 119 #endif // SYNTREE_H 124 120 -
src/SynTree/Type.cc
r685a5e8 rd5f1cfc 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // Type.cc -- 7 // Type.cc -- 8 8 // 9 9 // Author : Richard C. Bilson … … 54 54 } 55 55 56 void Type::Qualifiers::print( std::ostream &os, int indent ) const {57 if ( isConst ) {58 os << "const ";59 } // if60 if ( isVolatile ) {61 os << "volatile ";62 } // if63 if ( isRestrict ) {64 os << "restrict ";65 } // if66 if ( isLvalue ) {67 os << "lvalue ";68 } // if69 if ( isAtomic ) {70 os << "_Atomic ";71 } // if72 if ( isAttribute ) {73 os << "__attribute(( )) ";74 } // if75 }76 77 56 void Type::print( std::ostream &os, int indent ) const { 78 57 if ( ! forall.empty() ) { … … 81 60 os << std::string( indent+2, ' ' ); 82 61 } // if 83 tq.print( os, indent ); 62 if ( tq.isConst ) { 63 os << "const "; 64 } // if 65 if ( tq.isVolatile ) { 66 os << "volatile "; 67 } // if 68 if ( tq.isRestrict ) { 69 os << "restrict "; 70 } // if 71 if ( tq.isLvalue ) { 72 os << "lvalue "; 73 } // if 74 if ( tq.isAtomic ) { 75 os << "_Atomic "; 76 } // if 77 if ( tq.isAttribute ) { 78 os << "__attribute(( )) "; 79 } // if 84 80 } 85 81 -
src/SynTree/Type.h
r685a5e8 rd5f1cfc 36 36 bool operator<( const Qualifiers &other ); 37 37 bool operator>( const Qualifiers &other ); 38 void print( std::ostream &os, int indent = 0 ) const;39 38 40 39 bool isConst; -
src/SynTree/Visitor.cc
r685a5e8 rd5f1cfc 152 152 } 153 153 154 void Visitor::visit( ImplicitCtorDtorStmt *impCtorDtorStmt ) {155 maybeAccept( impCtorDtorStmt->get_callStmt(), *this );156 }157 158 154 void Visitor::visit( ApplicationExpr *applicationExpr ) { 159 155 acceptAll( applicationExpr->get_results(), *this ); -
src/SynTree/Visitor.h
r685a5e8 rd5f1cfc 52 52 virtual void visit( NullStmt *nullStmt ); 53 53 virtual void visit( DeclStmt *declStmt ); 54 virtual void visit( ImplicitCtorDtorStmt *impCtorDtorStmt );55 54 56 55 virtual void visit( ApplicationExpr *applicationExpr ); -
src/SynTree/module.mk
r685a5e8 rd5f1cfc 6 6 ## file "LICENCE" distributed with Cforall. 7 7 ## 8 ## module.mk -- 8 ## module.mk -- 9 9 ## 10 10 ## Author : Richard C. Bilson … … 46 46 SynTree/Visitor.cc \ 47 47 SynTree/Mutator.cc \ 48 SynTree/TypeSubstitution.cc \ 49 SynTree/Attribute.cc 48 SynTree/TypeSubstitution.cc 50 49 -
src/driver/Makefile.in
r685a5e8 rd5f1cfc 196 196 esac; \ 197 197 done; \ 198 echo ' cd $(top_srcdir) && $(AUTOMAKE) -- foreignsrc/driver/Makefile'; \198 echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu src/driver/Makefile'; \ 199 199 $(am__cd) $(top_srcdir) && \ 200 $(AUTOMAKE) -- foreignsrc/driver/Makefile200 $(AUTOMAKE) --gnu src/driver/Makefile 201 201 .PRECIOUS: Makefile 202 202 Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status -
src/examples/Makefile.in
r685a5e8 rd5f1cfc 198 198 esac; \ 199 199 done; \ 200 echo ' cd $(top_srcdir) && $(AUTOMAKE) -- foreignsrc/examples/Makefile'; \200 echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu src/examples/Makefile'; \ 201 201 $(am__cd) $(top_srcdir) && \ 202 $(AUTOMAKE) -- foreignsrc/examples/Makefile202 $(AUTOMAKE) --gnu src/examples/Makefile 203 203 .PRECIOUS: Makefile 204 204 Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status -
src/examples/avltree/avl-private.h
r685a5e8 rd5f1cfc 1 #ifndef AVL_PRIVATE_H2 1 #include "avl.h" 3 2 … … 14 13 forall(otype K | Comparable(K), otype V) 15 14 int height(tree(K, V) * t); 16 17 #endif -
src/libcfa/Makefile.in
r685a5e8 rd5f1cfc 231 231 esac; \ 232 232 done; \ 233 echo ' cd $(top_srcdir) && $(AUTOMAKE) -- foreignsrc/libcfa/Makefile'; \233 echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu src/libcfa/Makefile'; \ 234 234 $(am__cd) $(top_srcdir) && \ 235 $(AUTOMAKE) -- foreignsrc/libcfa/Makefile235 $(AUTOMAKE) --gnu src/libcfa/Makefile 236 236 .PRECIOUS: Makefile 237 237 Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
Note:
See TracChangeset
for help on using the changeset viewer.