Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/ExpressionNode.cc

    r2a4b088 r47534159  
    1010// Created On       : Sat May 16 13:17:07 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Mon Feb  1 13:32:30 2016
    13 // Update Count     : 271
     12// Last Modified On : Mon Oct  5 16:37:24 2015
     13// Update Count     : 255
    1414//
    1515
     
    2424#include "SynTree/Constant.h"
    2525#include "SynTree/Expression.h"
    26 #include "Common/UnimplementedError.h"
     26#include "UnimplementedError.h"
    2727#include "parseutility.h"
    28 #include "Common/utility.h"
     28#include "utility.h"
    2929
    3030using namespace std;
     
    9191static inline bool checkL( char c ) { return c == 'l' || c == 'L'; }
    9292static 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'; }
    9593static inline bool checkX( char c ) { return c == 'x' || c == 'X'; }
    9694
     
    116114                                { BasicType::UnsignedInt, BasicType::LongUnsignedInt, BasicType::LongLongUnsignedInt },
    117115                        };
     116                        size_t last = value.length() - 1;                       // last character of constant
     117                        unsigned long long v;                                           // converted integral value
    118118                        bool dec = true, Unsigned = false;                      // decimal, unsigned constant
    119119                        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
    122120
    123121                        if ( value[0] == '0' ) {                                        // octal constant ?
     
    178176          case Float:
    179177                {
    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
    204187                        break;
    205188                }
     
    382365//##############################################################################
    383366
    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 
    397367OperatorNode::OperatorNode( Type t ) : type( t ) {}
    398368
     
    408378void OperatorNode::printOneLine( std::ostream &os, int indent ) const {
    409379        printDesignation( os );
    410         os << opName[ type ] << ' ';
     380        os << OpName[ type ] << ' ';
    411381}
    412382
    413383void OperatorNode::print( std::ostream &os, int indent ) const{
    414384        printDesignation( os );
    415         os << string( indent, ' ' ) << "Operator: " << opName[type] << endl;
     385        os << string( indent, ' ' ) << "Operator: " << OpName[type] << endl;
    416386        return;
    417387}
    418388
    419389const char *OperatorNode::get_typename( void ) const{
    420         return opName[ type ];
    421 }
     390        return OpName[ type ];
     391}
     392
     393const 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};
    422406
    423407//##############################################################################
     
    455439}
    456440
    457 #include "Common/utility.h"
     441// the names that users use to define operator functions
     442static const char *opFuncName[] = {
     443        "",             "",             "",
     444        "",             "",
     445        //diadic
     446        "",             "",             "",             "",             "?+?",          "?-?",  "?*?",  "?/?",  "?%?",  "",              "",
     447        "?|?",          "?&?",          "?^?",  "",             "?<<?", "?>>?", "?<?",  "?>?",  "?<=?",
     448        "?>=?",         "?==?",         "?!=?", "?=?",  "?*=?", "?/=?", "?%=?", "?+=?", "?-=?",
     449        "?<<=?",        "?>>=?",        "?&=?", "?^=?", "?|=?", "?[?]", "",             "",             "Range",
     450        //monadic
     451        "+?",           "-?",           "",             "*?",   "!?",   "~?",   "++?",  "?++",  "--?",  "?--",  "&&"
     452};
     453
     454#include "utility.h"
    458455
    459456Expression *CompositeExprNode::build() const {
     
    532529          case OperatorNode::BitNeg:
    533530          case OperatorNode::LabelAddress:
    534                 return new UntypedExpr( new NameExpr( opName[ op->get_type() ] ), args );
     531                return new UntypedExpr( new NameExpr( opFuncName[ op->get_type() ] ), args );
    535532          case OperatorNode::AddressOf:
    536533                assert( args.size() == 1 );
     
    588585                        return ret;
    589586                }
     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                }
    590595          case OperatorNode::SizeOf:
    591596                {
     
    595600                                return new SizeofExpr( args.front());
    596601                        } // 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                         } // if
    605                 }
    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 );
    616602                }
    617603          case OperatorNode::Attr:
     
    664650          default:
    665651                // shouldn't happen
    666                 assert( false );
    667652                return 0;
    668653        } // switch
     
    675660        for ( ExpressionNode *cur = arguments; cur != 0; cur = dynamic_cast< ExpressionNode* >( cur->get_link() ) ) {
    676661                cur->printOneLine( os, indent );
    677         } // for
     662        }
    678663        os << ") ";
    679664}
Note: See TracChangeset for help on using the changeset viewer.