Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/AST/Convert.cpp

    r6896548 raaeacf4  
    733733        const ast::Expr * visit( const ast::VariableExpr * node ) override final {
    734734                auto expr = new VariableExpr();
     735                visitBaseExpr( node, expr );
    735736                expr->var = get<DeclarationWithType>().accept1(node->var);
    736                 visitBaseExpr( node, expr );
     737                Type * type = expr->var->get_type()->clone();
     738                if(FunctionType * ft = dynamic_cast<FunctionType*>(type)) {
     739                        if(node->result.as<ast::PointerType>()) {
     740                                type = new PointerType({}, ft);
     741                        }
     742                }
     743
     744                type->set_lvalue( true );
     745                expr->result = type ;
    737746                this->node = expr;
    738747                return nullptr;
     
    757766                        break;
    758767                case ast::ConstantExpr::String:
    759                         // Old world:   two types: rslt->constant.type, rslt->result
    760                         // New workd:   one type: node->result
    761                         // Both worlds: the outer, expression-level type can change during resolution
    762                         //              in case of string, that's char[k] before-resolve and char * after
    763                         // Old world:   the inner Constant type stays what it was built with
    764                         //              in case of string, that's char[k]
    765                         // Both worlds: the "rep" field of a string constant is the string value it was initialized from, wrapped in quotes, but not otherwise escaped
    766                         ast::ptr<ast::Type> charType = nullptr;
    767                         if (const ast::ArrayType *arrRslt = node->result.as<ast::ArrayType>()) {
    768                                 charType = arrRslt->base;
    769                         } else {
    770                                 const ast::PointerType *ptrRslt = node->result.as<ast::PointerType>();
    771                                 assert(ptrRslt);
    772                                 charType = ptrRslt->base;
    773                         }
    774                         rslt = new ConstantExpr(Constant::from_string(
    775                                 node->rep, get<Type>().accept1(charType)));          // rslt->result is char[k]
    776                         rslt->set_result( get<Type>().accept1( node->result ) ); // rslt->result is [[ node->rsult ]]
     768                        rslt = new ConstantExpr{Constant{
     769                                get<Type>().accept1( node->result ),
     770                                node->rep,
     771                                (long long unsigned int)0
     772                        }};
    777773                        break;
    778774                }
     
    21562152                );
    21572153
     2154                visitBaseExpr_SkipResultType( old,
     2155                        expr
     2156                );
     2157
    21582158                expr->var = GET_ACCEPT_1(var, DeclWithType);
    2159                 visitBaseExpr( old, expr );
    2160 
     2159                expr->result = expr->var->get_type();
     2160                if(const ast::FunctionType * ft = expr->result.as<ast::FunctionType>()) {
     2161                        if(dynamic_cast<PointerType *>(old->result)) {
     2162                                expr->result = new ast::PointerType(ft);
     2163                        }
     2164                }
     2165                add_qualifiers( expr->result, ast::CV::Lvalue );
    21612166                this->node = expr;
    21622167        }
     
    21882193
    21892194        int isStringlikeConstantType(const Type *t) {
    2190                 const Type *referentType = nullptr;
    21912195                if ( const ArrayType * aty = dynamic_cast< const ArrayType * >( t ) ) {
    2192                         referentType = aty->base;
    2193                 } else if ( const PointerType * pty = dynamic_cast< const PointerType * >( t ) ) {
    2194                         referentType = pty->base;
    2195                 }
    2196                 if (referentType) {
    2197                         if ( const BasicType * bty = dynamic_cast< const BasicType * >( referentType ) ) {
     2196                        if ( const BasicType * bty = dynamic_cast< const BasicType * >( aty->base ) ) {
    21982197                           if ( bty->kind == BasicType::Kind::Char ) {
    21992198                                   return true;
     
    22062205        virtual void visit( ConstantExpr * old ) override final {
    22072206                ast::ConstantExpr *rslt = nullptr;
    2208                 if (isStringlikeConstantType(old->result)) {
    2209                         rslt = new ast::ConstantExpr(
    2210                                 old->location,
    2211                                 GET_ACCEPT_1(result, Type), // preserve the expression-level type (old->result, not old->constant.type); see new-to-old
    2212                                 old->constant.get_value(),
    2213                                 0,
    2214                                 ast::ConstantExpr::Kind::String
    2215                         );
    2216                 } else if (isIntlikeConstantType(old->result)) {
     2207                if (isIntlikeConstantType(old->result)) {
    22172208                        rslt = new ast::ConstantExpr(
    22182209                                old->location,
     
    22282219                                old->constant.get_value(),
    22292220                                (double) old->constant.get_dval()
     2221                        );
     2222                } else if (isStringlikeConstantType(old->result)) {
     2223                        rslt = new ast::ConstantExpr(
     2224                                old->location,
     2225                                GET_ACCEPT_1(result, Type),
     2226                                old->constant.get_value(),
     2227                                0,
     2228                                ast::ConstantExpr::Kind::String
    22302229                        );
    22312230                }
Note: See TracChangeset for help on using the changeset viewer.