Changes in / [a56767c:61f9356]
- Location:
- src
- Files:
-
- 2 added
- 18 edited
-
CodeGen/CodeGenerator.cc (modified) (3 diffs)
-
CodeGen/OperatorTable.cc (modified) (2 diffs)
-
CodeGen/OperatorTable.h (modified) (2 diffs)
-
GenPoly/Box.cc (modified) (2 diffs)
-
InitTweak/InitModel.cc (modified) (3 diffs)
-
InitTweak/RemoveInit.cc (modified) (7 diffs)
-
MakeLibCfa.cc (modified) (5 diffs)
-
Parser/DeclarationNode.cc (modified) (7 diffs)
-
Parser/InitializerNode.cc (modified) (5 diffs)
-
Parser/ParseNode.h (modified) (7 diffs)
-
Parser/parser.cc (modified) (1 diff)
-
Parser/parser.yy (modified) (3 diffs)
-
SymTab/Validate.cc (modified) (4 diffs)
-
SynTree/Declaration.h (modified) (3 diffs)
-
SynTree/Initializer.cc (modified) (5 diffs)
-
SynTree/Initializer.h (modified) (6 diffs)
-
SynTree/ObjectDecl.cc (modified) (7 diffs)
-
examples/tests/vector_test.in.txt (added)
-
examples/tests/vector_test.out.txt (added)
-
initialization.txt (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
src/CodeGen/CodeGenerator.cc
ra56767c r61f9356 10 10 // Created On : Mon May 18 07:44:20 2015 11 11 // Last Modified By : Rob Schluntz 12 // Last Modified On : Thu Sep 17 15:2 5:58 201513 // Update Count : 23 312 // Last Modified On : Thu Sep 17 15:24:08 2015 13 // Update Count : 231 14 14 // 15 15 … … 258 258 259 259 case OT_CALL: 260 case OT_CTOR: 261 case OT_DTOR: 262 // there are no intrinsic definitions of the function call operator or constructors or destructors 260 // there are no intrinsic definitions of the function call operator 263 261 assert( false ); 264 262 break; … … 324 322 325 323 case OT_CALL: 326 case OT_CTOR:327 case OT_DTOR:328 324 assert( false ); 329 325 break; -
src/CodeGen/OperatorTable.cc
ra56767c r61f9356 9 9 // Author : Richard C. Bilson 10 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Rob Schluntz12 // Last Modified On : Tue Oct 06 15:26:34 201513 // Update Count : 911 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue Jun 23 17:41:14 2015 13 // Update Count : 5 14 14 // 15 15 … … 21 21 const OperatorInfo tableValues[] = { 22 22 { "?[?]", "", "_operator_index", OT_INDEX }, 23 { "?{}", "", "_constructor", OT_CTOR },24 { "^?{}", "", "_destructor", OT_DTOR }, // ~?{}, -?{}, !?{}, $?{}, ??{}, ^?{}, ?destroy, ?delete25 23 { "?()", "", "_operator_call", OT_CALL }, 26 24 { "?++", "++", "_operator_postincr", OT_POSTFIXASSIGN }, -
src/CodeGen/OperatorTable.h
ra56767c r61f9356 9 9 // Author : Richard C. Bilson 10 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Rob Schluntz12 // Last Modified On : Wed Jun 24 16:17:57 201513 // Update Count : 511 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue Jun 23 16:09:27 2015 13 // Update Count : 3 14 14 // 15 15 … … 22 22 enum OperatorType { 23 23 OT_INDEX, 24 OT_CTOR,25 OT_DTOR,26 24 OT_CALL, 27 25 OT_PREFIX, -
src/GenPoly/Box.cc
ra56767c r61f9356 10 10 // Created On : Mon May 18 07:44:20 2015 11 11 // Last Modified By : Rob Schluntz 12 // Last Modified On : Thu Jan 07 13:40:05 201613 // Update Count : 21 912 // Last Modified On : Fri Dec 18 14:53:08 2015 13 // Update Count : 217 14 14 // 15 15 … … 1139 1139 1140 1140 std::list<Expression*> designators; 1141 objectDecl->set_init( new SingleInit( alloc, designators , false ) ); // not constructed1141 objectDecl->set_init( new SingleInit( alloc, designators ) ); 1142 1142 } 1143 1143 } -
src/InitTweak/InitModel.cc
ra56767c r61f9356 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // InitModel.cc -- 7 // InitModel.cc -- 8 8 // 9 9 // Author : Rodolfo G. Esteves 10 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Rob Schluntz12 // Last Modified On : T hu Jan 07 13:38:46 201613 // Update Count : 511 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue May 19 16:37:08 2015 13 // Update Count : 1 14 14 // 15 15 … … 198 198 assert(init == 0 && single != 0); 199 199 std::list< Expression * > empty; 200 init = new SingleInit( single->get_expr(), empty , false ); // cannot be constructed200 init = new SingleInit( single->get_expr(), empty ); 201 201 return; 202 202 } … … 214 214 } // if 215 215 216 std::list< Expression * > desig; 217 init = new ListInit( contents, desig, false ); // cannot be constructed 216 init = new ListInit( contents ); 218 217 return; 219 218 } -
src/InitTweak/RemoveInit.cc
ra56767c r61f9356 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // RemoveInit.cc -- 7 // RemoveInit.cc -- 8 8 // 9 9 // Author : Rob Schluntz 10 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Rob Schluntz12 // Last Modified On : Mon Jan 11 14:41:26 201613 // Update Count : 1 1811 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue Dec 15 15:37:26 2015 13 // Update Count : 15 14 14 // 15 15 16 #include <stack>17 #include <list>18 16 #include "RemoveInit.h" 19 17 #include "SynTree/Declaration.h" … … 23 21 #include "SynTree/Initializer.h" 24 22 #include "SynTree/Mutator.h" 25 #include "GenPoly/PolyMutator.h"26 23 27 24 namespace InitTweak { … … 29 26 const std::list<Label> noLabels; 30 27 } 31 32 class RemoveInit : public GenPoly::PolyMutator {28 29 class RemoveInit : public Mutator { 33 30 public: 34 31 RemoveInit(); 35 virtual ObjectDecl * mutate( ObjectDecl *objDecl);32 virtual ObjectDecl * mutate(ObjectDecl *objDecl); 36 33 virtual DeclarationWithType * mutate( FunctionDecl *functionDecl ); 37 34 38 35 virtual Statement * mutate( ReturnStmt * returnStmt ); 36 37 virtual CompoundStmt * mutate(CompoundStmt * compoundStmt); 38 39 protected: 40 std::list< Statement* > stmtsToAddBefore; 41 std::list< Statement* > stmtsToAddAfter; 42 void mutateStatementList( std::list< Statement* > &statements ); 39 43 40 protected:41 44 std::list<DeclarationWithType*> returnVals; 42 45 UniqueName tempNamer; … … 44 47 }; 45 48 46 class CtorDtor : public GenPoly::PolyMutator {47 public:48 // CtorDtor();49 50 virtual ObjectDecl * mutate( ObjectDecl * );51 52 virtual CompoundStmt * mutate( CompoundStmt * compoundStmt );53 54 protected:55 typedef std::map< std::string, DeclarationWithType * > MMMMAP;56 std::stack< MMMMAP > constructedObjects;57 58 // to be added before block ends - use push_front so order is correct59 std::list< Statement * > destructorStmts;60 };61 62 49 void tweak( std::list< Declaration * > translationUnit ) { 63 50 RemoveInit remover; 64 CtorDtor ctordtor;65 51 mutateAll( translationUnit, remover ); 66 mutateAll( translationUnit, ctordtor );67 52 } 68 53 69 54 RemoveInit::RemoveInit() : tempNamer( "_retVal" ) {} 55 56 void RemoveInit::mutateStatementList( std::list< Statement* > &statements ) { 57 for ( std::list< Statement* >::iterator i = statements.begin(); i != statements.end(); ++i ) { 58 if ( ! stmtsToAddAfter.empty() ) { 59 statements.splice( i, stmtsToAddAfter ); 60 } // if 61 *i = (*i)->acceptMutator( *this ); 62 if ( ! stmtsToAddBefore.empty() ) { 63 statements.splice( i, stmtsToAddBefore ); 64 } // if 65 } // for 66 if ( ! stmtsToAddAfter.empty() ) { 67 statements.splice( statements.end(), stmtsToAddAfter ); 68 } // if 69 } 70 71 CompoundStmt *RemoveInit::mutate(CompoundStmt *compoundStmt) { 72 mutateStatementList( compoundStmt->get_kids() ); 73 return compoundStmt; 74 } 70 75 71 76 // in the case where an object has an initializer and a polymorphic type, insert an assignment immediately after the … … 90 95 if ( returnStmt->get_expr() && returnVals.size() == 1 && funcName != "?=?" && ! returnVals.front()->get_type()->get_isLvalue() ) { 91 96 ObjectDecl *newObj = new ObjectDecl( tempNamer.newName(), DeclarationNode::NoStorageClass, LinkageSpec::C, 0, returnVals.front()->get_type()->clone(), 0 ); 92 stmtsToAdd .push_back( new DeclStmt( noLabels, newObj ) );93 97 stmtsToAddBefore.push_back( new DeclStmt( noLabels, newObj ) ); 98 94 99 UntypedExpr *assign = new UntypedExpr( new NameExpr( "?=?" ) ); 95 100 assign->get_args().push_back( new AddressExpr (new NameExpr( newObj->get_name() ) ) ); 96 101 assign->get_args().push_back( returnStmt->get_expr() ); 97 stmtsToAdd .push_back(new ExprStmt(noLabels, assign));102 stmtsToAddBefore.push_back(new ExprStmt(noLabels, assign)); 98 103 99 104 returnStmt->set_expr( new VariableExpr( newObj ) ); … … 105 110 std::list<DeclarationWithType*> oldReturnVals = returnVals; 106 111 std::string oldFuncName = funcName; 107 112 108 113 FunctionType * type = functionDecl->get_functionType(); 109 114 returnVals = type->get_returnVals(); … … 114 119 return decl; 115 120 } 116 117 bool tryConstruct( ObjectDecl * objDecl ) {118 // xxx - handle designations119 return objDecl->get_init() == NULL ||120 ( objDecl->get_init() != NULL && objDecl->get_init()->get_maybeConstructed() );121 }122 123 ExprStmt * makeCtorDtorStmt( std::string name, ObjectDecl * objDecl, std::list< Expression * > args ) {124 UntypedExpr * expr = new UntypedExpr( new NameExpr( name ) );125 expr->get_args().push_back( new VariableExpr( objDecl ) );126 expr->get_args().splice( expr->get_args().end(), args );127 return new ExprStmt( noLabels, expr );128 }129 130 // InitExpander ctor/dtor being marked as weak symbols131 // this is causing a bug - Rodolfo's InitExpander is being constructed and destructed132 // with different fields, which causes a segfault133 134 class InitExpander : public Visitor {135 public:136 InitExpander() {}137 // ~InitExpander() {}138 virtual void visit( SingleInit * singleInit );139 virtual void visit( ListInit * listInit );140 std::list< Expression * > argList;141 };142 143 void InitExpander::visit( SingleInit * singleInit ) {144 argList.push_back( singleInit->get_value()->clone() );145 }146 147 void InitExpander::visit( ListInit * listInit ) {148 // xxx - for now, assume no nested list inits149 std::list<Initializer*>::iterator it = listInit->begin_initializers();150 for ( ; it != listInit->end_initializers(); ++it ) {151 (*it)->accept( *this );152 }153 }154 155 std::list< Expression * > makeInitList( Initializer * init ) {156 if ( init ) {157 InitExpander expander;158 // init->accept( expander );159 // std::list< Expression * > l = expander.argList;160 std::list< Expression * > l;161 return l;162 } else {163 std::list< Expression * > l;164 return l;165 }166 }167 168 ObjectDecl * CtorDtor::mutate( ObjectDecl * objDecl ) {169 // hands off if designated or if @=170 if ( tryConstruct( objDecl ) ) {171 ExprStmt * ctor = makeCtorDtorStmt( "?{}", objDecl, makeInitList( objDecl->get_init() ) );172 ExprStmt * dtor = makeCtorDtorStmt( "^?{}", objDecl, std::list< Expression * >() );173 174 // set_ctor...175 // need to remember init expression, in case no ctors exist176 // if ctor does exist, want to use ctor stmt instead of init177 objDecl->set_ctor( ctor );178 destructorStmts.push_front( dtor );179 }180 return objDecl;181 }182 183 CompoundStmt * CtorDtor::mutate( CompoundStmt * compoundStmt ) {184 CompoundStmt * ret = PolyMutator::mutate( compoundStmt );185 std::list< Statement * > &statements = ret->get_kids();186 if ( ! destructorStmts.empty() ) {187 statements.splice( statements.end(), destructorStmts );188 } // if189 return ret;190 }191 192 193 194 121 } // namespace InitTweak 195 122 -
src/MakeLibCfa.cc
ra56767c r61f9356 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // MakeLibCfa.cc -- 7 // MakeLibCfa.cc -- 8 8 // 9 9 // Author : Richard C. Bilson 10 10 // Created On : Sat May 16 10:33:33 2015 11 // Last Modified By : Rob Schluntz12 // Last Modified On : Thu Jan 07 13:34:39 201613 // Update Count : 2014 // 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Fri Jun 26 16:52:59 2015 13 // Update Count : 14 14 // 15 15 16 16 #include "MakeLibCfa.h" … … 29 29 void visit( FunctionDecl* funcDecl ); 30 30 void visit( ObjectDecl* objDecl ); 31 31 32 32 std::list< Declaration* > &get_newDecls() { return newDecls; } 33 33 private: … … 43 43 void MakeLibCfa::visit( FunctionDecl* origFuncDecl ) { 44 44 if ( origFuncDecl->get_linkage() != LinkageSpec::Intrinsic ) return; 45 45 46 46 FunctionDecl *funcDecl = origFuncDecl->clone(); 47 47 CodeGen::OperatorInfo opInfo; … … 77 77 break; 78 78 } 79 case CodeGen::OT_CTOR:80 case CodeGen::OT_DTOR:81 79 case CodeGen::OT_CONSTANT: 82 80 case CodeGen::OT_LABELADDRESS: … … 99 97 void MakeLibCfa::visit( ObjectDecl* origObjDecl ) { 100 98 if ( origObjDecl->get_linkage() != LinkageSpec::Intrinsic ) return; 101 99 102 100 ObjectDecl *objDecl = origObjDecl->clone(); 103 101 assert( ! objDecl->get_init() ); 104 102 std::list< Expression* > noDesignators; 105 objDecl->set_init( new SingleInit( new NameExpr( objDecl->get_name() ), noDesignators , false ) ); // cannot be constructed103 objDecl->set_init( new SingleInit( new NameExpr( objDecl->get_name() ), noDesignators ) ); 106 104 newDecls.push_back( objDecl ); 107 105 } -
src/Parser/DeclarationNode.cc
ra56767c r61f9356 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // DeclarationNode.cc -- 7 // DeclarationNode.cc -- 8 8 // 9 9 // Author : Rodolfo G. Esteves 10 10 // Created On : Sat May 16 12:34:05 2015 11 // Last Modified By : Rob Schluntz12 // Last Modified On : T hu Jan 07 13:18:02 201613 // Update Count : 1 3011 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue Jul 14 14:46:32 2015 13 // Update Count : 126 14 14 // 15 15 … … 96 96 os << endl << string( indent + 2, ' ' ) << "with initializer "; 97 97 initializer->printOneLine( os ); 98 os << " maybe constructed? " << initializer->get_maybeConstructed();99 100 98 } // if 101 99 … … 359 357 } // if 360 358 } 361 359 362 360 DeclarationNode *DeclarationNode::addQualifiers( DeclarationNode *q ) { 363 361 if ( q ) { … … 510 508 assert( false ); 511 509 } // switch 512 510 513 511 return this; 514 512 } … … 621 619 assert( a->type->kind == TypeData::Array ); 622 620 TypeData *lastArray = findLast( a->type ); 623 if ( type ) { 621 if ( type ) { 624 622 switch ( type->kind ) { 625 623 case TypeData::Aggregate: … … 665 663 } // if 666 664 } 667 665 668 666 DeclarationNode *DeclarationNode::addIdList( DeclarationNode *ids ) { 669 667 type = addIdListToType( type, ids ); … … 870 868 Type *DeclarationNode::buildType() const { 871 869 assert( type ); 872 870 873 871 switch ( type->kind ) { 874 872 case TypeData::Enum: -
src/Parser/InitializerNode.cc
ra56767c r61f9356 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // InitializerNode.cc -- 8 // 7 // InitializerNode.cc -- 8 // 9 9 // Author : Rodolfo G. Esteves 10 10 // Created On : Sat May 16 13:20:24 2015 11 // Last Modified By : Rob Schluntz12 // Last Modified On : Thu Jan 07 13:32:57 201613 // Update Count : 1314 // 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Thu Oct 8 17:18:55 2015 13 // Update Count : 4 14 // 15 15 16 16 #include <cassert> … … 23 23 24 24 InitializerNode::InitializerNode( ExpressionNode *_expr, bool aggrp, ExpressionNode *des ) 25 : expr( _expr ), aggregate( aggrp ), designator( des ), kids( 0 ) , maybeConstructed( true ){25 : expr( _expr ), aggregate( aggrp ), designator( des ), kids( 0 ) { 26 26 if ( aggrp ) 27 27 kids = dynamic_cast< InitializerNode *>( get_link() ); … … 32 32 33 33 InitializerNode::InitializerNode( InitializerNode *init, bool aggrp, ExpressionNode *des ) 34 : expr( 0 ), aggregate( aggrp ), designator( des ), kids( 0 ) , maybeConstructed( true ){34 : expr( 0 ), aggregate( aggrp ), designator( des ), kids( 0 ) { 35 35 if ( init != 0 ) 36 36 set_link(init); … … 91 91 } // if 92 92 93 return new ListInit( initlist, designlist , maybeConstructed);93 return new ListInit( initlist, designlist ); 94 94 } else { 95 95 std::list< Expression *> designators; … … 99 99 100 100 if ( get_expression() != 0) 101 return new SingleInit( get_expression()->build(), designators , maybeConstructed);101 return new SingleInit( get_expression()->build(), designators ); 102 102 } // if 103 103 -
src/Parser/ParseNode.h
ra56767c r61f9356 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // ParseNode.h -- 7 // ParseNode.h -- 8 8 // 9 9 // Author : Rodolfo G. Esteves 10 10 // Created On : Sat May 16 13:28:16 2015 11 11 // Last Modified By : Rob Schluntz 12 // Last Modified On : Thu Jan 07 13:17:46 201613 // Update Count : 17 712 // Last Modified On : Wed Aug 12 13:27:11 2015 13 // Update Count : 172 14 14 // 15 15 … … 175 175 public: 176 176 enum Type { TupleC, Comma, TupleFieldSel, 177 Cond, NCond, 178 SizeOf, AlignOf, Attr, CompLit, Plus, Minus, Mul, Div, Mod, Or, And, 179 BitOr, BitAnd, Xor, Cast, LShift, RShift, LThan, GThan, LEThan, GEThan, Eq, Neq, 180 Assign, MulAssn, DivAssn, ModAssn, PlusAssn, MinusAssn, LSAssn, RSAssn, AndAssn, 177 Cond, NCond, 178 SizeOf, AlignOf, Attr, CompLit, Plus, Minus, Mul, Div, Mod, Or, And, 179 BitOr, BitAnd, Xor, Cast, LShift, RShift, LThan, GThan, LEThan, GEThan, Eq, Neq, 180 Assign, MulAssn, DivAssn, ModAssn, PlusAssn, MinusAssn, LSAssn, RSAssn, AndAssn, 181 181 ERAssn, OrAssn, Index, FieldSel, PFieldSel, Range, 182 UnPlus, UnMinus, AddressOf, PointTo, Neg, BitNeg, Incr, IncrPost, Decr, DecrPost, LabelAddress, 183 Ctor, Dtor, 182 UnPlus, UnMinus, AddressOf, PointTo, Neg, BitNeg, Incr, IncrPost, Decr, DecrPost, LabelAddress 184 183 }; 185 184 … … 307 306 ValofExprNode( const ValofExprNode &other ); 308 307 ~ValofExprNode(); 309 308 310 309 virtual ValofExprNode *clone() const { return new ValofExprNode( *this ); } 311 310 … … 330 329 enum TypeClass { Type, Dtype, Ftype }; 331 330 332 static const char *storageName[]; 331 static const char *storageName[]; 333 332 static const char *qualifierName[]; 334 333 static const char *basicTypeName[]; … … 420 419 class StatementNode : public ParseNode { 421 420 public: 422 enum Type { Exp, If, Switch, Case, Default, Choose, Fallthru, 421 enum Type { Exp, If, Switch, Case, Default, Choose, Fallthru, 423 422 While, Do, For, 424 423 Goto, Continue, Break, Return, Throw, … … 518 517 ExpressionNode *get_designators() const { return designator; } 519 518 520 InitializerNode *set_maybeConstructed( bool value ) { maybeConstructed = value; return this; }521 bool get_maybeConstructed() const { return maybeConstructed; }522 523 519 InitializerNode *next_init() const { return kids; } 524 520 … … 532 528 ExpressionNode *designator; // may be list 533 529 InitializerNode *kids; 534 bool maybeConstructed;535 530 }; 536 531 -
src/Parser/parser.cc
ra56767c r61f9356 7291 7291 /* Line 1806 of yacc.c */ 7292 7292 #line 1684 "parser.yy" 7293 { (yyval.in) = (yyvsp[(2) - (2)].in) ->set_maybeConstructed( false ); }7293 { (yyval.in) = (yyvsp[(2) - (2)].in); } 7294 7294 break; 7295 7295 -
src/Parser/parser.yy
ra56767c r61f9356 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // cfa.y -- 8 // 7 // cfa.y -- 8 // 9 9 // Author : Peter A. Buhr 10 10 // Created On : Sat Sep 1 20:22:55 2001 … … 12 12 // Last Modified On : Thu Oct 8 17:17:54 2015 13 13 // Update Count : 1473 14 // 14 // 15 15 16 16 // This grammar is based on the ANSI99/11 C grammar, specifically parts of EXPRESSION and STATEMENTS, and on the C … … 1682 1682 { $$ = $2; } 1683 1683 | ATassign initializer 1684 { $$ = $2 ->set_maybeConstructed( false ); }1684 { $$ = $2; } 1685 1685 ; 1686 1686 -
src/SymTab/Validate.cc
ra56767c r61f9356 10 10 // Created On : Sun May 17 21:50:04 2015 11 11 // Last Modified By : Rob Schluntz 12 // Last Modified On : Thu Jan 07 11:27:49 201613 // Update Count : 2 6912 // Last Modified On : Fri Dec 18 15:34:05 2015 13 // Update Count : 218 14 14 // 15 15 … … 202 202 }; 203 203 204 class VerifyCtorDtor : public Visitor {205 public:206 /// ensure that constructors and destructors have at least one207 /// parameter, the first of which must be a pointer, and no208 /// return values.209 static void verify( std::list< Declaration * > &translationUnit );210 211 // VerifyCtorDtor() {}212 213 virtual void visit( FunctionDecl *funcDecl );214 private:215 };216 217 204 void validate( std::list< Declaration * > &translationUnit, bool doDebug ) { 218 205 Pass1 pass1; … … 226 213 AutogenerateRoutines::autogenerateRoutines( translationUnit ); 227 214 acceptAll( translationUnit, pass3 ); 228 VerifyCtorDtor::verify( translationUnit );229 215 } 230 216 … … 1043 1029 } 1044 1030 1045 void VerifyCtorDtor::verify( std::list< Declaration * > & translationUnit ) {1046 VerifyCtorDtor verifier;1047 acceptAll( translationUnit, verifier );1048 }1049 1050 void VerifyCtorDtor::visit( FunctionDecl * funcDecl ) {1051 FunctionType * funcType = funcDecl->get_functionType();1052 std::list< DeclarationWithType * > &returnVals = funcType->get_returnVals();1053 std::list< DeclarationWithType * > ¶ms = funcType->get_parameters();1054 1055 if ( funcDecl->get_name() == "?{}" || funcDecl->get_name() == "^?{}" ) {1056 if ( params.size() == 0 ) {1057 throw SemanticError( "Constructors and destructors require at least one parameter ", funcDecl );1058 }1059 if ( ! dynamic_cast< PointerType * >( params.front()->get_type() ) ) {1060 throw SemanticError( "First parameter of a constructor or destructor must be a pointer ", funcDecl );1061 }1062 if ( returnVals.size() != 0 ) {1063 throw SemanticError( "Constructors and destructors cannot have explicit return values ", funcDecl );1064 }1065 }1066 1067 Visitor::visit( funcDecl );1068 // original idea: modify signature of ctor/dtors and insert appropriate return statements1069 // to cause desired behaviour1070 // new idea: add comma exprs to every ctor call to produce first parameter.1071 // this requires some memoization of the first parameter, because it can be a1072 // complicated expression with side effects (see: malloc). idea: add temporary variable1073 // that is assigned address of constructed object in ctor argument position and1074 // return the temporary. It should also be done after all implicit ctors are1075 // added, so not in this pass!1076 }1077 1031 } // namespace SymTab 1078 1032 -
src/SynTree/Declaration.h
ra56767c r61f9356 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // Declaration.h -- 7 // Declaration.h -- 8 8 // 9 9 // Author : Richard C. Bilson 10 10 // Created On : Mon May 18 07:44:20 2015 11 11 // Last Modified By : Rob Schluntz 12 // Last Modified On : Thu Jan 07 14:48:44 201613 // Update Count : 3 412 // Last Modified On : Wed Dec 09 14:08:22 2015 13 // Update Count : 32 14 14 // 15 15 … … 91 91 Expression *get_bitfieldWidth() const { return bitfieldWidth; } 92 92 void set_bitfieldWidth( Expression *newValue ) { bitfieldWidth = newValue; } 93 ExprStmt * get_ctor() const { return ctor; }94 void set_ctor( ExprStmt * newValue ) { ctor = newValue; }95 93 96 94 virtual ObjectDecl *clone() const { return new ObjectDecl( *this ); } … … 103 101 Initializer *init; 104 102 Expression *bitfieldWidth; 105 ExprStmt * ctor;106 103 }; 107 104 -
src/SynTree/Initializer.cc
ra56767c r61f9356 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // Initializer.cc -- 7 // Initializer.cc -- 8 8 // 9 9 // Author : Richard C. Bilson 10 10 // Created On : Mon May 18 07:44:20 2015 11 11 // Last Modified By : Rob Schluntz 12 // Last Modified On : Thu Jan 07 15:00:18 201613 // Update Count : 2312 // Last Modified On : Wed Aug 12 14:05:25 2015 13 // Update Count : 14 14 14 // 15 15 … … 18 18 #include "utility.h" 19 19 20 Initializer::Initializer( bool maybeConstructed ) : maybeConstructed( maybeConstructed) {}20 Initializer::Initializer() {} 21 21 22 22 Initializer::~Initializer() {} … … 31 31 void Initializer::print( std::ostream &os, int indent ) {} 32 32 33 SingleInit::SingleInit( Expression *v, std::list< Expression *> &_designators , bool maybeConstructed ) : Initializer( maybeConstructed ), value ( v ), designators( _designators ) {33 SingleInit::SingleInit( Expression *v, std::list< Expression *> &_designators ) : value ( v ), designators( _designators ) { 34 34 } 35 35 36 SingleInit::SingleInit( const SingleInit &other ) : Initializer(other),value ( other.value ) {36 SingleInit::SingleInit( const SingleInit &other ) : value ( other.value ) { 37 37 cloneAll(other.designators, designators ); 38 38 } … … 54 54 } 55 55 56 ListInit::ListInit( std::list<Initializer*> &_initializers, std::list<Expression *> &_designators , bool maybeConstructed)57 : Initializer( maybeConstructed),initializers( _initializers ), designators( _designators ) {56 ListInit::ListInit( std::list<Initializer*> &_initializers, std::list<Expression *> &_designators ) 57 : initializers( _initializers ), designators( _designators ) { 58 58 } 59 59 … … 65 65 66 66 void ListInit::print( std::ostream &os, int indent ) { 67 os << std::endl << std::string(indent, ' ') << "Compound initializer: "; 67 os << std::endl << std::string(indent, ' ') << "Compound initializer: "; 68 68 if ( ! designators.empty() ) { 69 69 os << std::string(indent + 2, ' ' ) << "designated by: ["; 70 70 for ( std::list < Expression * >::iterator i = designators.begin(); 71 71 i != designators.end(); i++ ) { 72 ( *i )->print(os, indent + 4 ); 72 ( *i )->print(os, indent + 4 ); 73 73 } // for 74 74 75 75 os << std::string(indent + 2, ' ' ) << "]"; 76 76 } // if 77 77 78 for ( std::list<Initializer *>::iterator i = initializers.begin(); i != initializers.end(); i++ ) 78 for ( std::list<Initializer *>::iterator i = initializers.begin(); i != initializers.end(); i++ ) 79 79 (*i)->print( os, indent + 2 ); 80 80 } -
src/SynTree/Initializer.h
ra56767c r61f9356 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // Initializer.h -- 7 // Initializer.h -- 8 8 // 9 9 // Author : Richard C. Bilson 10 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Rob Schluntz12 // Last Modified On : Thu Jan 07 13:33:20 201613 // Update Count : 511 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon May 18 09:03:48 2015 13 // Update Count : 1 14 14 // 15 15 … … 27 27 public: 28 28 // Initializer( std::string _name = std::string(""), int _pos = 0 ); 29 Initializer( bool maybeConstructed);29 Initializer( ); 30 30 virtual ~Initializer(); 31 31 … … 43 43 } 44 44 45 bool get_maybeConstructed() { return maybeConstructed; }46 47 45 virtual Initializer *clone() const = 0; 48 46 virtual void accept( Visitor &v ) = 0; … … 52 50 // std::string name; 53 51 // int pos; 54 bool maybeConstructed;55 52 }; 56 53 … … 58 55 class SingleInit : public Initializer { 59 56 public: 60 SingleInit( Expression *value, std::list< Expression *> &designators , bool maybeConstructed);57 SingleInit( Expression *value, std::list< Expression *> &designators ); 61 58 SingleInit( const SingleInit &other ); 62 59 virtual ~SingleInit(); 63 60 64 61 Expression *get_value() { return value; } 65 62 void set_value( Expression *newValue ) { value = newValue; } … … 82 79 class ListInit : public Initializer { 83 80 public: 84 ListInit( std::list<Initializer*> &, 85 std::list<Expression *> &designators , bool maybeConstructed);81 ListInit( std::list<Initializer*> &, 82 std::list<Expression *> &designators = *(new std::list<Expression *>()) ); 86 83 virtual ~ListInit(); 87 84 -
src/SynTree/ObjectDecl.cc
ra56767c r61f9356 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // ObjectDecl.cc -- 7 // ObjectDecl.cc -- 8 8 // 9 9 // Author : Richard C. Bilson 10 10 // Created On : Mon May 18 07:44:20 2015 11 11 // Last Modified By : Rob Schluntz 12 // Last Modified On : Fri Jan 08 15:29:10 201613 // Update Count : 2712 // Last Modified On : Tue Sep 29 14:13:01 2015 13 // Update Count : 18 14 14 // 15 15 … … 19 19 #include "Expression.h" 20 20 #include "utility.h" 21 #include "Statement.h"22 21 23 22 ObjectDecl::ObjectDecl( const std::string &name, DeclarationNode::StorageClass sc, LinkageSpec::Type linkage, Expression *bitfieldWidth, Type *type, Initializer *init, bool isInline, bool isNoreturn ) … … 25 24 set_isInline( isInline ); 26 25 set_isNoreturn( isNoreturn ); 27 set_ctor( NULL );28 26 } 29 27 30 28 ObjectDecl::ObjectDecl( const ObjectDecl &other ) 31 : Parent( other ), type( maybeClone( other.type ) ), init( maybeClone( other.init ) ), bitfieldWidth( maybeClone( other.bitfieldWidth ) ) , ctor( maybeClone( other.ctor ) ){29 : Parent( other ), type( maybeClone( other.type ) ), init( maybeClone( other.init ) ), bitfieldWidth( maybeClone( other.bitfieldWidth ) ) { 32 30 } 33 31 … … 36 34 delete init; 37 35 delete bitfieldWidth; 38 delete ctor;39 36 } 40 37 … … 61 58 os << " with initializer "; 62 59 init->print( os, indent ); 63 os << std::string(indent, ' ') << "maybeConstructed? " << init->get_maybeConstructed();64 60 } // if 65 61 … … 68 64 bitfieldWidth->print( os ); 69 65 } // if 70 71 if ( ctor ) {72 os << " initially constructed with ";73 ctor->print( os, indent );74 } // if75 66 } 76 67 … … 78 69 #if 0 79 70 if ( get_mangleName() != "") { 80 os << get_mangleName() << ": "; 81 } else 71 os << get_mangleName() << ": "; 72 } else 82 73 #endif 83 74 if ( get_name() != "" ) { -
src/initialization.txt
ra56767c r61f9356 34 34 sure that resolved initializers for all declarations are being 35 35 generated. 36 37 38 ------39 40 More recent email: (I am quoted; Richard is the responder)41 > As far as I'm aware, the only way that I could currently get the correct42 > results from the unification engine is by feeding it an expression that43 > looks like "?=?( ((struct Y)x.y).a, 10 )", then picking out the pieces that44 > I need (namely the correct choice for a). Does this seem like a reasonable45 > approach to solve this problem?46 47 No, unfortunately. Initialization isn't being rewritten as assignment,48 so you shouldn't allow the particular selection of assignment49 operators that happen to be in scope (and which may include50 user-defined operators) to guide the type resolution.51 52 I don't think there is any way to rewrite an initializer as a single53 expression and have the resolver just do the right thing. I see the54 algorithm as:55 56 For each alternative interpretation of the designator:57 Construct an expression that casts the initializer to the type of58 the designator59 Construct an AlternativeFinder and use it to find the lowest cost60 interpretation of the expression61 Add this interpretation to a list of possibilities62 Go through the list of possibilities and pick the lowest cost63 64 As with many things in the resolver, it's conceptually simple but the65 implementation may be a bit of a pain. It fits in with functions like66 findSingleExpression, findIntegralExpression in Resolver.cc, although67 it will be significantly more complicated than any of the existing68 ones.69 70 71
Note:
See TracChangeset
for help on using the changeset viewer.