Changes in / [6a1dfda:dc5072f]
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
src/AST/Convert.cpp
r6a1dfda rdc5072f 733 733 const ast::Expr * visit( const ast::VariableExpr * node ) override final { 734 734 auto expr = new VariableExpr(); 735 visitBaseExpr( node, expr ); 735 736 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 ; 737 746 this->node = expr; 738 747 return nullptr; … … 757 766 break; 758 767 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 }}; 777 773 break; 778 774 } … … 2156 2152 ); 2157 2153 2154 visitBaseExpr_SkipResultType( old, 2155 expr 2156 ); 2157 2158 2158 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 ); 2161 2166 this->node = expr; 2162 2167 } … … 2209 2214 rslt = new ast::ConstantExpr( 2210 2215 old->location, 2211 GET_ACCEPT_1(result, Type), // preserve the expression-level type (old->result, not old->constant.type); see new-to-old2216 GET_ACCEPT_1(result, Type), 2212 2217 old->constant.get_value(), 2213 2218 0, -
src/AST/Expr.cpp
r6a1dfda rdc5072f 9 9 // Author : Aaron B. Moss 10 10 // Created On : Wed May 15 17:00:00 2019 11 // Last Modified By : A ndrew Beach12 // Created On : Thr Jun 13 13:38:00 201913 // Update Count : 211 // Last Modified By : Aaron B. Moss 12 // Created On : Wed May 15 17:00:00 2019 13 // Update Count : 1 14 14 // 15 15 … … 238 238 } 239 239 240 ConstantExpr * ConstantExpr::from_string( const CodeLocation & loc, const std::string & s ) { 241 return new ConstantExpr{ 242 loc, 243 new ArrayType{ 244 new BasicType{ BasicType::Char, CV::Const }, 245 ConstantExpr::from_int( loc, s.size() + 1 /* null terminator */ ), 246 FixedLen, DynamicDim }, 247 std::string{"\""} + s + "\"", 248 (unsigned long long)0, 249 ConstantExpr::String }; 250 } 251 240 252 ConstantExpr * ConstantExpr::null( const CodeLocation & loc, const Type * ptrType ) { 241 253 return new ConstantExpr{ … … 370 382 371 383 UniqueExpr::UniqueExpr( const CodeLocation & loc, const Expr * e, unsigned long long i ) 372 : Expr( loc, e->result ), expr( e ),id( i ) {384 : Expr( loc, e->result ), id( i ) { 373 385 assert( expr ); 374 386 if ( id == -1ull ) { -
src/AST/Expr.hpp
r6a1dfda rdc5072f 381 381 /// generates a floating point constant of the given double 382 382 static ConstantExpr * from_double( const CodeLocation & loc, double d ); 383 /// generates an array of chars constant of the given string 384 static ConstantExpr * from_string( const CodeLocation & loc, const std::string & s ); 383 385 /// generates a null pointer value for the given type. void * if omitted. 384 386 static ConstantExpr * null( const CodeLocation & loc, const Type * ptrType = nullptr ); … … 691 693 unsigned long long id; 692 694 693 UniqueExpr( const CodeLocation & loc, const Expr * e, unsigned long long i = -1 ull);695 UniqueExpr( const CodeLocation & loc, const Expr * e, unsigned long long i = -1 ); 694 696 695 697 const Expr * accept( Visitor & v ) const override { return v.visit( this ); } -
src/Parser/ExpressionNode.cc
r6a1dfda rdc5072f 354 354 strtype = new BasicType( Type::Qualifiers( Type::Const ), BasicType::Char ); 355 355 } // switch 356 Expression * ret = new ConstantExpr( Constant::from_string( str, strtype ) ); 356 ArrayType * at = new ArrayType( noQualifiers, strtype, 357 new ConstantExpr( Constant::from_ulong( str.size() + 1 - 2 ) ), // +1 for '\0' and -2 for '"' 358 false, false ); 359 Expression * ret = new ConstantExpr( Constant( at, str, (unsigned long long int)0 ) ); // constant 0 is ignored for pure string value 357 360 if ( units.length() != 0 ) { 358 361 ret = new UntypedExpr( new NameExpr( units ), { ret } ); -
src/ResolvExpr/Candidate.hpp
r6a1dfda rdc5072f 9 9 // Author : Aaron B. Moss 10 10 // Created On : Wed Jun 5 14:30:00 2019 11 // Last Modified By : A ndrew Beach12 // Last Modified On : Wed Jun 12 14:15:00 201913 // Update Count : 211 // Last Modified By : Aaron B. Moss 12 // Last Modified On : Wed Jun 5 14:30:00 2019 13 // Update Count : 1 14 14 // 15 15 … … 49 49 50 50 Candidate() : expr(), cost( Cost::zero ), cvtCost( Cost::zero ), env(), open(), need() {} 51 51 52 52 Candidate( const ast::Expr * x, const ast::TypeEnvironment & e ) 53 53 : expr( x ), cost( Cost::zero ), cvtCost( Cost::zero ), env( e ), open(), need() {} 54 54 55 55 Candidate( const Candidate & o, const ast::Expr * x ) 56 : expr( x ), cost( o.cost ), cvtCost( Cost::zero ), env( o.env ), open( o.open ), 56 : expr( x ), cost( o.cost ), cvtCost( Cost::zero ), env( o.env ), open( o.open ), 57 57 need( o.need ) {} 58 59 Candidate( 60 const ast::Expr * x, ast::TypeEnvironment && e, ast::OpenVarSet && o, 61 ast::AssertionSet && n, const Cost & c , const Cost & cvt = Cost::zero)62 : expr( x ), cost( c ), cvtCost( cvt ), env( std::move( e ) ), open( std::move( o ) ),58 59 Candidate( 60 const ast::Expr * x, ast::TypeEnvironment && e, ast::OpenVarSet && o, 61 ast::AssertionSet && n, const Cost & c ) 62 : expr( x ), cost( c ), cvtCost( Cost::zero ), env( std::move( e ) ), open( std::move( o ) ), 63 63 need( n.begin(), n.end() ) {} 64 64 }; -
src/SynTree/Constant.cc
r6a1dfda rdc5072f 51 51 } 52 52 53 Constant 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 );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 ); 61 61 } 62 62 -
src/SynTree/Constant.h
r6a1dfda rdc5072f 52 52 static Constant from_double( double d ); 53 53 /// generates an array of chars constant of the given string 54 static Constant from_string( std::string const & cEscapedVal, Type *charType);54 static Constant from_string( std::string const & s ); 55 55 56 56 /// generates a null pointer value for the given type. void * if omitted. -
tests/.in/manipulatorsInput.txt
r6a1dfda rdc5072f 5 5 abcyyy 6 6 aaaaaaaaxxxxxxxxaabbccbbdddwwwbbbbbbbbwwwwwwwwaaaaaaaawwwwwwww 7 abc 7 8 abc 8 9 xx
Note: See TracChangeset
for help on using the changeset viewer.