Changes in src/Parser/ExpressionNode.cc [2a4b088:47534159]
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Parser/ExpressionNode.cc
r2a4b088 r47534159 10 10 // Created On : Sat May 16 13:17:07 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon Feb 1 13:32:30 201613 // Update Count : 2 7112 // Last Modified On : Mon Oct 5 16:37:24 2015 13 // Update Count : 255 14 14 // 15 15 … … 24 24 #include "SynTree/Constant.h" 25 25 #include "SynTree/Expression.h" 26 #include " Common/UnimplementedError.h"26 #include "UnimplementedError.h" 27 27 #include "parseutility.h" 28 #include " Common/utility.h"28 #include "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'; }95 93 static inline bool checkX( char c ) { return c == 'x' || c == 'X'; } 96 94 … … 116 114 { BasicType::UnsignedInt, BasicType::LongUnsignedInt, BasicType::LongLongUnsignedInt }, 117 115 }; 116 size_t last = value.length() - 1; // last character of constant 117 unsigned long long v; // converted integral value 118 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 value121 size_t last = value.length() - 1; // last character of constant122 120 123 121 if ( value[0] == '0' ) { // octal constant ? … … 178 176 case Float: 179 177 { 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 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 204 187 break; 205 188 } … … 382 365 //############################################################################## 383 366 384 static const char *opName[] = {385 "TupleC", "Comma", "TupleFieldSel", // "TuplePFieldSel", // n-adic386 // triadic387 "Cond", "NCond",388 // diadic389 "SizeOf", "AlignOf", "OffsetOf", "Attr", "CompLit", "?+?", "?-?", "?*?", "?/?", "?%?", "||", "&&",390 "?|?", "?&?", "?^?", "Cast", "?<<?", "?>>?", "?<?", "?>?", "?<=?", "?>=?", "?==?", "?!=?",391 "?=?", "?*=?", "?/=?", "?%=?", "?+=?", "?-=?", "?<<=?", "?>>=?", "?&=?", "?^=?", "?|=?",392 "?[?]", "FieldSel", "PFieldSel", "Range",393 // monadic394 "+?", "-?", "AddressOf", "*?", "!?", "~?", "++?", "?++", "--?", "?--", "&&"395 };396 397 367 OperatorNode::OperatorNode( Type t ) : type( t ) {} 398 368 … … 408 378 void OperatorNode::printOneLine( std::ostream &os, int indent ) const { 409 379 printDesignation( os ); 410 os << opName[ type ] << ' ';380 os << OpName[ type ] << ' '; 411 381 } 412 382 413 383 void OperatorNode::print( std::ostream &os, int indent ) const{ 414 384 printDesignation( os ); 415 os << string( indent, ' ' ) << "Operator: " << opName[type] << endl;385 os << string( indent, ' ' ) << "Operator: " << OpName[type] << endl; 416 386 return; 417 387 } 418 388 419 389 const char *OperatorNode::get_typename( void ) const{ 420 return opName[ type ]; 421 } 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 }; 422 406 423 407 //############################################################################## … … 455 439 } 456 440 457 #include "Common/utility.h" 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" 458 455 459 456 Expression *CompositeExprNode::build() const { … … 532 529 case OperatorNode::BitNeg: 533 530 case OperatorNode::LabelAddress: 534 return new UntypedExpr( new NameExpr( op Name[ op->get_type() ] ), args );531 return new UntypedExpr( new NameExpr( opFuncName[ op->get_type() ] ), args ); 535 532 case OperatorNode::AddressOf: 536 533 assert( args.size() == 1 ); … … 588 585 return ret; 589 586 } 587 case OperatorNode::AlignOf: 588 { 589 if ( TypeValueNode * arg = dynamic_cast<TypeValueNode *>( get_args()) ) { 590 return new AlignofExpr( arg->get_decl()->buildType()); 591 } else { 592 return new AlignofExpr( args.front()); 593 } // if 594 } 590 595 case OperatorNode::SizeOf: 591 596 { … … 595 600 return new SizeofExpr( args.front()); 596 601 } // if 597 }598 case OperatorNode::AlignOf:599 {600 if ( TypeValueNode * arg = dynamic_cast<TypeValueNode *>( get_args()) ) {601 return new AlignofExpr( arg->get_decl()->buildType());602 } else {603 return new AlignofExpr( args.front());604 } // if605 }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 );616 602 } 617 603 case OperatorNode::Attr: … … 664 650 default: 665 651 // shouldn't happen 666 assert( false );667 652 return 0; 668 653 } // switch … … 675 660 for ( ExpressionNode *cur = arguments; cur != 0; cur = dynamic_cast< ExpressionNode* >( cur->get_link() ) ) { 676 661 cur->printOneLine( os, indent ); 677 } // for662 } 678 663 os << ") "; 679 664 }
Note:
See TracChangeset
for help on using the changeset viewer.