Changeset 70f89d00 for src/InitTweak


Ignore:
Timestamp:
May 30, 2016, 12:51:22 PM (8 years ago)
Author:
Rob Schluntz <rschlunt@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, ctor, deferred_resn, demangler, enum, forall-pointer-decay, gc_noraii, jacob/cs343-translation, jenkins-sandbox, master, memory, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
Children:
f1b1e4c
Parents:
677c1be
Message:

function scoped const objects can be constructed, add missing copy constructors to Initializer.cc

Location:
src/InitTweak
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • src/InitTweak/GenInit.cc

    r677c1be r70f89d00  
    143143                if ( tryConstruct( objDecl ) ) {
    144144                        if ( inFunction ) {
     145                                // remove qualifiers so that const objects can be initialized, and attach the
     146                                // qualifiers to ConstructorInit so that they can be replaced after resolving
     147                                Type * type = objDecl->get_type();
     148                                Type::Qualifiers qualifiers = type->get_qualifiers();
     149                                type->get_qualifiers() = Type::Qualifiers();
     150
    145151                                if ( ArrayType * at = dynamic_cast< ArrayType * >( objDecl->get_type() ) ) {
    146152                                        // call into makeArrayFunction from validate.cc to generate calls to ctor/dtor for each element of array
     
    165171                                                assert( dtor.size() == 1 );
    166172
    167                                                 objDecl->set_init( new ConstructorInit( ctor.front(), dtor.front(), objDecl->get_init() ) );
     173                                                objDecl->set_init( new ConstructorInit( ctor.front(), dtor.front(), objDecl->get_init(), objDecl, qualifiers ) );
    168174                                        } else {
    169175                                                // array came with an initializer list: initialize each element
     
    185191                                        ExprStmt * ctorStmt = new ExprStmt( noLabels, ctor );
    186192                                        ExprStmt * dtorStmt = new ExprStmt( noLabels, dtor );
    187                                         objDecl->set_init( new ConstructorInit( ctorStmt, dtorStmt, objDecl->get_init() ) );
     193                                        objDecl->set_init( new ConstructorInit( ctorStmt, dtorStmt, objDecl->get_init(), objDecl, qualifiers ) );
    188194                                }
    189195                        }
  • src/InitTweak/InitTweak.cc

    r677c1be r70f89d00  
    8383    }
    8484  }
     85
     86  namespace {
     87    template<typename CallExpr>
     88    std::string funcName( CallExpr * expr ) {
     89      Expression * func = expr->get_function();
     90      if ( NameExpr * nameExpr = dynamic_cast< NameExpr * >( func ) ) {
     91        return nameExpr->get_name();
     92      } else if ( VariableExpr * varExpr = dynamic_cast< VariableExpr * >( func ) ) {
     93        return varExpr->get_var()->get_name();
     94      } else {
     95        assert( false && "Unexpected expression type being called as a function in call expression" );
     96      }
     97    }
     98  }
     99
     100  std::string getFunctionName( Expression * expr ) {
     101    if ( ApplicationExpr * appExpr = dynamic_cast< ApplicationExpr * >( expr ) ) {
     102      return funcName( appExpr );
     103    } else if ( UntypedExpr * untypedExpr = dynamic_cast< UntypedExpr * > ( expr ) ) {
     104      return funcName( untypedExpr );
     105    } else {
     106      assert( false && "Unexpected expression type passed to getFunctionName" );
     107    }
     108  }
    85109}
  • src/InitTweak/InitTweak.h

    r677c1be r70f89d00  
    3939  /// Currently has assertions that make it less than fully general.
    4040  bool isInstrinsicSingleArgCallStmt( Statement * expr );
     41
     42  /// returns the name of the function being called
     43  std::string getFunctionName(Expression * expr);
    4144} // namespace
    4245
Note: See TracChangeset for help on using the changeset viewer.