source: src/ResolvExpr/Resolver.cc@ ee897e4b

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 with_gc
Last change on this file since ee897e4b was eeaea53, checked in by Thierry Delisle <tdelisle@…>, 9 years ago

Removed undefined behavior when anonymous unions have no member

  • Property mode set to 100644
File size: 21.6 KB
Line 
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//
7// Resolver.cc --
8//
9// Author : Richard C. Bilson
10// Created On : Sun May 17 12:17:01 2015
11// Last Modified By : Peter A. Buhr
12// Last Modified On : Tue Jul 12 17:45:42 2016
13// Update Count : 204
14//
15
16#include "Resolver.h"
17#include "AlternativeFinder.h"
18#include "Alternative.h"
19#include "RenameVars.h"
20#include "ResolveTypeof.h"
21#include "typeops.h"
22#include "SynTree/Statement.h"
23#include "SynTree/Type.h"
24#include "SynTree/Expression.h"
25#include "SynTree/Initializer.h"
26#include "SymTab/Indexer.h"
27#include "SymTab/Autogen.h"
28#include "Common/utility.h"
29#include "InitTweak/InitTweak.h"
30
31#include <iostream>
32using namespace std;
33
34namespace ResolvExpr {
35 class Resolver final : public SymTab::Indexer {
36 public:
37 Resolver() : SymTab::Indexer( false ) {}
38 Resolver( const SymTab:: Indexer & other ) : SymTab::Indexer( other ) {
39 if ( const Resolver * res = dynamic_cast< const Resolver * >( &other ) ) {
40 functionReturn = res->functionReturn;
41 initContext = res->initContext;
42 inEnumDecl = res->inEnumDecl;
43 }
44 }
45
46 typedef SymTab::Indexer Parent;
47 using Parent::visit;
48 virtual void visit( FunctionDecl *functionDecl ) override;
49 virtual void visit( ObjectDecl *functionDecl ) override;
50 virtual void visit( TypeDecl *typeDecl ) override;
51 virtual void visit( EnumDecl * enumDecl ) override;
52
53 virtual void visit( ArrayType * at ) override;
54 virtual void visit( PointerType * at ) override;
55
56 virtual void visit( ExprStmt *exprStmt ) override;
57 virtual void visit( AsmExpr *asmExpr ) override;
58 virtual void visit( AsmStmt *asmStmt ) override;
59 virtual void visit( IfStmt *ifStmt ) override;
60 virtual void visit( WhileStmt *whileStmt ) override;
61 virtual void visit( ForStmt *forStmt ) override;
62 virtual void visit( SwitchStmt *switchStmt ) override;
63 virtual void visit( CaseStmt *caseStmt ) override;
64 virtual void visit( BranchStmt *branchStmt ) override;
65 virtual void visit( ReturnStmt *returnStmt ) override;
66
67 virtual void visit( SingleInit *singleInit ) override;
68 virtual void visit( ListInit *listInit ) override;
69 virtual void visit( ConstructorInit *ctorInit ) override;
70 private:
71 typedef std::list< Initializer * >::iterator InitIterator;
72
73 template< typename PtrType >
74 void handlePtrType( PtrType * type );
75
76 void resolveAggrInit( ReferenceToType *, InitIterator &, InitIterator & );
77 void resolveSingleAggrInit( Declaration *, InitIterator &, InitIterator &, TypeSubstitution sub );
78 void fallbackInit( ConstructorInit * ctorInit );
79
80 Type * functionReturn = nullptr;
81 Type *initContext = nullptr;
82 bool inEnumDecl = false;
83 };
84
85 void resolve( std::list< Declaration * > translationUnit ) {
86 Resolver resolver;
87 acceptAll( translationUnit, resolver );
88#if 0
89 resolver.print( cerr );
90 for ( std::list< Declaration * >::iterator i = translationUnit.begin(); i != translationUnit.end(); ++i ) {
91 (*i)->print( std::cerr );
92 (*i)->accept( resolver );
93 } // for
94#endif
95 }
96
97 Expression *resolveInVoidContext( Expression *expr, const SymTab::Indexer &indexer ) {
98 TypeEnvironment env;
99 return resolveInVoidContext( expr, indexer, env );
100 }
101
102
103 namespace {
104 void finishExpr( Expression *expr, const TypeEnvironment &env ) {
105 expr->set_env( new TypeSubstitution );
106 env.makeSubstitution( *expr->get_env() );
107 }
108 } // namespace
109
110 Expression *findVoidExpression( Expression *untyped, const SymTab::Indexer &indexer ) {
111 global_renamer.reset();
112 TypeEnvironment env;
113 Expression *newExpr = resolveInVoidContext( untyped, indexer, env );
114 finishExpr( newExpr, env );
115 return newExpr;
116 }
117
118 namespace {
119 Expression *findSingleExpression( Expression *untyped, const SymTab::Indexer &indexer ) {
120 TypeEnvironment env;
121 AlternativeFinder finder( indexer, env );
122 finder.find( untyped );
123#if 0
124 if ( finder.get_alternatives().size() != 1 ) {
125 std::cout << "untyped expr is ";
126 untyped->print( std::cout );
127 std::cout << std::endl << "alternatives are:";
128 for ( std::list< Alternative >::const_iterator i = finder.get_alternatives().begin(); i != finder.get_alternatives().end(); ++i ) {
129 i->print( std::cout );
130 } // for
131 } // if
132#endif
133 assert( finder.get_alternatives().size() == 1 );
134 Alternative &choice = finder.get_alternatives().front();
135 Expression *newExpr = choice.expr->clone();
136 finishExpr( newExpr, choice.env );
137 return newExpr;
138 }
139
140 bool isIntegralType( Type *type ) {
141 if ( dynamic_cast< EnumInstType * >( type ) ) {
142 return true;
143 } else if ( BasicType *bt = dynamic_cast< BasicType * >( type ) ) {
144 return bt->isInteger();
145 } else if ( dynamic_cast< ZeroType* >( type ) != nullptr || dynamic_cast< OneType* >( type ) != nullptr ) {
146 return true;
147 } else {
148 return false;
149 } // if
150 }
151
152 Expression *findIntegralExpression( Expression *untyped, const SymTab::Indexer &indexer ) {
153 TypeEnvironment env;
154 AlternativeFinder finder( indexer, env );
155 finder.find( untyped );
156#if 0
157 if ( finder.get_alternatives().size() != 1 ) {
158 std::cout << "untyped expr is ";
159 untyped->print( std::cout );
160 std::cout << std::endl << "alternatives are:";
161 for ( std::list< Alternative >::const_iterator i = finder.get_alternatives().begin(); i != finder.get_alternatives().end(); ++i ) {
162 i->print( std::cout );
163 } // for
164 } // if
165#endif
166 Expression *newExpr = 0;
167 const TypeEnvironment *newEnv = 0;
168 for ( AltList::const_iterator i = finder.get_alternatives().begin(); i != finder.get_alternatives().end(); ++i ) {
169 if ( i->expr->get_result()->size() == 1 && isIntegralType( i->expr->get_result() ) ) {
170 if ( newExpr ) {
171 throw SemanticError( "Too many interpretations for case control expression", untyped );
172 } else {
173 newExpr = i->expr->clone();
174 newEnv = &i->env;
175 } // if
176 } // if
177 } // for
178 if ( ! newExpr ) {
179 throw SemanticError( "No interpretations for case control expression", untyped );
180 } // if
181 finishExpr( newExpr, *newEnv );
182 return newExpr;
183 }
184
185 }
186
187 void Resolver::visit( ObjectDecl *objectDecl ) {
188 Type *new_type = resolveTypeof( objectDecl->get_type(), *this );
189 objectDecl->set_type( new_type );
190 // To handle initialization of routine pointers, e.g., int (*fp)(int) = foo(), means that class-variable
191 // initContext is changed multiple time because the LHS is analysed twice. The second analysis changes
192 // initContext because of a function type can contain object declarations in the return and parameter types. So
193 // each value of initContext is retained, so the type on the first analysis is preserved and used for selecting
194 // the RHS.
195 Type *temp = initContext;
196 initContext = new_type;
197 if ( inEnumDecl && dynamic_cast< EnumInstType * >( initContext ) ) {
198 // enumerator initializers should not use the enum type to initialize, since
199 // the enum type is still incomplete at this point. Use signed int instead.
200 initContext = new BasicType( Type::Qualifiers(), BasicType::SignedInt );
201 }
202 Parent::visit( objectDecl );
203 if ( inEnumDecl && dynamic_cast< EnumInstType * >( initContext ) ) {
204 // delete newly created signed int type
205 delete initContext;
206 }
207 initContext = temp;
208 }
209
210 template< typename PtrType >
211 void Resolver::handlePtrType( PtrType * type ) {
212 if ( type->get_dimension() ) {
213 CastExpr *castExpr = new CastExpr( type->get_dimension(), SymTab::SizeType->clone() );
214 Expression *newExpr = findSingleExpression( castExpr, *this );
215 delete type->get_dimension();
216 type->set_dimension( newExpr );
217 }
218 }
219
220 void Resolver::visit( ArrayType * at ) {
221 handlePtrType( at );
222 Parent::visit( at );
223 }
224
225 void Resolver::visit( PointerType * pt ) {
226 handlePtrType( pt );
227 Parent::visit( pt );
228 }
229
230 void Resolver::visit( TypeDecl *typeDecl ) {
231 if ( typeDecl->get_base() ) {
232 Type *new_type = resolveTypeof( typeDecl->get_base(), *this );
233 typeDecl->set_base( new_type );
234 } // if
235 Parent::visit( typeDecl );
236 }
237
238 void Resolver::visit( FunctionDecl *functionDecl ) {
239#if 0
240 std::cout << "resolver visiting functiondecl ";
241 functionDecl->print( std::cout );
242 std::cout << std::endl;
243#endif
244 Type *new_type = resolveTypeof( functionDecl->get_type(), *this );
245 functionDecl->set_type( new_type );
246 ValueGuard< Type * > oldFunctionReturn( functionReturn );
247 functionReturn = ResolvExpr::extractResultType( functionDecl->get_functionType() );
248 Parent::visit( functionDecl );
249 }
250
251 void Resolver::visit( EnumDecl * enumDecl ) {
252 // in case we decide to allow nested enums
253 ValueGuard< bool > oldInEnumDecl( inEnumDecl );
254 inEnumDecl = true;
255 Parent::visit( enumDecl );
256 }
257
258 void Resolver::visit( ExprStmt *exprStmt ) {
259 assertf( exprStmt->get_expr(), "ExprStmt has null Expression in resolver" );
260 Expression *newExpr = findVoidExpression( exprStmt->get_expr(), *this );
261 delete exprStmt->get_expr();
262 exprStmt->set_expr( newExpr );
263 }
264
265 void Resolver::visit( AsmExpr *asmExpr ) {
266 Expression *newExpr = findVoidExpression( asmExpr->get_operand(), *this );
267 delete asmExpr->get_operand();
268 asmExpr->set_operand( newExpr );
269 if ( asmExpr->get_inout() ) {
270 newExpr = findVoidExpression( asmExpr->get_inout(), *this );
271 delete asmExpr->get_inout();
272 asmExpr->set_inout( newExpr );
273 } // if
274 }
275
276 void Resolver::visit( AsmStmt *asmStmt ) {
277 acceptAll( asmStmt->get_input(), *this);
278 acceptAll( asmStmt->get_output(), *this);
279 }
280
281 void Resolver::visit( IfStmt *ifStmt ) {
282 Expression *newExpr = findSingleExpression( ifStmt->get_condition(), *this );
283 delete ifStmt->get_condition();
284 ifStmt->set_condition( newExpr );
285 Parent::visit( ifStmt );
286 }
287
288 void Resolver::visit( WhileStmt *whileStmt ) {
289 Expression *newExpr = findSingleExpression( whileStmt->get_condition(), *this );
290 delete whileStmt->get_condition();
291 whileStmt->set_condition( newExpr );
292 Parent::visit( whileStmt );
293 }
294
295 void Resolver::visit( ForStmt *forStmt ) {
296 Parent::visit( forStmt );
297
298 if ( forStmt->get_condition() ) {
299 Expression * newExpr = findSingleExpression( forStmt->get_condition(), *this );
300 delete forStmt->get_condition();
301 forStmt->set_condition( newExpr );
302 } // if
303
304 if ( forStmt->get_increment() ) {
305 Expression * newExpr = findVoidExpression( forStmt->get_increment(), *this );
306 delete forStmt->get_increment();
307 forStmt->set_increment( newExpr );
308 } // if
309 }
310
311 template< typename SwitchClass >
312 void handleSwitchStmt( SwitchClass *switchStmt, SymTab::Indexer &visitor ) {
313 Expression *newExpr;
314 newExpr = findIntegralExpression( switchStmt->get_condition(), visitor );
315 delete switchStmt->get_condition();
316 switchStmt->set_condition( newExpr );
317
318 visitor.Visitor::visit( switchStmt );
319 }
320
321 void Resolver::visit( SwitchStmt *switchStmt ) {
322 handleSwitchStmt( switchStmt, *this );
323 }
324
325 void Resolver::visit( CaseStmt *caseStmt ) {
326 Parent::visit( caseStmt );
327 }
328
329 void Resolver::visit( BranchStmt *branchStmt ) {
330 // must resolve the argument for a computed goto
331 if ( branchStmt->get_type() == BranchStmt::Goto ) { // check for computed goto statement
332 if ( Expression * arg = branchStmt->get_computedTarget() ) {
333 VoidType v = Type::Qualifiers(); // cast to void * for the alternative finder
334 PointerType pt( Type::Qualifiers(), v.clone() );
335 CastExpr * castExpr = new CastExpr( arg, pt.clone() );
336 Expression * newExpr = findSingleExpression( castExpr, *this ); // find best expression
337 branchStmt->set_target( newExpr );
338 } // if
339 } // if
340 }
341
342 void Resolver::visit( ReturnStmt *returnStmt ) {
343 if ( returnStmt->get_expr() ) {
344 CastExpr *castExpr = new CastExpr( returnStmt->get_expr(), functionReturn->clone() );
345 Expression *newExpr = findSingleExpression( castExpr, *this );
346 delete castExpr;
347 returnStmt->set_expr( newExpr );
348 } // if
349 }
350
351 template< typename T >
352 bool isCharType( T t ) {
353 if ( BasicType * bt = dynamic_cast< BasicType * >( t ) ) {
354 return bt->get_kind() == BasicType::Char || bt->get_kind() == BasicType::SignedChar ||
355 bt->get_kind() == BasicType::UnsignedChar;
356 }
357 return false;
358 }
359
360 void Resolver::visit( SingleInit *singleInit ) {
361 if ( singleInit->get_value() ) {
362#if 0
363 if (NameExpr * ne = dynamic_cast<NameExpr*>(singleInit->get_value())) {
364 string n = ne->get_name();
365 if (n == "0") {
366 initContext = new BasicType(Type::Qualifiers(),
367 BasicType::SignedInt);
368 } else {
369 DeclarationWithType * decl = lookupId( n );
370 initContext = decl->get_type();
371 }
372 } else if (ConstantExpr * e =
373 dynamic_cast<ConstantExpr*>(singleInit->get_value())) {
374 Constant *c = e->get_constant();
375 initContext = c->get_type();
376 } else {
377 assert(0);
378 }
379#endif
380 CastExpr *castExpr = new CastExpr( singleInit->get_value(), initContext->clone() );
381 Expression *newExpr = findSingleExpression( castExpr, *this );
382 delete castExpr;
383 singleInit->set_value( newExpr );
384
385 // check if initializing type is char[]
386 if ( ArrayType * at = dynamic_cast< ArrayType * >( initContext ) ) {
387 if ( isCharType( at->get_base() ) ) {
388 // check if the resolved type is char *
389 if ( PointerType * pt = dynamic_cast< PointerType *>( newExpr->get_result() ) ) {
390 if ( isCharType( pt->get_base() ) ) {
391 // strip cast if we're initializing a char[] with a char *, e.g. char x[] = "hello";
392 CastExpr *ce = dynamic_cast< CastExpr * >( newExpr );
393 singleInit->set_value( ce->get_arg() );
394 ce->set_arg( NULL );
395 delete ce;
396 }
397 }
398 }
399 }
400 } // if
401// singleInit->get_value()->accept( *this );
402 }
403
404 template< typename AggrInst >
405 TypeSubstitution makeGenericSubstitutuion( AggrInst * inst ) {
406 assert( inst );
407 assert( inst->get_baseParameters() );
408 std::list< TypeDecl * > baseParams = *inst->get_baseParameters();
409 std::list< Expression * > typeSubs = inst->get_parameters();
410 TypeSubstitution subs( baseParams.begin(), baseParams.end(), typeSubs.begin() );
411 return subs;
412 }
413
414 ReferenceToType * isStructOrUnion( Type * type ) {
415 if ( StructInstType * sit = dynamic_cast< StructInstType * >( type ) ) {
416 return sit;
417 } else if ( UnionInstType * uit = dynamic_cast< UnionInstType * >( type ) ) {
418 return uit;
419 }
420 return nullptr;
421 }
422
423 void Resolver::resolveSingleAggrInit( Declaration * dcl, InitIterator & init, InitIterator & initEnd, TypeSubstitution sub ) {
424 DeclarationWithType * dt = dynamic_cast< DeclarationWithType * >( dcl );
425 assert( dt );
426 // need to substitute for generic types, so that casts are to concrete types
427 initContext = dt->get_type()->clone();
428 sub.apply( initContext );
429
430 try {
431 if ( init == initEnd ) return; // stop when there are no more initializers
432 (*init)->accept( *this );
433 ++init; // made it past an initializer
434 } catch( SemanticError & ) {
435 // need to delve deeper, if you can
436 if ( ReferenceToType * type = isStructOrUnion( initContext ) ) {
437 resolveAggrInit( type, init, initEnd );
438 } else {
439 // member is not an aggregate type, so can't go any deeper
440
441 // might need to rethink what is being thrown
442 throw;
443 } // if
444 }
445 }
446
447 void Resolver::resolveAggrInit( ReferenceToType * inst, InitIterator & init, InitIterator & initEnd ) {
448 if ( StructInstType * sit = dynamic_cast< StructInstType * >( inst ) ) {
449 TypeSubstitution sub = makeGenericSubstitutuion( sit );
450 StructDecl * st = sit->get_baseStruct();
451 if(st->get_members().empty()) return;
452 // want to resolve each initializer to the members of the struct,
453 // but if there are more initializers than members we should stop
454 list< Declaration * >::iterator it = st->get_members().begin();
455 for ( ; it != st->get_members().end(); ++it) {
456 resolveSingleAggrInit( *it, init, initEnd, sub );
457 }
458 } else if ( UnionInstType * uit = dynamic_cast< UnionInstType * >( inst ) ) {
459 TypeSubstitution sub = makeGenericSubstitutuion( uit );
460 UnionDecl * un = uit->get_baseUnion();
461 if(un->get_members().empty()) return;
462 // only resolve to the first member of a union
463 resolveSingleAggrInit( *un->get_members().begin(), init, initEnd, sub );
464 } // if
465 }
466
467 void Resolver::visit( ListInit * listInit ) {
468 InitIterator iter = listInit->begin();
469 InitIterator end = listInit->end();
470
471 if ( ArrayType * at = dynamic_cast< ArrayType * >( initContext ) ) {
472 // resolve each member to the base type of the array
473 for ( ; iter != end; ++iter ) {
474 initContext = at->get_base();
475 (*iter)->accept( *this );
476 } // for
477 } else if ( TupleType * tt = dynamic_cast< TupleType * > ( initContext ) ) {
478 for ( Type * t : *tt ) {
479 if ( iter == end ) break;
480 initContext = t;
481 (*iter++)->accept( *this );
482 }
483 } else if ( ReferenceToType * type = isStructOrUnion( initContext ) ) {
484 resolveAggrInit( type, iter, end );
485 } else if ( TypeInstType * tt = dynamic_cast< TypeInstType * >( initContext ) ) {
486 Type * base = tt->get_baseType()->get_base();
487 if ( base ) {
488 // know the implementation type, so try using that as the initContext
489 initContext = base;
490 visit( listInit );
491 } else {
492 // missing implementation type -- might be an unknown type variable, so try proceeding with the current init context
493 Parent::visit( listInit );
494 }
495 } else {
496 assert( dynamic_cast< BasicType * >( initContext ) || dynamic_cast< PointerType * >( initContext )
497 || dynamic_cast< ZeroType * >( initContext ) || dynamic_cast< OneType * >( initContext ) || dynamic_cast < EnumInstType * > ( initContext ) );
498 // basic types are handled here
499 Parent::visit( listInit );
500 }
501
502#if 0
503 if ( ArrayType *at = dynamic_cast<ArrayType*>(initContext) ) {
504 std::list<Initializer *>::iterator iter( listInit->begin_initializers() );
505 for ( ; iter != listInit->end_initializers(); ++iter ) {
506 initContext = at->get_base();
507 (*iter)->accept( *this );
508 } // for
509 } else if ( StructInstType *st = dynamic_cast<StructInstType*>(initContext) ) {
510 StructDecl *baseStruct = st->get_baseStruct();
511 std::list<Declaration *>::iterator iter1( baseStruct->get_members().begin() );
512 std::list<Initializer *>::iterator iter2( listInit->begin_initializers() );
513 for ( ; iter1 != baseStruct->get_members().end() && iter2 != listInit->end_initializers(); ++iter2 ) {
514 if ( (*iter2)->get_designators().empty() ) {
515 DeclarationWithType *dt = dynamic_cast<DeclarationWithType *>( *iter1 );
516 initContext = dt->get_type();
517 (*iter2)->accept( *this );
518 ++iter1;
519 } else {
520 StructDecl *st = baseStruct;
521 iter1 = st->get_members().begin();
522 std::list<Expression *>::iterator iter3( (*iter2)->get_designators().begin() );
523 for ( ; iter3 != (*iter2)->get_designators().end(); ++iter3 ) {
524 NameExpr *key = dynamic_cast<NameExpr *>( *iter3 );
525 assert( key );
526 for ( ; iter1 != st->get_members().end(); ++iter1 ) {
527 if ( key->get_name() == (*iter1)->get_name() ) {
528 (*iter1)->print( cout );
529 cout << key->get_name() << endl;
530 ObjectDecl *fred = dynamic_cast<ObjectDecl *>( *iter1 );
531 assert( fred );
532 StructInstType *mary = dynamic_cast<StructInstType*>( fred->get_type() );
533 assert( mary );
534 st = mary->get_baseStruct();
535 iter1 = st->get_members().begin();
536 break;
537 } // if
538 } // for
539 } // for
540 ObjectDecl *fred = dynamic_cast<ObjectDecl *>( *iter1 );
541 assert( fred );
542 initContext = fred->get_type();
543 (*listInit->begin_initializers())->accept( *this );
544 } // if
545 } // for
546 } else if ( UnionInstType *st = dynamic_cast<UnionInstType*>(initContext) ) {
547 DeclarationWithType *dt = dynamic_cast<DeclarationWithType *>( *st->get_baseUnion()->get_members().begin() );
548 initContext = dt->get_type();
549 (*listInit->begin_initializers())->accept( *this );
550 } // if
551#endif
552 }
553
554 // ConstructorInit - fall back on C-style initializer
555 void Resolver::fallbackInit( ConstructorInit * ctorInit ) {
556 // could not find valid constructor, or found an intrinsic constructor
557 // fall back on C-style initializer
558 delete ctorInit->get_ctor();
559 ctorInit->set_ctor( NULL );
560 delete ctorInit->get_dtor();
561 ctorInit->set_dtor( NULL );
562 maybeAccept( ctorInit->get_init(), *this );
563 }
564
565 // needs to be callable from outside the resolver, so this is a standalone function
566 void resolveCtorInit( ConstructorInit * ctorInit, const SymTab::Indexer & indexer ) {
567 assert( ctorInit );
568 Resolver resolver( indexer );
569 ctorInit->accept( resolver );
570 }
571
572 void resolveStmtExpr( StmtExpr * stmtExpr, const SymTab::Indexer & indexer ) {
573 assert( stmtExpr );
574 Resolver resolver( indexer );
575 stmtExpr->accept( resolver );
576 }
577
578 void Resolver::visit( ConstructorInit *ctorInit ) {
579 // xxx - fallback init has been removed => remove fallbackInit function and remove complexity from FixInit and remove C-init from ConstructorInit
580 maybeAccept( ctorInit->get_ctor(), *this );
581 maybeAccept( ctorInit->get_dtor(), *this );
582
583 // found a constructor - can get rid of C-style initializer
584 delete ctorInit->get_init();
585 ctorInit->set_init( NULL );
586
587 // intrinsic single parameter constructors and destructors do nothing. Since this was
588 // implicitly generated, there's no way for it to have side effects, so get rid of it
589 // to clean up generated code.
590 if ( InitTweak::isIntrinsicSingleArgCallStmt( ctorInit->get_ctor() ) ) {
591 delete ctorInit->get_ctor();
592 ctorInit->set_ctor( NULL );
593 }
594
595 if ( InitTweak::isIntrinsicSingleArgCallStmt( ctorInit->get_dtor() ) ) {
596 delete ctorInit->get_dtor();
597 ctorInit->set_dtor( NULL );
598 }
599
600 // xxx - todo -- what about arrays?
601 // if ( dtor == NULL && InitTweak::isIntrinsicCallStmt( ctorInit->get_ctor() ) ) {
602 // // can reduce the constructor down to a SingleInit using the
603 // // second argument from the ctor call, since
604 // delete ctorInit->get_ctor();
605 // ctorInit->set_ctor( NULL );
606
607 // Expression * arg =
608 // ctorInit->set_init( new SingleInit( arg ) );
609 // }
610 }
611} // namespace ResolvExpr
612
613// Local Variables: //
614// tab-width: 4 //
615// mode: c++ //
616// compile-command: "make install" //
617// End: //
Note: See TracBrowser for help on using the repository browser.