Changes in src/Parser/ExpressionNode.cc [47534159:2a4b088]
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Parser/ExpressionNode.cc
r47534159 r2a4b088 10 10 // Created On : Sat May 16 13:17:07 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon Oct 5 16:37:24 201513 // Update Count : 2 5512 // Last Modified On : Mon Feb 1 13:32:30 2016 13 // Update Count : 271 14 14 // 15 15 … … 24 24 #include "SynTree/Constant.h" 25 25 #include "SynTree/Expression.h" 26 #include " UnimplementedError.h"26 #include "Common/UnimplementedError.h" 27 27 #include "parseutility.h" 28 #include " utility.h"28 #include "Common/utility.h" 29 29 30 30 using namespace std; … … 91 91 static inline bool checkL( char c ) { return c == 'l' || c == 'L'; } 92 92 static inline bool checkF( char c ) { return c == 'f' || c == 'F'; } 93 static inline bool checkD( char c ) { return c == 'd' || c == 'D'; } 94 static inline bool checkI( char c ) { return c == 'i' || c == 'I'; } 93 95 static inline bool checkX( char c ) { return c == 'x' || c == 'X'; } 94 96 … … 114 116 { BasicType::UnsignedInt, BasicType::LongUnsignedInt, BasicType::LongLongUnsignedInt }, 115 117 }; 116 size_t last = value.length() - 1; // last character of constant117 unsigned long long v; // converted integral value118 118 bool dec = true, Unsigned = false; // decimal, unsigned constant 119 119 int size; // 0 => int, 1 => long, 2 => long long 120 unsigned long long v; // converted integral value 121 size_t last = value.length() - 1; // last character of constant 120 122 121 123 if ( value[0] == '0' ) { // octal constant ? … … 176 178 case Float: 177 179 { 178 size_t len = value.length() - 1; 179 180 btype = BasicType::Double; // default 181 if ( checkF( value[len] ) ) { // float ? 182 btype = BasicType::Float; 183 } // if 184 if ( checkL( value[len] ) ) { // long double ? 185 btype = BasicType::LongDouble; 186 } // if 180 static const BasicType::Kind kind[2][3] = { 181 { BasicType::Float, BasicType::Double, BasicType::LongDouble }, 182 { BasicType::FloatComplex, BasicType::DoubleComplex, BasicType::LongDoubleComplex }, 183 }; 184 bool complx = false; // real, complex 185 int size = 1; // 0 => float, 1 => double (default), 2 => long double 186 // floating-point constant has minimum of 2 characters: 1. or .1 187 size_t last = value.length() - 1; 188 189 if ( checkI( value[last] ) ) { // imaginary ? 190 complx = true; 191 last -= 1; // backup one character 192 } // if 193 if ( checkF( value[last] ) ) { // float ? 194 size = 0; 195 } else if ( checkD( value[last] ) ) { // double ? 196 size = 1; 197 } else if ( checkL( value[last] ) ) { // long double ? 198 size = 2; 199 } // if 200 if ( ! complx && checkI( value[last - 1] ) ) { // imaginary ? 201 complx = true; 202 } // if 203 btype = kind[complx][size]; // lookup constant type 187 204 break; 188 205 } … … 365 382 //############################################################################## 366 383 384 static const char *opName[] = { 385 "TupleC", "Comma", "TupleFieldSel", // "TuplePFieldSel", // n-adic 386 // triadic 387 "Cond", "NCond", 388 // diadic 389 "SizeOf", "AlignOf", "OffsetOf", "Attr", "CompLit", "?+?", "?-?", "?*?", "?/?", "?%?", "||", "&&", 390 "?|?", "?&?", "?^?", "Cast", "?<<?", "?>>?", "?<?", "?>?", "?<=?", "?>=?", "?==?", "?!=?", 391 "?=?", "?*=?", "?/=?", "?%=?", "?+=?", "?-=?", "?<<=?", "?>>=?", "?&=?", "?^=?", "?|=?", 392 "?[?]", "FieldSel", "PFieldSel", "Range", 393 // monadic 394 "+?", "-?", "AddressOf", "*?", "!?", "~?", "++?", "?++", "--?", "?--", "&&" 395 }; 396 367 397 OperatorNode::OperatorNode( Type t ) : type( t ) {} 368 398 … … 378 408 void OperatorNode::printOneLine( std::ostream &os, int indent ) const { 379 409 printDesignation( os ); 380 os << OpName[ type ] << ' ';410 os << opName[ type ] << ' '; 381 411 } 382 412 383 413 void OperatorNode::print( std::ostream &os, int indent ) const{ 384 414 printDesignation( os ); 385 os << string( indent, ' ' ) << "Operator: " << OpName[type] << endl;415 os << string( indent, ' ' ) << "Operator: " << opName[type] << endl; 386 416 return; 387 417 } 388 418 389 419 const char *OperatorNode::get_typename( void ) const{ 390 return OpName[ type ]; 391 } 392 393 const char *OperatorNode::OpName[] = { 394 "TupleC", "Comma", "TupleFieldSel",// "TuplePFieldSel", //n-adic 395 // triadic 396 "Cond", "NCond", 397 // diadic 398 "SizeOf", "AlignOf", "Attr", "CompLit", "Plus", "Minus", "Mul", "Div", "Mod", "Or", 399 "And", "BitOr", "BitAnd", "Xor", "Cast", "LShift", "RShift", "LThan", "GThan", 400 "LEThan", "GEThan", "Eq", "Neq", "Assign", "MulAssn", "DivAssn", "ModAssn", "PlusAssn", 401 "MinusAssn", "LSAssn", "RSAssn", "AndAssn", "ERAssn", "OrAssn", "Index", "FieldSel","PFieldSel", 402 "Range", 403 // monadic 404 "UnPlus", "UnMinus", "AddressOf", "PointTo", "Neg", "BitNeg", "Incr", "IncrPost", "Decr", "DecrPost", "LabelAddress" 405 }; 420 return opName[ type ]; 421 } 406 422 407 423 //############################################################################## … … 439 455 } 440 456 441 // the names that users use to define operator functions 442 static const char *opFuncName[] = { 443 "", "", "", 444 "", "", 445 //diadic 446 "", "", "", "", "?+?", "?-?", "?*?", "?/?", "?%?", "", "", 447 "?|?", "?&?", "?^?", "", "?<<?", "?>>?", "?<?", "?>?", "?<=?", 448 "?>=?", "?==?", "?!=?", "?=?", "?*=?", "?/=?", "?%=?", "?+=?", "?-=?", 449 "?<<=?", "?>>=?", "?&=?", "?^=?", "?|=?", "?[?]", "", "", "Range", 450 //monadic 451 "+?", "-?", "", "*?", "!?", "~?", "++?", "?++", "--?", "?--", "&&" 452 }; 453 454 #include "utility.h" 457 #include "Common/utility.h" 455 458 456 459 Expression *CompositeExprNode::build() const { … … 529 532 case OperatorNode::BitNeg: 530 533 case OperatorNode::LabelAddress: 531 return new UntypedExpr( new NameExpr( op FuncName[ op->get_type() ] ), args );534 return new UntypedExpr( new NameExpr( opName[ op->get_type() ] ), args ); 532 535 case OperatorNode::AddressOf: 533 536 assert( args.size() == 1 ); … … 585 588 return ret; 586 589 } 590 case OperatorNode::SizeOf: 591 { 592 if ( TypeValueNode * arg = dynamic_cast<TypeValueNode *>( get_args()) ) { 593 return new SizeofExpr( arg->get_decl()->buildType()); 594 } else { 595 return new SizeofExpr( args.front()); 596 } // if 597 } 587 598 case OperatorNode::AlignOf: 588 599 { … … 593 604 } // if 594 605 } 595 case OperatorNode::SizeOf: 596 { 597 if ( TypeValueNode * arg = dynamic_cast<TypeValueNode *>( get_args()) ) { 598 return new SizeofExpr( arg->get_decl()->buildType()); 599 } else { 600 return new SizeofExpr( args.front()); 601 } // if 606 case OperatorNode::OffsetOf: 607 { 608 assert( args.size() == 2 ); 609 610 if ( TypeValueNode * arg = dynamic_cast<TypeValueNode *>( get_args() ) ) { 611 NameExpr *member = dynamic_cast<NameExpr *>( args.back() ); 612 assert( member != 0 ); 613 614 return new UntypedOffsetofExpr( arg->get_decl()->buildType(), member->get_name() ); 615 } else assert( false ); 602 616 } 603 617 case OperatorNode::Attr: … … 650 664 default: 651 665 // shouldn't happen 666 assert( false ); 652 667 return 0; 653 668 } // switch … … 660 675 for ( ExpressionNode *cur = arguments; cur != 0; cur = dynamic_cast< ExpressionNode* >( cur->get_link() ) ) { 661 676 cur->printOneLine( os, indent ); 662 } 677 } // for 663 678 os << ") "; 664 679 }
Note:
See TracChangeset
for help on using the changeset viewer.