| [51587aa] | 1 | // | 
|---|
|  | 2 | // Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo | 
|---|
|  | 3 | // | 
|---|
|  | 4 | // The contents of this file are covered under the licence agreement in the | 
|---|
|  | 5 | // file "LICENCE" distributed with Cforall. | 
|---|
|  | 6 | // | 
|---|
| [6943f051] | 7 | // OperatorTable.cc -- | 
|---|
| [51587aa] | 8 | // | 
|---|
|  | 9 | // Author           : Richard C. Bilson | 
|---|
|  | 10 | // Created On       : Mon May 18 07:44:20 2015 | 
|---|
| [58dd019] | 11 | // Last Modified By : Peter A. Buhr | 
|---|
| [60a8062] | 12 | // Last Modified On : Tue Feb 18 15:55:01 2020 | 
|---|
|  | 13 | // Update Count     : 55 | 
|---|
| [51587aa] | 14 | // | 
|---|
| [51b73452] | 15 |  | 
|---|
| [bff227f] | 16 | #include <algorithm>  // for any_of | 
|---|
|  | 17 | #include <map>        // for map, _Rb_tree_const_iterator, map<>::const_iterator | 
|---|
|  | 18 | #include <utility>    // for pair | 
|---|
| [60a8062] | 19 | using namespace std; | 
|---|
| [bf2438c] | 20 |  | 
|---|
| [51b73452] | 21 | #include "OperatorTable.h" | 
|---|
| [bc3127d] | 22 | #include "Common/utility.h" | 
|---|
| [51b73452] | 23 |  | 
|---|
|  | 24 | namespace CodeGen { | 
|---|
| [60a8062] | 25 | const OperatorInfo CodeGen::tableValues[] = { | 
|---|
|  | 26 | // inputName symbol   outputName                     friendlyName                  type | 
|---|
|  | 27 | {       "?[?]",   "",     "_operator_index",             "Index",                      OT_INDEX          }, | 
|---|
|  | 28 | {       "?{}",    "=",    "_constructor",                "Constructor",                OT_CTOR           }, | 
|---|
|  | 29 | {       "^?{}",   "",     "_destructor",                 "Destructor",                 OT_DTOR           }, | 
|---|
|  | 30 | {       "?()",    "",     "_operator_call",              "Call Operator",              OT_CALL           }, | 
|---|
|  | 31 | {       "?++",    "++",   "_operator_postincr",          "Postfix Increment",          OT_POSTFIXASSIGN  }, | 
|---|
|  | 32 | {       "?--",    "--",   "_operator_postdecr",          "Postfix Decrement",          OT_POSTFIXASSIGN  }, | 
|---|
|  | 33 | {       "*?",     "*",    "_operator_deref",             "Dereference",                OT_PREFIX         }, | 
|---|
|  | 34 | {       "+?",     "+",    "_operator_unaryplus",         "Plus",                       OT_PREFIX         }, | 
|---|
|  | 35 | {       "-?",     "-",    "_operator_unaryminus",        "Minus",                      OT_PREFIX         }, | 
|---|
|  | 36 | {       "~?",     "~",    "_operator_bitnot",            "Bitwise Not",                OT_PREFIX         }, | 
|---|
|  | 37 | {       "!?",     "!",    "_operator_lognot",            "Logical Not",                OT_PREFIX         }, | 
|---|
|  | 38 | {       "++?",    "++",   "_operator_preincr",           "Prefix Increment",           OT_PREFIXASSIGN   }, | 
|---|
|  | 39 | {       "--?",    "--",   "_operator_predecr",           "Prefix Decrement",           OT_PREFIXASSIGN   }, | 
|---|
|  | 40 | {       "?\\?",   "\\",   "_operator_exponential",       "Exponentiation",             OT_INFIX          }, | 
|---|
|  | 41 | {       "?*?",    "*",    "_operator_multiply",          "Multiplication",             OT_INFIX          }, | 
|---|
|  | 42 | {       "?/?",    "/",    "_operator_divide",            "Division",                   OT_INFIX          }, | 
|---|
|  | 43 | {       "?%?",    "%",    "_operator_modulus",           "Modulo",                     OT_INFIX          }, | 
|---|
|  | 44 | {       "?+?",    "+",    "_operator_add",               "Addition",                   OT_INFIX          }, | 
|---|
|  | 45 | {       "?-?",    "-",    "_operator_subtract",          "Substraction",               OT_INFIX          }, | 
|---|
|  | 46 | {       "?<<?",   "<<",   "_operator_shiftleft",         "Shift Left",                 OT_INFIX          }, | 
|---|
|  | 47 | {       "?>>?",   ">>",   "_operator_shiftright",        "Shift Right",                OT_INFIX          }, | 
|---|
|  | 48 | {       "?<?",    "<",    "_operator_less",              "Less-than",                  OT_INFIX          }, | 
|---|
|  | 49 | {       "?>?",    ">",    "_operator_greater",           "Greater-than",               OT_INFIX          }, | 
|---|
|  | 50 | {       "?<=?",   "<=",   "_operator_lessequal",         "Less-than-or-Equal",         OT_INFIX          }, | 
|---|
|  | 51 | {       "?>=?",   ">=",   "_operator_greaterequal",      "Greater-than-or-Equal",      OT_INFIX          }, | 
|---|
|  | 52 | {       "?==?",   "==",   "_operator_equal",             "Equality",                   OT_INFIX          }, | 
|---|
|  | 53 | {       "?!=?",   "!=",   "_operator_notequal",          "Not-Equal",                  OT_INFIX          }, | 
|---|
|  | 54 | {       "?&?",    "&",    "_operator_bitand",            "Bitwise And",                OT_INFIX          }, | 
|---|
|  | 55 | {       "?^?",    "^",    "_operator_bitxor",            "Bitwise Xor",                OT_INFIX          }, | 
|---|
|  | 56 | {       "?|?",    "|",    "_operator_bitor",             "Bitwise Or",                 OT_INFIX          }, | 
|---|
|  | 57 | {       "?=?",    "=",    "_operator_assign",            "Assignment",                 OT_INFIXASSIGN    }, | 
|---|
|  | 58 | {       "?\\=?",  "\\=",  "_operator_expassign",         "Exponentiation Assignment",  OT_INFIXASSIGN    }, | 
|---|
|  | 59 | {       "?*=?",   "*=",   "_operator_multassign",        "Multiplication Assignment",  OT_INFIXASSIGN    }, | 
|---|
|  | 60 | {       "?/=?",   "/=",   "_operator_divassign",         "Division Assignment",        OT_INFIXASSIGN    }, | 
|---|
|  | 61 | {       "?%=?",   "%=",   "_operator_modassign",         "Modulo Assignment",          OT_INFIXASSIGN    }, | 
|---|
|  | 62 | {       "?+=?",   "+=",   "_operator_addassign",         "Addition Assignment",        OT_INFIXASSIGN    }, | 
|---|
|  | 63 | {       "?-=?",   "-=",   "_operator_subassign",         "Substrction Assignment",     OT_INFIXASSIGN    }, | 
|---|
|  | 64 | {       "?<<=?",  "<<=",  "_operator_shiftleftassign",   "Shift Left Assignment",      OT_INFIXASSIGN    }, | 
|---|
|  | 65 | {       "?>>=?",  ">>=",  "_operator_shiftrightassign",  "Shift Right Assignment",     OT_INFIXASSIGN    }, | 
|---|
|  | 66 | {       "?&=?",   "&=",   "_operator_bitandassign",      "Bitwise And Assignment",     OT_INFIXASSIGN    }, | 
|---|
|  | 67 | {       "?^=?",   "^=",   "_operator_bitxorassign",      "Bitwise Xor Assignment",     OT_INFIXASSIGN    }, | 
|---|
|  | 68 | {       "?|=?",   "|=",   "_operator_bitorassign",       "Bitwise Or Assignment",      OT_INFIXASSIGN    }, | 
|---|
|  | 69 | }; // tableValues | 
|---|
|  | 70 |  | 
|---|
|  | 71 | std::map< std::string, OperatorInfo > CodeGen::table; | 
|---|
|  | 72 |  | 
|---|
|  | 73 | CodeGen::CodeGen() { | 
|---|
|  | 74 | enum { numOps = sizeof( tableValues ) / sizeof( OperatorInfo ) }; | 
|---|
|  | 75 | for ( int i = 0; i < numOps; i += 1 ) { | 
|---|
|  | 76 | table[ tableValues[i].inputName ] = tableValues[i]; | 
|---|
|  | 77 | } // for | 
|---|
|  | 78 | } | 
|---|
| [bc3127d] | 79 |  | 
|---|
| [60a8062] | 80 | const OperatorInfo * operatorLookup( const string & funcName ) { | 
|---|
|  | 81 | if ( funcName.find_first_of( "?^*+-!", 0, 1 ) == string::npos ) return nullptr; // prefilter | 
|---|
|  | 82 | const OperatorInfo * ret = &CodeGen::table.find( funcName )->second; // must be in the table | 
|---|
|  | 83 | assert( ret ); | 
|---|
|  | 84 | return ret; | 
|---|
| [51587aa] | 85 | } | 
|---|
| [bff227f] | 86 |  | 
|---|
| [60a8062] | 87 | bool isOperator( const string & funcName ) { | 
|---|
|  | 88 | return operatorLookup( funcName ) != nullptr; | 
|---|
| [3d2b7bc] | 89 | } | 
|---|
|  | 90 |  | 
|---|
| [60a8062] | 91 | string operatorFriendlyName( const string & funcName ) { | 
|---|
|  | 92 | const OperatorInfo * info = operatorLookup( funcName ); | 
|---|
|  | 93 | if ( info ) return info->friendlyName; | 
|---|
| [98538288] | 94 | return ""; | 
|---|
|  | 95 | } | 
|---|
|  | 96 |  | 
|---|
| [60a8062] | 97 | bool isConstructor( const string & funcName ) { | 
|---|
|  | 98 | const OperatorInfo * info = operatorLookup( funcName ); | 
|---|
|  | 99 | if ( info ) return info->type == OT_CTOR; | 
|---|
| [bff227f] | 100 | return false; | 
|---|
|  | 101 | } | 
|---|
|  | 102 |  | 
|---|
| [60a8062] | 103 | bool isDestructor( const string & funcName ) { | 
|---|
|  | 104 | const OperatorInfo * info = operatorLookup( funcName ); | 
|---|
|  | 105 | if ( info ) return info->type == OT_DTOR; | 
|---|
|  | 106 | return false; | 
|---|
| [bff227f] | 107 | } | 
|---|
|  | 108 |  | 
|---|
| [60a8062] | 109 | bool isCtorDtor( const string & funcName ) { | 
|---|
|  | 110 | const OperatorInfo * info = operatorLookup( funcName ); | 
|---|
|  | 111 | if ( info ) return info->type <= OT_CONSTRUCTOR; | 
|---|
|  | 112 | return false; | 
|---|
| [bff227f] | 113 | } | 
|---|
|  | 114 |  | 
|---|
| [60a8062] | 115 | bool isAssignment( const string & funcName ) { | 
|---|
|  | 116 | const OperatorInfo * info = operatorLookup( funcName ); | 
|---|
|  | 117 | if ( info ) return info->type > OT_CONSTRUCTOR && info->type <= OT_ASSIGNMENT; | 
|---|
|  | 118 | return false; | 
|---|
| [bff227f] | 119 | } | 
|---|
|  | 120 |  | 
|---|
| [60a8062] | 121 | bool isCtorDtorAssign( const string & funcName ) { | 
|---|
|  | 122 | const OperatorInfo * info = operatorLookup( funcName ); | 
|---|
|  | 123 | if ( info ) return info->type <= OT_ASSIGNMENT; | 
|---|
|  | 124 | return false; | 
|---|
| [bff227f] | 125 | } | 
|---|
|  | 126 |  | 
|---|
| [60a8062] | 127 | CodeGen codegen;                                                                        // initialize singleton package | 
|---|
| [51b73452] | 128 | } // namespace CodeGen | 
|---|
| [51587aa] | 129 |  | 
|---|
|  | 130 | // Local Variables: // | 
|---|
|  | 131 | // tab-width: 4 // | 
|---|
|  | 132 | // End: // | 
|---|