00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 #ifndef COMMA_BASIC_PRIMITIVEOPS_HDR_GUARD
00010 #define COMMA_BASIC_PRIMITIVEOPS_HDR_GUARD
00011 
00012 #include "llvm/ADT/StringRef.h"
00013 
00014 namespace comma {
00015 
00016 class IdentifierInfo;
00017 
00018 namespace primitive_ops {
00019 
00020 enum PrimitiveID {
00021 
00022     NotPrimitive,
00023 
00024     
00025     
00026     
00027     ADD_op,
00028     SUB_op,
00029     MUL_op,
00030     DIV_op,
00031     MOD_op,
00032     REM_op,
00033     POW_op,
00034 
00035     
00036     
00037     
00038     EQ_op,
00039     NE_op,
00040     LT_op,
00041     GT_op,
00042     LE_op,
00043     GE_op,
00044     LOR_op,
00045     LAND_op,
00046     LXOR_op,
00047 
00048     
00049     
00050     
00051     LNOT_op,
00052 
00053     
00054     
00055     POS_op,
00056     NEG_op,
00057 
00058     
00059     
00060     
00061     ENUM_op,
00062 
00063     
00064     FIRST_PREDICATE_OP = EQ_op,
00065     LAST_PREDICATE_OP = LNOT_op,
00066 
00067     FIRST_PRIMITIVE_OP = ADD_op,
00068     LAST_PRIMITIVE_OP = ENUM_op,
00069 
00070     FIRST_BINARY_OP = ADD_op,
00071     LAST_BINARY_OP = LXOR_op,
00072 
00073     FIRST_UNARY_OP = LNOT_op,
00074     LAST_UNARY_OP = NEG_op
00075 };
00076 
00078 inline bool denotesOperator(PrimitiveID ID) {
00079     return (FIRST_PRIMITIVE_OP <= ID) && (ID <= LAST_PRIMITIVE_OP);
00080 }
00081 
00083 inline bool denotesPredicateOp(PrimitiveID ID) {
00084     return (FIRST_PREDICATE_OP <= ID) && (ID <= LAST_PREDICATE_OP);
00085 }
00086 
00088 inline bool denotesUnaryOp(PrimitiveID ID) {
00089     return (FIRST_UNARY_OP <= ID) && (ID <= LAST_UNARY_OP);
00090 }
00091 
00093 inline bool denotesBinaryOp(PrimitiveID ID) {
00094     return (FIRST_BINARY_OP <= ID) && (ID <= LAST_BINARY_OP);
00095 }
00096 
00098 bool denotesBinaryOp(const llvm::StringRef &string);
00099 
00101 bool denotesUnaryOp(const llvm::StringRef &string);
00102 
00104 bool denotesOperator(const llvm::StringRef &string);
00105 
00107 bool denotesBinaryOp(const comma::IdentifierInfo *idInfo);
00108 
00110 bool denotesUnaryOp(const comma::IdentifierInfo *idInfo);
00111 
00113 bool denotesOperator(const comma::IdentifierInfo *idInfo);
00114 
00116 inline const char *getOpName(PrimitiveID ID) {
00117     switch (ID) {
00118     default:
00119         assert(false && "Not a primitive operator!");
00120         return 0;
00121     case EQ_op: return "=";
00122     case NE_op: return "/=";
00123     case LT_op: return "<";
00124     case GT_op: return ">";
00125     case LE_op: return "<=";
00126     case GE_op: return ">=";
00127     case ADD_op: return "+";
00128     case SUB_op: return "-";
00129     case MUL_op: return "*";
00130     case DIV_op: return "/";
00131     case MOD_op: return "mod";
00132     case REM_op: return "rem";
00133     case POW_op: return "**";
00134     case POS_op: return "+";
00135     case NEG_op: return "-";
00136     case LOR_op: return "or";
00137     case LAND_op: return "and";
00138     case LNOT_op: return "not";
00139     case LXOR_op: return "xor";
00140     }
00141 }
00142 
00143 } 
00144 
00145 namespace PO = primitive_ops;
00146 
00147 } 
00148 
00149 #endif