LCOV - code coverage report
Current view: top level - idlc/inc/idlc - astexpression.hxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 6 8 75.0 %
Date: 2012-08-25 Functions: 3 4 75.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 0 -

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

Generated by: LCOV version 1.10