source: src/ResolvExpr/Resolver.cc@ bd098ea

ADT aaron-thesis arm-eh ast-experimental cleanup-dtors deferred_resn demangler enum forall-pointer-decay jacob/cs343-translation jenkins-sandbox new-ast new-ast-unique-expr new-env no_list persistent-indexer pthread-emulation qualifiedEnum resolv-new stuck-waitfor-destruct with_gc
Last change on this file since bd098ea was ea6332d, checked in by Thierry Delisle <tdelisle@…>, 8 years ago

Big header cleaning pass - commit 3

  • Property mode set to 100644
File size: 20.4 KB
RevLine 
[a32b204]1//
2// Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo
3//
4// The contents of this file are covered under the licence agreement in the
5// file "LICENCE" distributed with Cforall.
6//
[71f4e4f]7// Resolver.cc --
[a32b204]8//
9// Author : Richard C. Bilson
10// Created On : Sun May 17 12:17:01 2015
[cbce272]11// Last Modified By : Andrew Beach
12// Last Modified On : Tus Aug 8 16:06:00 2017
13// Update Count : 212
[a32b204]14//
15
[ea6332d]16#include <stddef.h> // for NULL
17#include <cassert> // for safe_dynamic_cast, assert
18#include <memory> // for allocator, allocator_traits<...
19#include <tuple> // for get
20
21#include "Alternative.h" // for Alternative, AltList
22#include "AlternativeFinder.h" // for AlternativeFinder, resolveIn...
23#include "Common/SemanticError.h" // for SemanticError
24#include "Common/utility.h" // for ValueGuard, group_iterate
25#include "CurrentObject.h" // for CurrentObject
26#include "InitTweak/InitTweak.h" // for isIntrinsicSingleArgCallStmt
27#include "RenameVars.h" // for RenameVars, global_renamer
28#include "ResolvExpr/TypeEnvironment.h" // for TypeEnvironment
29#include "ResolveTypeof.h" // for resolveTypeof
[e4d829b]30#include "Resolver.h"
[ea6332d]31#include "SymTab/Autogen.h" // for SizeType
32#include "SymTab/Indexer.h" // for Indexer
33#include "SynTree/Declaration.h" // for ObjectDecl, TypeDecl, Declar...
34#include "SynTree/Expression.h" // for Expression, CastExpr, InitExpr
35#include "SynTree/Initializer.h" // for ConstructorInit, SingleInit
36#include "SynTree/Statement.h" // for ForStmt, Statement, BranchStmt
37#include "SynTree/Type.h" // for Type, BasicType, PointerType
38#include "SynTree/TypeSubstitution.h" // for TypeSubstitution
39#include "SynTree/Visitor.h" // for acceptAll, maybeAccept
40#include "typeops.h" // for extractResultType
[51b73452]41
[d9a0e76]42using namespace std;
[51b73452]43
[d9a0e76]44namespace ResolvExpr {
[62e5546]45 class Resolver final : public SymTab::Indexer {
[a32b204]46 public:
[77971f6]47 Resolver() : SymTab::Indexer( false ) {}
[1d2b64f]48 Resolver( const SymTab:: Indexer & other ) : SymTab::Indexer( other ) {
49 if ( const Resolver * res = dynamic_cast< const Resolver * >( &other ) ) {
50 functionReturn = res->functionReturn;
[e4d829b]51 currentObject = res->currentObject;
[1d2b64f]52 inEnumDecl = res->inEnumDecl;
53 }
54 }
[71f4e4f]55
[1d2b64f]56 typedef SymTab::Indexer Parent;
57 using Parent::visit;
[62e5546]58 virtual void visit( FunctionDecl *functionDecl ) override;
59 virtual void visit( ObjectDecl *functionDecl ) override;
60 virtual void visit( TypeDecl *typeDecl ) override;
61 virtual void visit( EnumDecl * enumDecl ) override;
[94b4364]62
[62e5546]63 virtual void visit( ArrayType * at ) override;
64 virtual void visit( PointerType * at ) override;
[d9a0e76]65
[62e5546]66 virtual void visit( ExprStmt *exprStmt ) override;
67 virtual void visit( AsmExpr *asmExpr ) override;
68 virtual void visit( AsmStmt *asmStmt ) override;
69 virtual void visit( IfStmt *ifStmt ) override;
70 virtual void visit( WhileStmt *whileStmt ) override;
71 virtual void visit( ForStmt *forStmt ) override;
72 virtual void visit( SwitchStmt *switchStmt ) override;
73 virtual void visit( CaseStmt *caseStmt ) override;
74 virtual void visit( BranchStmt *branchStmt ) override;
75 virtual void visit( ReturnStmt *returnStmt ) override;
[307a732]76 virtual void visit( ThrowStmt *throwStmt ) override;
[cbce272]77 virtual void visit( CatchStmt *catchStmt ) override;
[d9a0e76]78
[62e5546]79 virtual void visit( SingleInit *singleInit ) override;
80 virtual void visit( ListInit *listInit ) override;
81 virtual void visit( ConstructorInit *ctorInit ) override;
[a32b204]82 private:
[94b4364]83 typedef std::list< Initializer * >::iterator InitIterator;
84
[40e636a]85 template< typename PtrType >
86 void handlePtrType( PtrType * type );
87
[30b65d8]88 void resolveAggrInit( ReferenceToType *, InitIterator &, InitIterator & );
89 void resolveSingleAggrInit( Declaration *, InitIterator &, InitIterator &, TypeSubstitution sub );
[f1e012b]90 void fallbackInit( ConstructorInit * ctorInit );
[b726084]91
[77971f6]92 Type * functionReturn = nullptr;
[e4d829b]93 CurrentObject currentObject = nullptr;
[a436947]94 bool inEnumDecl = false;
[a32b204]95 };
[d9a0e76]96
[a32b204]97 void resolve( std::list< Declaration * > translationUnit ) {
98 Resolver resolver;
99 acceptAll( translationUnit, resolver );
[d9a0e76]100 }
101
[a32b204]102 Expression *resolveInVoidContext( Expression *expr, const SymTab::Indexer &indexer ) {
103 TypeEnvironment env;
104 return resolveInVoidContext( expr, indexer, env );
[d9a0e76]105 }
[a32b204]106
[db4ecc5]107
[a32b204]108 namespace {
109 void finishExpr( Expression *expr, const TypeEnvironment &env ) {
110 expr->set_env( new TypeSubstitution );
111 env.makeSubstitution( *expr->get_env() );
112 }
[db4ecc5]113 } // namespace
[a32b204]114
[db4ecc5]115 Expression *findVoidExpression( Expression *untyped, const SymTab::Indexer &indexer ) {
116 global_renamer.reset();
117 TypeEnvironment env;
118 Expression *newExpr = resolveInVoidContext( untyped, indexer, env );
119 finishExpr( newExpr, env );
120 return newExpr;
121 }
[71f4e4f]122
[db4ecc5]123 namespace {
[a32b204]124 Expression *findSingleExpression( Expression *untyped, const SymTab::Indexer &indexer ) {
125 TypeEnvironment env;
126 AlternativeFinder finder( indexer, env );
127 finder.find( untyped );
[d9a0e76]128#if 0
[a32b204]129 if ( finder.get_alternatives().size() != 1 ) {
130 std::cout << "untyped expr is ";
131 untyped->print( std::cout );
132 std::cout << std::endl << "alternatives are:";
133 for ( std::list< Alternative >::const_iterator i = finder.get_alternatives().begin(); i != finder.get_alternatives().end(); ++i ) {
134 i->print( std::cout );
135 } // for
136 } // if
[d9a0e76]137#endif
[0b150ec]138 assertf( finder.get_alternatives().size() == 1, "findSingleExpression: must have exactly one alternative at the end." );
[a32b204]139 Alternative &choice = finder.get_alternatives().front();
140 Expression *newExpr = choice.expr->clone();
141 finishExpr( newExpr, choice.env );
142 return newExpr;
143 }
[d9a0e76]144
[a32b204]145 bool isIntegralType( Type *type ) {
146 if ( dynamic_cast< EnumInstType * >( type ) ) {
147 return true;
148 } else if ( BasicType *bt = dynamic_cast< BasicType * >( type ) ) {
149 return bt->isInteger();
[89e6ffc]150 } else if ( dynamic_cast< ZeroType* >( type ) != nullptr || dynamic_cast< OneType* >( type ) != nullptr ) {
151 return true;
[a32b204]152 } else {
153 return false;
154 } // if
155 }
[71f4e4f]156
[a32b204]157 Expression *findIntegralExpression( Expression *untyped, const SymTab::Indexer &indexer ) {
158 TypeEnvironment env;
159 AlternativeFinder finder( indexer, env );
160 finder.find( untyped );
[d9a0e76]161#if 0
[a32b204]162 if ( finder.get_alternatives().size() != 1 ) {
163 std::cout << "untyped expr is ";
164 untyped->print( std::cout );
165 std::cout << std::endl << "alternatives are:";
166 for ( std::list< Alternative >::const_iterator i = finder.get_alternatives().begin(); i != finder.get_alternatives().end(); ++i ) {
167 i->print( std::cout );
168 } // for
169 } // if
[d9a0e76]170#endif
[a32b204]171 Expression *newExpr = 0;
172 const TypeEnvironment *newEnv = 0;
173 for ( AltList::const_iterator i = finder.get_alternatives().begin(); i != finder.get_alternatives().end(); ++i ) {
[906e24d]174 if ( i->expr->get_result()->size() == 1 && isIntegralType( i->expr->get_result() ) ) {
[a32b204]175 if ( newExpr ) {
176 throw SemanticError( "Too many interpretations for case control expression", untyped );
177 } else {
178 newExpr = i->expr->clone();
179 newEnv = &i->env;
180 } // if
181 } // if
182 } // for
183 if ( ! newExpr ) {
184 throw SemanticError( "No interpretations for case control expression", untyped );
185 } // if
186 finishExpr( newExpr, *newEnv );
187 return newExpr;
188 }
[71f4e4f]189
[a32b204]190 }
[71f4e4f]191
[a32b204]192 void Resolver::visit( ObjectDecl *objectDecl ) {
193 Type *new_type = resolveTypeof( objectDecl->get_type(), *this );
194 objectDecl->set_type( new_type );
[3cfe27f]195 // To handle initialization of routine pointers, e.g., int (*fp)(int) = foo(), means that class-variable
196 // initContext is changed multiple time because the LHS is analysed twice. The second analysis changes
197 // initContext because of a function type can contain object declarations in the return and parameter types. So
198 // each value of initContext is retained, so the type on the first analysis is preserved and used for selecting
199 // the RHS.
[e4d829b]200 ValueGuard<CurrentObject> temp( currentObject );
201 currentObject = CurrentObject( objectDecl->get_type() );
202 if ( inEnumDecl && dynamic_cast< EnumInstType * >( objectDecl->get_type() ) ) {
[a436947]203 // enumerator initializers should not use the enum type to initialize, since
204 // the enum type is still incomplete at this point. Use signed int instead.
[e4d829b]205 currentObject = CurrentObject( new BasicType( Type::Qualifiers(), BasicType::SignedInt ) );
[a436947]206 }
[1d2b64f]207 Parent::visit( objectDecl );
[e4d829b]208 if ( inEnumDecl && dynamic_cast< EnumInstType * >( objectDecl->get_type() ) ) {
[a436947]209 // delete newly created signed int type
[e4d829b]210 // delete currentObject.getType();
[a436947]211 }
[bfbf97f]212 }
213
[40e636a]214 template< typename PtrType >
215 void Resolver::handlePtrType( PtrType * type ) {
216 if ( type->get_dimension() ) {
217 CastExpr *castExpr = new CastExpr( type->get_dimension(), SymTab::SizeType->clone() );
[bfbf97f]218 Expression *newExpr = findSingleExpression( castExpr, *this );
[40e636a]219 delete type->get_dimension();
220 type->set_dimension( newExpr );
[d1d17f5]221 }
[40e636a]222 }
223
224 void Resolver::visit( ArrayType * at ) {
225 handlePtrType( at );
[1d2b64f]226 Parent::visit( at );
[a32b204]227 }
[94b4364]228
[40e636a]229 void Resolver::visit( PointerType * pt ) {
230 handlePtrType( pt );
[1d2b64f]231 Parent::visit( pt );
[40e636a]232 }
233
[a32b204]234 void Resolver::visit( TypeDecl *typeDecl ) {
235 if ( typeDecl->get_base() ) {
236 Type *new_type = resolveTypeof( typeDecl->get_base(), *this );
237 typeDecl->set_base( new_type );
238 } // if
[1d2b64f]239 Parent::visit( typeDecl );
[a32b204]240 }
[94b4364]241
[a32b204]242 void Resolver::visit( FunctionDecl *functionDecl ) {
[d9a0e76]243#if 0
[a32b204]244 std::cout << "resolver visiting functiondecl ";
245 functionDecl->print( std::cout );
246 std::cout << std::endl;
[d9a0e76]247#endif
[a32b204]248 Type *new_type = resolveTypeof( functionDecl->get_type(), *this );
249 functionDecl->set_type( new_type );
[906e24d]250 ValueGuard< Type * > oldFunctionReturn( functionReturn );
251 functionReturn = ResolvExpr::extractResultType( functionDecl->get_functionType() );
[1d2b64f]252 Parent::visit( functionDecl );
[88d1066]253
254 // default value expressions have an environment which shouldn't be there and trips up later passes.
255 // xxx - it might be necessary to somehow keep the information from this environment, but I can't currently
256 // see how it's useful.
257 for ( Declaration * d : functionDecl->get_functionType()->get_parameters() ) {
258 if ( ObjectDecl * obj = dynamic_cast< ObjectDecl * >( d ) ) {
259 if ( SingleInit * init = dynamic_cast< SingleInit * >( obj->get_init() ) ) {
260 delete init->get_value()->get_env();
261 init->get_value()->set_env( nullptr );
262 }
263 }
264 }
[a32b204]265 }
[51b73452]266
[a436947]267 void Resolver::visit( EnumDecl * enumDecl ) {
268 // in case we decide to allow nested enums
[1d2b64f]269 ValueGuard< bool > oldInEnumDecl( inEnumDecl );
[a436947]270 inEnumDecl = true;
[1d2b64f]271 Parent::visit( enumDecl );
[a436947]272 }
273
[a32b204]274 void Resolver::visit( ExprStmt *exprStmt ) {
[1d2b64f]275 assertf( exprStmt->get_expr(), "ExprStmt has null Expression in resolver" );
276 Expression *newExpr = findVoidExpression( exprStmt->get_expr(), *this );
277 delete exprStmt->get_expr();
278 exprStmt->set_expr( newExpr );
[a32b204]279 }
[51b73452]280
[7f5566b]281 void Resolver::visit( AsmExpr *asmExpr ) {
282 Expression *newExpr = findVoidExpression( asmExpr->get_operand(), *this );
283 delete asmExpr->get_operand();
284 asmExpr->set_operand( newExpr );
285 if ( asmExpr->get_inout() ) {
286 newExpr = findVoidExpression( asmExpr->get_inout(), *this );
287 delete asmExpr->get_inout();
288 asmExpr->set_inout( newExpr );
289 } // if
290 }
291
292 void Resolver::visit( AsmStmt *asmStmt ) {
293 acceptAll( asmStmt->get_input(), *this);
294 acceptAll( asmStmt->get_output(), *this);
295 }
296
[a32b204]297 void Resolver::visit( IfStmt *ifStmt ) {
298 Expression *newExpr = findSingleExpression( ifStmt->get_condition(), *this );
299 delete ifStmt->get_condition();
300 ifStmt->set_condition( newExpr );
[1d2b64f]301 Parent::visit( ifStmt );
[a32b204]302 }
[51b73452]303
[a32b204]304 void Resolver::visit( WhileStmt *whileStmt ) {
305 Expression *newExpr = findSingleExpression( whileStmt->get_condition(), *this );
306 delete whileStmt->get_condition();
307 whileStmt->set_condition( newExpr );
[1d2b64f]308 Parent::visit( whileStmt );
[a32b204]309 }
[51b73452]310
[a32b204]311 void Resolver::visit( ForStmt *forStmt ) {
[1d2b64f]312 Parent::visit( forStmt );
[145f1fc]313
[a32b204]314 if ( forStmt->get_condition() ) {
[145f1fc]315 Expression * newExpr = findSingleExpression( forStmt->get_condition(), *this );
[a32b204]316 delete forStmt->get_condition();
317 forStmt->set_condition( newExpr );
318 } // if
[71f4e4f]319
[a32b204]320 if ( forStmt->get_increment() ) {
[145f1fc]321 Expression * newExpr = findVoidExpression( forStmt->get_increment(), *this );
[a32b204]322 delete forStmt->get_increment();
323 forStmt->set_increment( newExpr );
324 } // if
325 }
[51b73452]326
[32b8144]327 void Resolver::visit( SwitchStmt *switchStmt ) {
[e4d829b]328 ValueGuard< CurrentObject > oldCurrentObject( currentObject );
[a32b204]329 Expression *newExpr;
[32b8144]330 newExpr = findIntegralExpression( switchStmt->get_condition(), *this );
[a32b204]331 delete switchStmt->get_condition();
332 switchStmt->set_condition( newExpr );
[71f4e4f]333
[e4d829b]334 currentObject = CurrentObject( newExpr->get_result() );
[32b8144]335 Parent::visit( switchStmt );
[a32b204]336 }
[51b73452]337
[a32b204]338 void Resolver::visit( CaseStmt *caseStmt ) {
[32b8144]339 if ( caseStmt->get_condition() ) {
[e4d829b]340 std::list< InitAlternative > initAlts = currentObject.getOptions();
341 assertf( initAlts.size() == 1, "SwitchStmt did not correctly resolve an integral expression." );
342 CastExpr * castExpr = new CastExpr( caseStmt->get_condition(), initAlts.front().type->clone() );
[32b8144]343 Expression * newExpr = findSingleExpression( castExpr, *this );
344 castExpr = safe_dynamic_cast< CastExpr * >( newExpr );
345 caseStmt->set_condition( castExpr->get_arg() );
346 castExpr->set_arg( nullptr );
347 delete castExpr;
348 }
[1d2b64f]349 Parent::visit( caseStmt );
[a32b204]350 }
[51b73452]351
[de62360d]352 void Resolver::visit( BranchStmt *branchStmt ) {
353 // must resolve the argument for a computed goto
354 if ( branchStmt->get_type() == BranchStmt::Goto ) { // check for computed goto statement
[2871210]355 if ( Expression * arg = branchStmt->get_computedTarget() ) {
[de62360d]356 VoidType v = Type::Qualifiers(); // cast to void * for the alternative finder
357 PointerType pt( Type::Qualifiers(), v.clone() );
358 CastExpr * castExpr = new CastExpr( arg, pt.clone() );
359 Expression * newExpr = findSingleExpression( castExpr, *this ); // find best expression
360 branchStmt->set_target( newExpr );
361 } // if
362 } // if
363 }
364
[a32b204]365 void Resolver::visit( ReturnStmt *returnStmt ) {
366 if ( returnStmt->get_expr() ) {
[906e24d]367 CastExpr *castExpr = new CastExpr( returnStmt->get_expr(), functionReturn->clone() );
[a32b204]368 Expression *newExpr = findSingleExpression( castExpr, *this );
369 delete castExpr;
370 returnStmt->set_expr( newExpr );
371 } // if
372 }
[51b73452]373
[307a732]374 void Resolver::visit( ThrowStmt *throwStmt ) {
[cbce272]375 // TODO: Replace *exception type with &exception type.
[307a732]376 if ( throwStmt->get_expr() ) {
[cbce272]377 StructDecl * exception_decl =
378 lookupStruct( "__cfaehm__base_exception_t" );
379 assert( exception_decl );
380 Expression * wrapped = new CastExpr(
381 throwStmt->get_expr(),
382 new PointerType(
383 noQualifiers,
384 new StructInstType(
385 noQualifiers,
386 exception_decl
387 )
388 )
389 );
[307a732]390 Expression * newExpr = findSingleExpression( wrapped, *this );
391 throwStmt->set_expr( newExpr );
392 }
393 }
394
[cbce272]395 void Resolver::visit( CatchStmt *catchStmt ) {
[6a36975]396 Parent::visit( catchStmt );
397
[cbce272]398 if ( catchStmt->get_cond() ) {
399 Expression * wrapped = new CastExpr(
400 catchStmt->get_cond(),
401 new BasicType( noQualifiers, BasicType::Bool )
402 );
403 catchStmt->set_cond( findSingleExpression( wrapped, *this ) );
404 }
405 }
406
[b5c5684]407 template< typename T >
408 bool isCharType( T t ) {
409 if ( BasicType * bt = dynamic_cast< BasicType * >( t ) ) {
[71f4e4f]410 return bt->get_kind() == BasicType::Char || bt->get_kind() == BasicType::SignedChar ||
[b5c5684]411 bt->get_kind() == BasicType::UnsignedChar;
412 }
413 return false;
414 }
415
[e4d829b]416 void Resolver::visit( SingleInit *singleInit ) {
[62423350]417 // resolve initialization using the possibilities as determined by the currentObject cursor
[e4d829b]418 UntypedInitExpr * untyped = new UntypedInitExpr( singleInit->get_value(), currentObject.getOptions() );
419 Expression * newExpr = findSingleExpression( untyped, *this );
420 InitExpr * initExpr = safe_dynamic_cast< InitExpr * >( newExpr );
[62423350]421
422 // move cursor to the object that is actually initialized
[e4d829b]423 currentObject.setNext( initExpr->get_designation() );
[62423350]424
425 // discard InitExpr wrapper and retain relevant pieces
426 newExpr = initExpr->get_expr();
[435e75f]427 newExpr->set_env( initExpr->get_env() );
[62423350]428 initExpr->set_expr( nullptr );
429 initExpr->set_env( nullptr );
[e4d829b]430 delete initExpr;
431
[62423350]432 // get the actual object's type (may not exactly match what comes back from the resolver due to conversions)
433 Type * initContext = currentObject.getCurrentType();
434
435 // check if actual object's type is char[]
436 if ( ArrayType * at = dynamic_cast< ArrayType * >( initContext ) ) {
437 if ( isCharType( at->get_base() ) ) {
438 // check if the resolved type is char *
439 if ( PointerType * pt = dynamic_cast< PointerType *>( newExpr->get_result() ) ) {
440 if ( isCharType( pt->get_base() ) ) {
441 // strip cast if we're initializing a char[] with a char *, e.g. char x[] = "hello";
442 CastExpr *ce = safe_dynamic_cast< CastExpr * >( newExpr );
443 newExpr = ce->get_arg();
444 ce->set_arg( nullptr );
445 delete ce;
446 }
447 }
448 }
449 }
[94b4364]450
[62423350]451 // set initializer expr to resolved express
452 singleInit->set_value( newExpr );
453
454 // move cursor to next object in preparation for next initializer
455 currentObject.increment();
456 }
[94b4364]457
458 void Resolver::visit( ListInit * listInit ) {
[62423350]459 // move cursor into brace-enclosed initializer-list
[e4d829b]460 currentObject.enterListInit();
461 // xxx - fix this so that the list isn't copied, iterator should be used to change current element
462 std::list<Designation *> newDesignations;
463 for ( auto p : group_iterate(listInit->get_designations(), listInit->get_initializers()) ) {
[62423350]464 // iterate designations and initializers in pairs, moving the cursor to the current designated object and resolving
465 // the initializer against that object.
[e4d829b]466 Designation * des = std::get<0>(p);
467 Initializer * init = std::get<1>(p);
468 newDesignations.push_back( currentObject.findNext( des ) );
469 init->accept( *this );
[b5c5684]470 }
[62423350]471 // set the set of 'resolved' designations and leave the brace-enclosed initializer-list
[e4d829b]472 listInit->get_designations() = newDesignations; // xxx - memory management
473 currentObject.exitListInit();
474
[62423350]475 // xxx - this part has not be folded into CurrentObject yet
[e4d829b]476 // } else if ( TypeInstType * tt = dynamic_cast< TypeInstType * >( initContext ) ) {
477 // Type * base = tt->get_baseType()->get_base();
478 // if ( base ) {
479 // // know the implementation type, so try using that as the initContext
480 // ObjectDecl tmpObj( "", Type::StorageClasses(), LinkageSpec::Cforall, nullptr, base->clone(), nullptr );
481 // currentObject = &tmpObj;
482 // visit( listInit );
483 // } else {
484 // // missing implementation type -- might be an unknown type variable, so try proceeding with the current init context
485 // Parent::visit( listInit );
486 // }
487 // } else {
[a32b204]488 }
[71f4e4f]489
[f1e012b]490 // ConstructorInit - fall back on C-style initializer
491 void Resolver::fallbackInit( ConstructorInit * ctorInit ) {
492 // could not find valid constructor, or found an intrinsic constructor
493 // fall back on C-style initializer
494 delete ctorInit->get_ctor();
495 ctorInit->set_ctor( NULL );
[71a145de]496 delete ctorInit->get_dtor();
497 ctorInit->set_dtor( NULL );
[f1e012b]498 maybeAccept( ctorInit->get_init(), *this );
499 }
500
[1d2b64f]501 // needs to be callable from outside the resolver, so this is a standalone function
502 void resolveCtorInit( ConstructorInit * ctorInit, const SymTab::Indexer & indexer ) {
503 assert( ctorInit );
504 Resolver resolver( indexer );
505 ctorInit->accept( resolver );
506 }
507
508 void resolveStmtExpr( StmtExpr * stmtExpr, const SymTab::Indexer & indexer ) {
509 assert( stmtExpr );
510 Resolver resolver( indexer );
511 stmtExpr->accept( resolver );
512 }
513
[71f4e4f]514 void Resolver::visit( ConstructorInit *ctorInit ) {
[1ba88a0]515 // xxx - fallback init has been removed => remove fallbackInit function and remove complexity from FixInit and remove C-init from ConstructorInit
516 maybeAccept( ctorInit->get_ctor(), *this );
517 maybeAccept( ctorInit->get_dtor(), *this );
[071a31a]518
[5b2f5bb]519 // found a constructor - can get rid of C-style initializer
520 delete ctorInit->get_init();
521 ctorInit->set_init( NULL );
[ec79847]522
523 // intrinsic single parameter constructors and destructors do nothing. Since this was
524 // implicitly generated, there's no way for it to have side effects, so get rid of it
525 // to clean up generated code.
[f9cebb5]526 if ( InitTweak::isIntrinsicSingleArgCallStmt( ctorInit->get_ctor() ) ) {
[ec79847]527 delete ctorInit->get_ctor();
528 ctorInit->set_ctor( NULL );
529 }
[f9cebb5]530
531 if ( InitTweak::isIntrinsicSingleArgCallStmt( ctorInit->get_dtor() ) ) {
[ec79847]532 delete ctorInit->get_dtor();
533 ctorInit->set_dtor( NULL );
534 }
[a465caff]535
536 // xxx - todo -- what about arrays?
537 // if ( dtor == NULL && InitTweak::isIntrinsicCallStmt( ctorInit->get_ctor() ) ) {
538 // // can reduce the constructor down to a SingleInit using the
539 // // second argument from the ctor call, since
540 // delete ctorInit->get_ctor();
541 // ctorInit->set_ctor( NULL );
542
543 // Expression * arg =
544 // ctorInit->set_init( new SingleInit( arg ) );
545 // }
[71f4e4f]546 }
[51b73452]547} // namespace ResolvExpr
[a32b204]548
549// Local Variables: //
550// tab-width: 4 //
551// mode: c++ //
552// compile-command: "make install" //
553// End: //
Note: See TracBrowser for help on using the repository browser.