Changes in / [61f9356:a56767c]
- Location:
- src
- Files:
-
- 2 deleted
- 18 edited
Legend:
- Unmodified
- Added
- Removed
-
src/CodeGen/CodeGenerator.cc
r61f9356 ra56767c 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 4:08 201513 // Update Count : 23 112 // Last Modified On : Thu Sep 17 15:25:58 2015 13 // Update Count : 233 14 14 // 15 15 … … 258 258 259 259 case OT_CALL: 260 // there are no intrinsic definitions of the function call operator 260 case OT_CTOR: 261 case OT_DTOR: 262 // there are no intrinsic definitions of the function call operator or constructors or destructors 261 263 assert( false ); 262 264 break; … … 322 324 323 325 case OT_CALL: 326 case OT_CTOR: 327 case OT_DTOR: 324 328 assert( false ); 325 329 break; -
src/CodeGen/OperatorTable.cc
r61f9356 ra56767c 9 9 // Author : Richard C. Bilson 10 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Peter A. Buhr12 // Last Modified On : Tue Jun 23 17:41:14 201513 // Update Count : 511 // Last Modified By : Rob Schluntz 12 // Last Modified On : Tue Oct 06 15:26:34 2015 13 // Update Count : 9 14 14 // 15 15 … … 21 21 const OperatorInfo tableValues[] = { 22 22 { "?[?]", "", "_operator_index", OT_INDEX }, 23 { "?{}", "", "_constructor", OT_CTOR }, 24 { "^?{}", "", "_destructor", OT_DTOR }, // ~?{}, -?{}, !?{}, $?{}, ??{}, ^?{}, ?destroy, ?delete 23 25 { "?()", "", "_operator_call", OT_CALL }, 24 26 { "?++", "++", "_operator_postincr", OT_POSTFIXASSIGN }, -
src/CodeGen/OperatorTable.h
r61f9356 ra56767c 9 9 // Author : Richard C. Bilson 10 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Peter A. Buhr12 // Last Modified On : Tue Jun 23 16:09:27 201513 // Update Count : 311 // Last Modified By : Rob Schluntz 12 // Last Modified On : Wed Jun 24 16:17:57 2015 13 // Update Count : 5 14 14 // 15 15 … … 22 22 enum OperatorType { 23 23 OT_INDEX, 24 OT_CTOR, 25 OT_DTOR, 24 26 OT_CALL, 25 27 OT_PREFIX, -
src/GenPoly/Box.cc
r61f9356 ra56767c 10 10 // Created On : Mon May 18 07:44:20 2015 11 11 // Last Modified By : Rob Schluntz 12 // Last Modified On : Fri Dec 18 14:53:08 201513 // Update Count : 21 712 // Last Modified On : Thu Jan 07 13:40:05 2016 13 // Update Count : 219 14 14 // 15 15 … … 1139 1139 1140 1140 std::list<Expression*> designators; 1141 objectDecl->set_init( new SingleInit( alloc, designators ) );1141 objectDecl->set_init( new SingleInit( alloc, designators, false ) ); // not constructed 1142 1142 } 1143 1143 } -
src/InitTweak/InitModel.cc
r61f9356 ra56767c 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 : Peter A. Buhr12 // Last Modified On : T ue May 19 16:37:08 201513 // Update Count : 111 // Last Modified By : Rob Schluntz 12 // Last Modified On : Thu Jan 07 13:38:46 2016 13 // Update Count : 5 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 );200 init = new SingleInit( single->get_expr(), empty, false ); // cannot be constructed 201 201 return; 202 202 } … … 214 214 } // if 215 215 216 init = new ListInit( contents ); 216 std::list< Expression * > desig; 217 init = new ListInit( contents, desig, false ); // cannot be constructed 217 218 return; 218 219 } -
src/InitTweak/RemoveInit.cc
r61f9356 ra56767c 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 : Peter A. Buhr 12 // Last Modified On : Tue Dec 15 15:37:26 2015 13 // Update Count : 15 14 // 15 11 // Last Modified By : Rob Schluntz 12 // Last Modified On : Mon Jan 11 14:41:26 2016 13 // Update Count : 118 14 // 15 16 #include <stack> 17 #include <list> 16 18 #include "RemoveInit.h" 17 19 #include "SynTree/Declaration.h" … … 21 23 #include "SynTree/Initializer.h" 22 24 #include "SynTree/Mutator.h" 25 #include "GenPoly/PolyMutator.h" 23 26 24 27 namespace InitTweak { … … 26 29 const std::list<Label> noLabels; 27 30 } 28 29 class RemoveInit : public Mutator {31 32 class RemoveInit : public GenPoly::PolyMutator { 30 33 public: 31 34 RemoveInit(); 32 virtual ObjectDecl * mutate( ObjectDecl *objDecl);35 virtual ObjectDecl * mutate( ObjectDecl *objDecl ); 33 36 virtual DeclarationWithType * mutate( FunctionDecl *functionDecl ); 34 37 35 38 virtual Statement * mutate( ReturnStmt * returnStmt ); 36 37 virtual CompoundStmt * mutate(CompoundStmt * compoundStmt); 38 39 39 40 protected: 40 std::list< Statement* > stmtsToAddBefore;41 std::list< Statement* > stmtsToAddAfter;42 void mutateStatementList( std::list< Statement* > &statements );43 44 41 std::list<DeclarationWithType*> returnVals; 45 42 UniqueName tempNamer; … … 47 44 }; 48 45 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 correct 59 std::list< Statement * > destructorStmts; 60 }; 61 49 62 void tweak( std::list< Declaration * > translationUnit ) { 50 63 RemoveInit remover; 64 CtorDtor ctordtor; 51 65 mutateAll( translationUnit, remover ); 66 mutateAll( translationUnit, ctordtor ); 52 67 } 53 68 54 69 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 } // if61 *i = (*i)->acceptMutator( *this );62 if ( ! stmtsToAddBefore.empty() ) {63 statements.splice( i, stmtsToAddBefore );64 } // if65 } // for66 if ( ! stmtsToAddAfter.empty() ) {67 statements.splice( statements.end(), stmtsToAddAfter );68 } // if69 }70 71 CompoundStmt *RemoveInit::mutate(CompoundStmt *compoundStmt) {72 mutateStatementList( compoundStmt->get_kids() );73 return compoundStmt;74 }75 70 76 71 // in the case where an object has an initializer and a polymorphic type, insert an assignment immediately after the … … 95 90 if ( returnStmt->get_expr() && returnVals.size() == 1 && funcName != "?=?" && ! returnVals.front()->get_type()->get_isLvalue() ) { 96 91 ObjectDecl *newObj = new ObjectDecl( tempNamer.newName(), DeclarationNode::NoStorageClass, LinkageSpec::C, 0, returnVals.front()->get_type()->clone(), 0 ); 97 stmtsToAdd Before.push_back( new DeclStmt( noLabels, newObj ) );98 92 stmtsToAdd.push_back( new DeclStmt( noLabels, newObj ) ); 93 99 94 UntypedExpr *assign = new UntypedExpr( new NameExpr( "?=?" ) ); 100 95 assign->get_args().push_back( new AddressExpr (new NameExpr( newObj->get_name() ) ) ); 101 96 assign->get_args().push_back( returnStmt->get_expr() ); 102 stmtsToAdd Before.push_back(new ExprStmt(noLabels, assign));97 stmtsToAdd.push_back(new ExprStmt(noLabels, assign)); 103 98 104 99 returnStmt->set_expr( new VariableExpr( newObj ) ); … … 110 105 std::list<DeclarationWithType*> oldReturnVals = returnVals; 111 106 std::string oldFuncName = funcName; 112 107 113 108 FunctionType * type = functionDecl->get_functionType(); 114 109 returnVals = type->get_returnVals(); … … 119 114 return decl; 120 115 } 116 117 bool tryConstruct( ObjectDecl * objDecl ) { 118 // xxx - handle designations 119 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 symbols 131 // this is causing a bug - Rodolfo's InitExpander is being constructed and destructed 132 // with different fields, which causes a segfault 133 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 inits 149 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 exist 176 // if ctor does exist, want to use ctor stmt instead of init 177 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 } // if 189 return ret; 190 } 191 192 193 121 194 } // namespace InitTweak 122 195 -
src/MakeLibCfa.cc
r61f9356 ra56767c 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 : Peter A. Buhr12 // Last Modified On : Fri Jun 26 16:52:59 201513 // Update Count : 1414 // 11 // Last Modified By : Rob Schluntz 12 // Last Modified On : Thu Jan 07 13:34:39 2016 13 // Update Count : 20 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: 79 81 case CodeGen::OT_CONSTANT: 80 82 case CodeGen::OT_LABELADDRESS: … … 97 99 void MakeLibCfa::visit( ObjectDecl* origObjDecl ) { 98 100 if ( origObjDecl->get_linkage() != LinkageSpec::Intrinsic ) return; 99 101 100 102 ObjectDecl *objDecl = origObjDecl->clone(); 101 103 assert( ! objDecl->get_init() ); 102 104 std::list< Expression* > noDesignators; 103 objDecl->set_init( new SingleInit( new NameExpr( objDecl->get_name() ), noDesignators ) );105 objDecl->set_init( new SingleInit( new NameExpr( objDecl->get_name() ), noDesignators, false ) ); // cannot be constructed 104 106 newDecls.push_back( objDecl ); 105 107 } -
src/Parser/DeclarationNode.cc
r61f9356 ra56767c 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 : Peter A. Buhr12 // Last Modified On : T ue Jul 14 14:46:32 201513 // Update Count : 1 2611 // Last Modified By : Rob Schluntz 12 // Last Modified On : Thu Jan 07 13:18:02 2016 13 // Update Count : 130 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 98 100 } // if 99 101 … … 357 359 } // if 358 360 } 359 361 360 362 DeclarationNode *DeclarationNode::addQualifiers( DeclarationNode *q ) { 361 363 if ( q ) { … … 508 510 assert( false ); 509 511 } // switch 510 512 511 513 return this; 512 514 } … … 619 621 assert( a->type->kind == TypeData::Array ); 620 622 TypeData *lastArray = findLast( a->type ); 621 if ( type ) { 623 if ( type ) { 622 624 switch ( type->kind ) { 623 625 case TypeData::Aggregate: … … 663 665 } // if 664 666 } 665 667 666 668 DeclarationNode *DeclarationNode::addIdList( DeclarationNode *ids ) { 667 669 type = addIdListToType( type, ids ); … … 868 870 Type *DeclarationNode::buildType() const { 869 871 assert( type ); 870 872 871 873 switch ( type->kind ) { 872 874 case TypeData::Enum: -
src/Parser/InitializerNode.cc
r61f9356 ra56767c 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 : Peter A. Buhr12 // Last Modified On : Thu Oct 8 17:18:55 201513 // Update Count : 414 // 11 // Last Modified By : Rob Schluntz 12 // Last Modified On : Thu Jan 07 13:32:57 2016 13 // Update Count : 13 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 ) {25 : expr( _expr ), aggregate( aggrp ), designator( des ), kids( 0 ), maybeConstructed( true ) { 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 ) {34 : expr( 0 ), aggregate( aggrp ), designator( des ), kids( 0 ), maybeConstructed( true ) { 35 35 if ( init != 0 ) 36 36 set_link(init); … … 91 91 } // if 92 92 93 return new ListInit( initlist, designlist );93 return new ListInit( initlist, designlist, maybeConstructed ); 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 );101 return new SingleInit( get_expression()->build(), designators, maybeConstructed ); 102 102 } // if 103 103 -
src/Parser/ParseNode.h
r61f9356 ra56767c 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 : Wed Aug 12 13:27:11 201513 // Update Count : 17 212 // Last Modified On : Thu Jan 07 13:17:46 2016 13 // Update Count : 177 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 182 UnPlus, UnMinus, AddressOf, PointTo, Neg, BitNeg, Incr, IncrPost, Decr, DecrPost, LabelAddress, 183 Ctor, Dtor, 183 184 }; 184 185 … … 306 307 ValofExprNode( const ValofExprNode &other ); 307 308 ~ValofExprNode(); 308 309 309 310 virtual ValofExprNode *clone() const { return new ValofExprNode( *this ); } 310 311 … … 329 330 enum TypeClass { Type, Dtype, Ftype }; 330 331 331 static const char *storageName[]; 332 static const char *storageName[]; 332 333 static const char *qualifierName[]; 333 334 static const char *basicTypeName[]; … … 419 420 class StatementNode : public ParseNode { 420 421 public: 421 enum Type { Exp, If, Switch, Case, Default, Choose, Fallthru, 422 enum Type { Exp, If, Switch, Case, Default, Choose, Fallthru, 422 423 While, Do, For, 423 424 Goto, Continue, Break, Return, Throw, … … 517 518 ExpressionNode *get_designators() const { return designator; } 518 519 520 InitializerNode *set_maybeConstructed( bool value ) { maybeConstructed = value; return this; } 521 bool get_maybeConstructed() const { return maybeConstructed; } 522 519 523 InitializerNode *next_init() const { return kids; } 520 524 … … 528 532 ExpressionNode *designator; // may be list 529 533 InitializerNode *kids; 534 bool maybeConstructed; 530 535 }; 531 536 -
src/Parser/parser.cc
r61f9356 ra56767c 7291 7291 /* Line 1806 of yacc.c */ 7292 7292 #line 1684 "parser.yy" 7293 { (yyval.in) = (yyvsp[(2) - (2)].in) ; }7293 { (yyval.in) = (yyvsp[(2) - (2)].in)->set_maybeConstructed( false ); } 7294 7294 break; 7295 7295 -
src/Parser/parser.yy
r61f9356 ra56767c 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 ; }1684 { $$ = $2->set_maybeConstructed( false ); } 1685 1685 ; 1686 1686 -
src/SymTab/Validate.cc
r61f9356 ra56767c 10 10 // Created On : Sun May 17 21:50:04 2015 11 11 // Last Modified By : Rob Schluntz 12 // Last Modified On : Fri Dec 18 15:34:05 201513 // Update Count : 2 1812 // Last Modified On : Thu Jan 07 11:27:49 2016 13 // Update Count : 269 14 14 // 15 15 … … 202 202 }; 203 203 204 class VerifyCtorDtor : public Visitor { 205 public: 206 /// ensure that constructors and destructors have at least one 207 /// parameter, the first of which must be a pointer, and no 208 /// return values. 209 static void verify( std::list< Declaration * > &translationUnit ); 210 211 // VerifyCtorDtor() {} 212 213 virtual void visit( FunctionDecl *funcDecl ); 214 private: 215 }; 216 204 217 void validate( std::list< Declaration * > &translationUnit, bool doDebug ) { 205 218 Pass1 pass1; … … 213 226 AutogenerateRoutines::autogenerateRoutines( translationUnit ); 214 227 acceptAll( translationUnit, pass3 ); 228 VerifyCtorDtor::verify( translationUnit ); 215 229 } 216 230 … … 1029 1043 } 1030 1044 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 statements 1069 // to cause desired behaviour 1070 // 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 a 1072 // complicated expression with side effects (see: malloc). idea: add temporary variable 1073 // that is assigned address of constructed object in ctor argument position and 1074 // return the temporary. It should also be done after all implicit ctors are 1075 // added, so not in this pass! 1076 } 1031 1077 } // namespace SymTab 1032 1078 -
src/SynTree/Declaration.h
r61f9356 ra56767c 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 : Wed Dec 09 14:08:22 201513 // Update Count : 3 212 // Last Modified On : Thu Jan 07 14:48:44 2016 13 // Update Count : 34 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; } 93 95 94 96 virtual ObjectDecl *clone() const { return new ObjectDecl( *this ); } … … 101 103 Initializer *init; 102 104 Expression *bitfieldWidth; 105 ExprStmt * ctor; 103 106 }; 104 107 -
src/SynTree/Initializer.cc
r61f9356 ra56767c 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 : Wed Aug 12 14:05:25 201513 // Update Count : 1412 // Last Modified On : Thu Jan 07 15:00:18 2016 13 // Update Count : 23 14 14 // 15 15 … … 18 18 #include "utility.h" 19 19 20 Initializer::Initializer( ) {}20 Initializer::Initializer( bool maybeConstructed ) : maybeConstructed( maybeConstructed ) {} 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 ) : value ( v ), designators( _designators ) {33 SingleInit::SingleInit( Expression *v, std::list< Expression *> &_designators, bool maybeConstructed ) : Initializer( maybeConstructed ), value ( v ), designators( _designators ) { 34 34 } 35 35 36 SingleInit::SingleInit( const SingleInit &other ) : value ( other.value ) {36 SingleInit::SingleInit( const SingleInit &other ) : Initializer(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 )57 : initializers( _initializers ), designators( _designators ) {56 ListInit::ListInit( std::list<Initializer*> &_initializers, std::list<Expression *> &_designators, bool maybeConstructed ) 57 : Initializer( maybeConstructed), 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
r61f9356 ra56767c 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 : Peter A. Buhr12 // Last Modified On : Mon May 18 09:03:48 201513 // Update Count : 111 // Last Modified By : Rob Schluntz 12 // Last Modified On : Thu Jan 07 13:33:20 2016 13 // Update Count : 5 14 14 // 15 15 … … 27 27 public: 28 28 // Initializer( std::string _name = std::string(""), int _pos = 0 ); 29 Initializer( );29 Initializer( bool maybeConstructed ); 30 30 virtual ~Initializer(); 31 31 … … 43 43 } 44 44 45 bool get_maybeConstructed() { return maybeConstructed; } 46 45 47 virtual Initializer *clone() const = 0; 46 48 virtual void accept( Visitor &v ) = 0; … … 50 52 // std::string name; 51 53 // int pos; 54 bool maybeConstructed; 52 55 }; 53 56 … … 55 58 class SingleInit : public Initializer { 56 59 public: 57 SingleInit( Expression *value, std::list< Expression *> &designators );60 SingleInit( Expression *value, std::list< Expression *> &designators, bool maybeConstructed ); 58 61 SingleInit( const SingleInit &other ); 59 62 virtual ~SingleInit(); 60 63 61 64 Expression *get_value() { return value; } 62 65 void set_value( Expression *newValue ) { value = newValue; } … … 79 82 class ListInit : public Initializer { 80 83 public: 81 ListInit( std::list<Initializer*> &, 82 std::list<Expression *> &designators = *(new std::list<Expression *>()));84 ListInit( std::list<Initializer*> &, 85 std::list<Expression *> &designators, bool maybeConstructed ); 83 86 virtual ~ListInit(); 84 87 -
src/SynTree/ObjectDecl.cc
r61f9356 ra56767c 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 : Tue Sep 29 14:13:01 201513 // Update Count : 1812 // Last Modified On : Fri Jan 08 15:29:10 2016 13 // Update Count : 27 14 14 // 15 15 … … 19 19 #include "Expression.h" 20 20 #include "utility.h" 21 #include "Statement.h" 21 22 22 23 ObjectDecl::ObjectDecl( const std::string &name, DeclarationNode::StorageClass sc, LinkageSpec::Type linkage, Expression *bitfieldWidth, Type *type, Initializer *init, bool isInline, bool isNoreturn ) … … 24 25 set_isInline( isInline ); 25 26 set_isNoreturn( isNoreturn ); 27 set_ctor( NULL ); 26 28 } 27 29 28 30 ObjectDecl::ObjectDecl( const ObjectDecl &other ) 29 : Parent( other ), type( maybeClone( other.type ) ), init( maybeClone( other.init ) ), bitfieldWidth( maybeClone( other.bitfieldWidth ) ) {31 : Parent( other ), type( maybeClone( other.type ) ), init( maybeClone( other.init ) ), bitfieldWidth( maybeClone( other.bitfieldWidth ) ), ctor( maybeClone( other.ctor ) ) { 30 32 } 31 33 … … 34 36 delete init; 35 37 delete bitfieldWidth; 38 delete ctor; 36 39 } 37 40 … … 58 61 os << " with initializer "; 59 62 init->print( os, indent ); 63 os << std::string(indent, ' ') << "maybeConstructed? " << init->get_maybeConstructed(); 60 64 } // if 61 65 … … 64 68 bitfieldWidth->print( os ); 65 69 } // if 70 71 if ( ctor ) { 72 os << " initially constructed with "; 73 ctor->print( os, indent ); 74 } // if 66 75 } 67 76 … … 69 78 #if 0 70 79 if ( get_mangleName() != "") { 71 os << get_mangleName() << ": "; 72 } else 80 os << get_mangleName() << ": "; 81 } else 73 82 #endif 74 83 if ( get_name() != "" ) { -
src/initialization.txt
r61f9356 ra56767c 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 correct 42 > results from the unification engine is by feeding it an expression that 43 > looks like "?=?( ((struct Y)x.y).a, 10 )", then picking out the pieces that 44 > I need (namely the correct choice for a). Does this seem like a reasonable 45 > 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 assignment 49 operators that happen to be in scope (and which may include 50 user-defined operators) to guide the type resolution. 51 52 I don't think there is any way to rewrite an initializer as a single 53 expression and have the resolver just do the right thing. I see the 54 algorithm as: 55 56 For each alternative interpretation of the designator: 57 Construct an expression that casts the initializer to the type of 58 the designator 59 Construct an AlternativeFinder and use it to find the lowest cost 60 interpretation of the expression 61 Add this interpretation to a list of possibilities 62 Go through the list of possibilities and pick the lowest cost 63 64 As with many things in the resolver, it's conceptually simple but the 65 implementation may be a bit of a pain. It fits in with functions like 66 findSingleExpression, findIntegralExpression in Resolver.cc, although 67 it will be significantly more complicated than any of the existing 68 ones. 69 70 71
Note: See TracChangeset
for help on using the changeset viewer.