1*f04bd1c4SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*f04bd1c4SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*f04bd1c4SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*f04bd1c4SAndrew Rist * distributed with this work for additional information 6*f04bd1c4SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*f04bd1c4SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*f04bd1c4SAndrew Rist * "License"); you may not use this file except in compliance 9*f04bd1c4SAndrew Rist * with the License. You may obtain a copy of the License at 10*f04bd1c4SAndrew Rist * 11*f04bd1c4SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12*f04bd1c4SAndrew Rist * 13*f04bd1c4SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*f04bd1c4SAndrew Rist * software distributed under the License is distributed on an 15*f04bd1c4SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*f04bd1c4SAndrew Rist * KIND, either express or implied. See the License for the 17*f04bd1c4SAndrew Rist * specific language governing permissions and limitations 18*f04bd1c4SAndrew Rist * under the License. 19*f04bd1c4SAndrew Rist * 20*f04bd1c4SAndrew Rist *************************************************************/ 21*f04bd1c4SAndrew Rist 22*f04bd1c4SAndrew Rist 23cdf0e10cSrcweir #ifndef _IDLC_ASTEXPRESSION_HXX_ 24cdf0e10cSrcweir #define _IDLC_ASTEXPRESSION_HXX_ 25cdf0e10cSrcweir 26cdf0e10cSrcweir #include <idlc/idlc.hxx> 27cdf0e10cSrcweir 28cdf0e10cSrcweir // Enum to define all the different operators to combine expressions 29cdf0e10cSrcweir enum ExprComb 30cdf0e10cSrcweir { 31cdf0e10cSrcweir EC_add, // '+' 32cdf0e10cSrcweir EC_minus, // '-' 33cdf0e10cSrcweir EC_mul, // '*' 34cdf0e10cSrcweir EC_div, // '/' 35cdf0e10cSrcweir EC_mod, // '%' 36cdf0e10cSrcweir EC_or, // '|' 37cdf0e10cSrcweir EC_xor, // '^' 38cdf0e10cSrcweir EC_and, // '&' 39cdf0e10cSrcweir EC_left, // '<<' 40cdf0e10cSrcweir EC_right, // '>>' 41cdf0e10cSrcweir EC_u_plus, // unary '+' 42cdf0e10cSrcweir EC_u_minus, // unary '-' 43cdf0e10cSrcweir EC_bit_neg, // '~' 44cdf0e10cSrcweir EC_none, // No operator (missing) 45cdf0e10cSrcweir EC_symbol // a symbol (function or constant name) 46cdf0e10cSrcweir }; 47cdf0e10cSrcweir 48cdf0e10cSrcweir // Enum to define the different kinds of evaluation possible 49cdf0e10cSrcweir enum EvalKind 50cdf0e10cSrcweir { 51cdf0e10cSrcweir EK_const, // Must evaluate to constant 52cdf0e10cSrcweir EK_positive_int // Must evaluate to positive integer 53cdf0e10cSrcweir }; 54cdf0e10cSrcweir 55cdf0e10cSrcweir // Enum to define expression type 56cdf0e10cSrcweir enum ExprType 57cdf0e10cSrcweir { 58cdf0e10cSrcweir ET_short, // Expression value is short 59cdf0e10cSrcweir ET_ushort, // Expression value is unsigned short 60cdf0e10cSrcweir ET_long, // Expression value is long 61cdf0e10cSrcweir ET_ulong, // Expression value is unsigned long 62cdf0e10cSrcweir ET_hyper, // Expression value is hyper (64 bit) 63cdf0e10cSrcweir ET_uhyper, // Expression value is unsigned hyper 64cdf0e10cSrcweir ET_float, // Expression value is 32-bit float 65cdf0e10cSrcweir ET_double, // Expression value is 64-bit float 66cdf0e10cSrcweir ET_char, // Expression value is char 67cdf0e10cSrcweir ET_byte, // Expression value is byte 68cdf0e10cSrcweir ET_boolean, // Expression value is boolean 69cdf0e10cSrcweir ET_string, // Expression value is char * 70cdf0e10cSrcweir ET_any, // Expression value is any of above 71cdf0e10cSrcweir ET_void, // Expression value is void (absent) 72cdf0e10cSrcweir ET_type, // Expression value is type 73cdf0e10cSrcweir ET_none // Expression value is missing 74cdf0e10cSrcweir }; 75cdf0e10cSrcweir 76cdf0e10cSrcweir // Structure to describe value of constant expression and its type 77cdf0e10cSrcweir struct AstExprValue 78cdf0e10cSrcweir { 79cdf0e10cSrcweir union 80cdf0e10cSrcweir { 81cdf0e10cSrcweir sal_uInt8 byval; // Contains byte expression value 82cdf0e10cSrcweir sal_Int16 sval; // Contains short expression value 83cdf0e10cSrcweir sal_uInt16 usval; // Contains unsigned short expr value 84cdf0e10cSrcweir sal_Int32 lval; // Contains long expression value 85cdf0e10cSrcweir sal_uInt32 ulval; // Contains unsigned long expr value 86cdf0e10cSrcweir sal_Int64 hval; // Contains hyper expression value 87cdf0e10cSrcweir sal_uInt64 uhval; // Contains unsigned hyper expr value 88cdf0e10cSrcweir sal_Bool bval; // Contains boolean expression value 89cdf0e10cSrcweir float fval; // Contains 32-bit float expr value 90cdf0e10cSrcweir double dval; // Contains 64-bit float expr value 91cdf0e10cSrcweir sal_uInt32 eval; // Contains enumeration value 92cdf0e10cSrcweir } u; 93cdf0e10cSrcweir ExprType et; 94cdf0e10cSrcweir }; 95cdf0e10cSrcweir 96cdf0e10cSrcweir const sal_Char* SAL_CALL exprTypeToString(ExprType t); 97cdf0e10cSrcweir 98cdf0e10cSrcweir class AstExpression 99cdf0e10cSrcweir { 100cdf0e10cSrcweir public: 101cdf0e10cSrcweir // Constructor(s) 102cdf0e10cSrcweir AstExpression(ExprComb c, AstExpression *pExpr1, AstExpression *pExpr2); 103cdf0e10cSrcweir 104cdf0e10cSrcweir AstExpression(sal_Int32 l); 105cdf0e10cSrcweir AstExpression(sal_Int32 l, ExprType et); 106cdf0e10cSrcweir AstExpression(sal_Int64 h); 107cdf0e10cSrcweir AstExpression(sal_uInt64 uh); 108cdf0e10cSrcweir AstExpression(double d); 109cdf0e10cSrcweir AstExpression(::rtl::OString* scopedName); 110cdf0e10cSrcweir 111cdf0e10cSrcweir virtual ~AstExpression(); 112cdf0e10cSrcweir 113cdf0e10cSrcweir // Data Accessors getScope()114cdf0e10cSrcweir AstScope* getScope() 115cdf0e10cSrcweir { return m_pScope; } setScope(AstScope * pScope)116cdf0e10cSrcweir void setScope(AstScope* pScope) 117cdf0e10cSrcweir { m_pScope = pScope; } getLine()118cdf0e10cSrcweir sal_Int32 getLine() 119cdf0e10cSrcweir { return m_lineNo; } setLine(sal_Int32 l)120cdf0e10cSrcweir void setLine(sal_Int32 l) 121cdf0e10cSrcweir { m_lineNo = l; } getFileName()122cdf0e10cSrcweir const ::rtl::OString& getFileName() 123cdf0e10cSrcweir { return m_fileName; } setFileName(const::rtl::OString & fileName)124cdf0e10cSrcweir void setFileName(const ::rtl::OString& fileName) 125cdf0e10cSrcweir { m_fileName = fileName; } getCombOperator()126cdf0e10cSrcweir ExprComb getCombOperator() 127cdf0e10cSrcweir { return m_combOperator; } setCombOperator(ExprComb new_ec)128cdf0e10cSrcweir void setCombOperator(ExprComb new_ec) 129cdf0e10cSrcweir { m_combOperator = new_ec; } getExprValue()130cdf0e10cSrcweir AstExprValue* getExprValue() 131cdf0e10cSrcweir { return m_exprValue; } setExprValue(AstExprValue * pEv)132cdf0e10cSrcweir void setExprValue(AstExprValue *pEv) 133cdf0e10cSrcweir { m_exprValue = pEv; } getExpr1()134cdf0e10cSrcweir AstExpression* getExpr1() 135cdf0e10cSrcweir { return m_subExpr1; } setExpr1(AstExpression * pExpr)136cdf0e10cSrcweir void setExpr1(AstExpression *pExpr) 137cdf0e10cSrcweir { m_subExpr1 = pExpr; } getExpr2()138cdf0e10cSrcweir AstExpression* getExpr2() 139cdf0e10cSrcweir { return m_subExpr2; } setExpr2(AstExpression * pExpr)140cdf0e10cSrcweir void setExpr2(AstExpression *pExpr) 141cdf0e10cSrcweir { m_subExpr2 = pExpr; } getSymbolicName()142cdf0e10cSrcweir ::rtl::OString* getSymbolicName() 143cdf0e10cSrcweir { return m_pSymbolicName; } setSymbolicName(::rtl::OString * pSymbolicName)144cdf0e10cSrcweir void setSymbolicName(::rtl::OString* pSymbolicName) 145cdf0e10cSrcweir { m_pSymbolicName = pSymbolicName; } 146cdf0e10cSrcweir 147cdf0e10cSrcweir // Evaluation and value coercion 148cdf0e10cSrcweir AstExprValue* coerce(ExprType type, sal_Bool bAssign=sal_True); 149cdf0e10cSrcweir 150cdf0e10cSrcweir // Evaluate then store value inside this AstExpression 151cdf0e10cSrcweir void evaluate(EvalKind ek); 152cdf0e10cSrcweir 153cdf0e10cSrcweir // Compare to AstExpressions 154cdf0e10cSrcweir sal_Bool operator==(AstExpression *pExpr); 155cdf0e10cSrcweir sal_Bool compare(AstExpression *pExpr); 156cdf0e10cSrcweir 157cdf0e10cSrcweir ::rtl::OString toString(); dump()158cdf0e10cSrcweir void dump() {} 159cdf0e10cSrcweir private: 160cdf0e10cSrcweir // Fill out the lineno, filename and definition scope details 161cdf0e10cSrcweir void fillDefinitionDetails(); 162cdf0e10cSrcweir // Internal evaluation 163cdf0e10cSrcweir AstExprValue* eval_internal(EvalKind ek); 164cdf0e10cSrcweir // Evaluate different sets of operators 165cdf0e10cSrcweir AstExprValue* eval_bin_op(EvalKind ek); 166cdf0e10cSrcweir AstExprValue* eval_bit_op(EvalKind ek); 167cdf0e10cSrcweir AstExprValue* eval_un_op(EvalKind ek); 168cdf0e10cSrcweir AstExprValue* eval_symbol(EvalKind ek); 169cdf0e10cSrcweir 170cdf0e10cSrcweir AstScope* m_pScope; // scope defined in 171cdf0e10cSrcweir sal_Int32 m_lineNo; // line number defined in 172cdf0e10cSrcweir ::rtl::OString m_fileName; // fileName defined in 173cdf0e10cSrcweir 174cdf0e10cSrcweir ExprComb m_combOperator; 175cdf0e10cSrcweir AstExpression* m_subExpr1; 176cdf0e10cSrcweir AstExpression* m_subExpr2; 177cdf0e10cSrcweir AstExprValue* m_exprValue; 178cdf0e10cSrcweir ::rtl::OString* m_pSymbolicName; 179cdf0e10cSrcweir }; 180cdf0e10cSrcweir 181cdf0e10cSrcweir #endif // _IDLC_ASTEXPRESSION_HXX_ 182cdf0e10cSrcweir 183