Changes in src/AST/Convert.cpp [8b34df0:e6faef4]
- File:
-
- 1 edited
-
src/AST/Convert.cpp (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/AST/Convert.cpp
r8b34df0 re6faef4 10 10 // Created On : Thu May 09 15::37::05 2019 11 11 // Last Modified By : Andrew Beach 12 // Last Modified On : M an Jun 10 11:51:00 201913 // Update Count : 1 112 // Last Modified On : Mon Jun 17 16:44:00 2019 13 // Update Count : 12 14 14 // 15 15 … … 734 734 const ast::Expr * visit( const ast::VariableExpr * node ) override final { 735 735 auto expr = new VariableExpr(); 736 expr->var = get<DeclarationWithType>().accept1(node->var); 736 737 visitBaseExpr( node, expr ); 737 expr->var = get<DeclarationWithType>().accept1(node->var);738 Type * type = expr->var->get_type()->clone();739 if(FunctionType * ft = dynamic_cast<FunctionType*>(type)) {740 if(node->result.as<ast::PointerType>()) {741 type = new PointerType({}, ft);742 }743 }744 745 type->set_lvalue( true );746 expr->result = type ;747 738 this->node = expr; 748 739 return nullptr; … … 750 741 751 742 const ast::Expr * visit( const ast::ConstantExpr * node ) override final { 752 ConstantExpr *rslt = nullptr; 753 switch ( node->kind ) { 754 case ast::ConstantExpr::Integer: 755 rslt = new ConstantExpr{Constant{ 756 get<Type>().accept1( node->result ), 757 node->rep, 758 (unsigned long long) node->intValue() 759 }}; 760 break; 761 case ast::ConstantExpr::FloatingPoint: 762 rslt = new ConstantExpr{Constant{ 763 get<Type>().accept1(node->result), 764 node->rep, 765 (double) node->floatValue() 766 }}; 767 break; 768 case ast::ConstantExpr::String: 769 rslt = new ConstantExpr{Constant{ 770 get<Type>().accept1( node->result ), 771 node->rep, 772 (long long unsigned int)0 773 }}; 774 break; 775 } 776 assert(rslt); 743 // Old world: two types: rslt->constant.type, rslt->result 744 // New workd: one public type: node->result, plus node->underlyer only to support roundtrip conversion 745 // preserving underlyer because the correct type for string literals is complicated to construct, 746 // and distinguishing a string from other literals using the type is hard to do accurately 747 // Both worlds: the outer, expression-level type can change during resolution 748 // for a string, that's char[k] before-resolve and char * after 749 // Old world: the inner Constant type stays what it was built with 750 // for a string, that's char[k] always 751 // Both worlds: the "rep" field of a constant is the C source file fragment that compiles to the desired value 752 // for a string, that includes outer quotes, backslashes, et al cases from the Literals test 753 ConstantExpr *rslt = new ConstantExpr(Constant( 754 get<Type>().accept1(node->underlyer), 755 node->rep, 756 node->ival)); 777 757 auto expr = visitBaseExpr( node, rslt ); 778 758 this->node = expr; … … 969 949 const ast::Expr * visit( const ast::TupleExpr * node ) override final { 970 950 auto expr = visitBaseExpr( node, 971 new UntypedTupleExpr(951 new TupleExpr( 972 952 get<Expression>().acceptL(node->exprs) 973 953 ) … … 1490 1470 decl->mangleName = old->mangleName; 1491 1471 decl->isDeleted = old->isDeleted; 1472 decl->asmName = GET_ACCEPT_1(asmName, Expr); 1492 1473 decl->uniqueId = old->uniqueId; 1493 1474 decl->extension = old->extension; … … 1514 1495 decl->mangleName = old->mangleName; 1515 1496 decl->isDeleted = old->isDeleted; 1497 decl->asmName = GET_ACCEPT_1(asmName, Expr); 1516 1498 decl->uniqueId = old->uniqueId; 1517 1499 decl->extension = old->extension; … … 2153 2135 ); 2154 2136 2155 visitBaseExpr_SkipResultType( old,2156 expr2157 );2158 2159 2137 expr->var = GET_ACCEPT_1(var, DeclWithType); 2160 expr->result = expr->var->get_type(); 2161 if(const ast::FunctionType * ft = expr->result.as<ast::FunctionType>()) { 2162 if(dynamic_cast<PointerType *>(old->result)) { 2163 expr->result = new ast::PointerType(ft); 2164 } 2165 } 2166 add_qualifiers( expr->result, ast::CV::Lvalue ); 2167 this->node = expr; 2168 } 2169 2170 bool isIntlikeConstantType(const Type *t) { 2171 if ( const BasicType * basicType = dynamic_cast< const BasicType * >( t ) ) { 2172 if ( basicType->isInteger() ) { 2173 return true; 2174 } 2175 } else if ( dynamic_cast< const OneType * >( t ) ) { 2176 return true; 2177 } else if ( dynamic_cast< const ZeroType * >( t ) ) { 2178 return true; 2179 } else if ( dynamic_cast< const PointerType * >( t ) ) { 2180 // null pointer constants, with zero int-values 2181 return true; 2182 } 2183 return false; 2184 } 2185 2186 int isFloatlikeConstantType(const Type *t) { 2187 if ( const BasicType * bty = dynamic_cast< const BasicType * >( t ) ) { 2188 if ( ! bty->isInteger() ) { 2189 return true; 2190 } 2191 } 2192 return false; 2193 } 2194 2195 int isStringlikeConstantType(const Type *t) { 2196 const Type *referentType = nullptr; 2197 if ( const ArrayType * aty = dynamic_cast< const ArrayType * >( t ) ) { 2198 referentType = aty->base; 2199 } else if ( const PointerType * pty = dynamic_cast< const PointerType * >( t ) ) { 2200 referentType = pty->base; 2201 } 2202 if (referentType) { 2203 if ( const BasicType * bty = dynamic_cast< const BasicType * >( referentType ) ) { 2204 if ( bty->kind == BasicType::Kind::Char ) { 2205 return true; 2206 } 2207 } 2208 } 2209 return false; 2138 visitBaseExpr( old, expr ); 2139 2140 this->node = expr; 2210 2141 } 2211 2142 2212 2143 virtual void visit( ConstantExpr * old ) override final { 2213 ast::ConstantExpr *rslt = nullptr; 2214 if (isStringlikeConstantType(old->result)) { 2215 rslt = new ast::ConstantExpr( 2216 old->location, 2217 GET_ACCEPT_1(result, Type), 2218 old->constant.get_value(), 2219 0, 2220 ast::ConstantExpr::Kind::String 2221 ); 2222 } else if (isIntlikeConstantType(old->result)) { 2223 rslt = new ast::ConstantExpr( 2224 old->location, 2225 GET_ACCEPT_1(result, Type), 2226 old->constant.get_value(), 2227 (unsigned long long) old->intValue(), 2228 ast::ConstantExpr::Kind::Integer 2229 ); 2230 } else if (isFloatlikeConstantType(old->result)) { 2231 rslt = new ast::ConstantExpr( 2232 old->location, 2233 GET_ACCEPT_1(result, Type), 2234 old->constant.get_value(), 2235 (double) old->constant.get_dval() 2236 ); 2237 } 2238 assert(rslt); 2144 ast::ConstantExpr *rslt = new ast::ConstantExpr( 2145 old->location, 2146 GET_ACCEPT_1(result, Type), 2147 old->constant.get_value(), 2148 old->constant.ival 2149 ); 2150 rslt->underlyer = getAccept1< ast::Type, Type* >( old->constant.get_type() ); 2239 2151 this->node = visitBaseExpr( old, rslt ); 2240 2152 }
Note:
See TracChangeset
for help on using the changeset viewer.