Changeset 6896548 for src/SynTree


Ignore:
Timestamp:
Jun 13, 2019, 3:56:24 PM (5 years ago)
Author:
Michael Brooks <mlbrooks@…>
Branches:
ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
6a1dfda
Parents:
d76f32c
Message:

Fixed convert-convert issues with strings, when conversion happens after resolve. Three specific issues fixed.

  1. String literals were not roundtripping new-old-new with the original type at the constant level, whereas the resolver changes the expression-level type from array to pointer.
  2. String literals were roundtripping with noise on a "--print astexpr" diff, with the char-array's index type coming up signed int (expecting unsigned long long int).
  3. Function calls that pass a foo[] variable as argument to a foo* formal were crashing on copy-constructor generation because convert-convert was changing the arg-expression type from foo* (set by the resolver, as expecteed) back to foo[], taken from the variable (switched to foo* taken from convert-src expression).
Location:
src/SynTree
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • src/SynTree/Constant.cc

    rd76f32c r6896548  
    5151}
    5252
    53 Constant Constant::from_string( std::string const & str ) {
    54         return Constant(
    55                 new ArrayType(
    56                         noQualifiers,
    57                         new BasicType( Type::Qualifiers( Type::Const ), BasicType::Char ),
    58                         new ConstantExpr( Constant::from_int( str.size() + 1 /* \0 */ )),
    59                         false, false ),
    60                 std::string("\"") + str + "\"", (unsigned long long int)0 );
     53Constant Constant::from_string( std::string const & cEscapedVal, Type *charType ) {
     54        assert(cEscapedVal.length() >= 2);
     55        assert(cEscapedVal.front() == '"');
     56        assert(cEscapedVal.back() == '"');
     57        ArrayType * at = new ArrayType( noQualifiers, charType,
     58                                                                        new ConstantExpr( Constant::from_ulong( cEscapedVal.size() + 1 - 2 ) ), // +1 for '\0' and -2 for '"'
     59                                                                        false, false );
     60        return Constant( at, cEscapedVal, (unsigned long long int)0 );
    6161}
    6262
  • src/SynTree/Constant.h

    rd76f32c r6896548  
    5252        static Constant from_double( double d );
    5353        /// generates an array of chars constant of the given string
    54         static Constant from_string( std::string const & s );
     54        static Constant from_string( std::string const & cEscapedVal, Type *charType );
    5555
    5656        /// generates a null pointer value for the given type. void * if omitted.
Note: See TracChangeset for help on using the changeset viewer.