LCOV - code coverage report
Current view: top level - basic/source/inc - expr.hxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 35 41 85.4 %
Date: 2014-11-03 Functions: 33 40 82.5 %
Legend: Lines: hit not hit

          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             : 
      20             : #ifndef INCLUDED_BASIC_SOURCE_INC_EXPR_HXX
      21             : #define INCLUDED_BASIC_SOURCE_INC_EXPR_HXX
      22             : 
      23             : #include "opcodes.hxx"
      24             : #include "token.hxx"
      25             : 
      26             : class SbiExprNode;
      27             : class SbiExpression;
      28             : class SbiExprList;
      29             : class SbiDimList;
      30             : class SbiParameters;
      31             : class SbiParser;
      32             : class SbiCodeGen;
      33             : class SbiSymDef;
      34             : class SbiProcDef;
      35             : 
      36             : 
      37             : #include <vector>
      38             : typedef ::std::vector<SbiExprList*> SbiExprListVector;
      39             : 
      40             : struct SbVar {
      41             :     SbiExprNode*        pNext;      // next element (for structures)
      42             :     SbiSymDef*          pDef;       // symbol definition
      43             :     SbiExprList*        pPar;       // optional parameters (is deleted)
      44             :     SbiExprListVector*  pvMorePar;  // Array of arrays foo(pPar)(avMorePar[0])(avMorePar[1])...
      45             : };
      46             : 
      47           0 : struct KeywordSymbolInfo
      48             : {
      49             :     OUString m_aKeywordSymbol;
      50             :     SbxDataType     m_eSbxDataType;
      51             :     SbiToken        m_eTok;
      52             : };
      53             : 
      54             : enum SbiExprType {                  // expression types:
      55             :     SbSTDEXPR,                      // normal expression
      56             :     SbLVALUE,                       // any lValue
      57             :     SbSYMBOL,                       // any composite symbol
      58             :     SbOPERAND                       // variable/function
      59             : };
      60             : 
      61             : enum SbiExprMode {                  // Expression context:
      62             :     EXPRMODE_STANDARD,              // default
      63             :     EXPRMODE_STANDALONE,            // a param1, param2 OR a( param1, param2 ) = 42
      64             :     EXPRMODE_LPAREN_PENDING,        // start of parameter list with bracket, special handling
      65             :     EXPRMODE_LPAREN_NOT_NEEDED,     // pending LPAREN has not been used
      66             :     EXPRMODE_ARRAY_OR_OBJECT,       // '=' or '(' or '.' found after ')' on ParenLevel 0, stopping
      67             :                                     // expression, assuming array syntax a(...)[(...)] = ?
      68             :                                     // or a(...).b(...)
      69             :     EXPRMODE_EMPTY_PAREN            // It turned out that the paren don't contain anything: a()
      70             : };
      71             : 
      72             : enum SbiNodeType {
      73             :     SbxNUMVAL,                      // nVal = value
      74             :     SbxSTRVAL,                      // aStrVal = value, before #i59791/#i45570: nStringId = value
      75             :     SbxVARVAL,                      // aVar = value
      76             :     SbxTYPEOF,                      // TypeOf ObjExpr Is Type
      77             :     SbxNODE,                        // Node
      78             :     SbxNEW,                         // new <type> expression
      79             :     SbxDUMMY
      80             : };
      81             : 
      82             : enum RecursiveMode
      83             : {
      84             :     UNDEFINED,
      85             :     FORCE_CALL,
      86             :     PREVENT_CALL
      87             : };
      88             : 
      89             : class SbiExprNode {                  // operators (and operands)
      90             :     friend class SbiExpression;
      91             :     friend class SbiConstExpression;
      92             :     union {
      93             :         sal_uInt16 nTypeStrId;          // pooled String-ID, #i59791/#i45570 Now only for TypeOf
      94             :         double nVal;                // numeric value
      95             :         SbVar  aVar;                // or variable
      96             :     };
      97             :     OUString aStrVal;               // #i59791/#i45570 Store string directly
      98             :     SbiExprNode* pLeft;             // right branch
      99             :     SbiExprNode* pRight;            // right branch (NULL for unary ops)
     100             :     SbiExprNode* pWithParent;       // node, whose member is "this per with"
     101             :     SbiCodeGen*  pGen;              // code-generator
     102             :     SbiNodeType  eNodeType;
     103             :     SbxDataType eType;
     104             :     SbiToken     eTok;
     105             :     bool  bError;                   // true: error
     106             :     void  FoldConstants();
     107             :     void  CollectBits();            // converting numbers to strings
     108       52670 :     bool  IsOperand()
     109       52670 :         { return eNodeType != SbxNODE && eNodeType != SbxTYPEOF && eNodeType != SbxNEW; }
     110        5602 :     bool  IsTypeOf()
     111        5602 :         { return eNodeType == SbxTYPEOF; }
     112        5602 :     bool  IsNew()
     113        5602 :         { return eNodeType == SbxNEW; }
     114             :     bool  IsNumber();
     115             :     bool  IsLvalue();               // true, if usable as Lvalue
     116             :     void  GenElement( SbiOpcode );
     117             :     void  BaseInit( SbiParser* p ); // help function for Ctor, from 17.12.95
     118             : public:
     119             :     SbiExprNode( void );
     120             :     SbiExprNode( SbiParser*, double, SbxDataType );
     121             :     SbiExprNode( SbiParser*, const OUString& );
     122             :     SbiExprNode( SbiParser*, const SbiSymDef&, SbxDataType, SbiExprList* = NULL );
     123             :     SbiExprNode( SbiParser*, SbiExprNode*, SbiToken, SbiExprNode* );
     124             :     SbiExprNode( SbiParser*, SbiExprNode*, sal_uInt16 );    // #120061 TypeOf
     125             :     SbiExprNode( SbiParser*, sal_uInt16 );                  // new <type>
     126             :     virtual ~SbiExprNode();
     127             : 
     128        9554 :     bool IsValid()                  { return !bError; }
     129       41454 :     bool IsConstant()               // true: constant operand
     130       41454 :         { return eNodeType == SbxSTRVAL || eNodeType == SbxNUMVAL; }
     131             :     bool IsIntConst();
     132             :     bool IsVariable();
     133             : 
     134       17882 :     SbiExprNode* GetWithParent()            { return pWithParent; }
     135         106 :     void SetWithParent( SbiExprNode* p )    { pWithParent = p; }
     136             : 
     137       35368 :     SbxDataType GetType()           { return eType; }
     138          28 :     void SetType( SbxDataType eTp ) { eType = eTp; }
     139           0 :     SbiNodeType GetNodeType()       { return eNodeType; }
     140             :     SbiSymDef* GetVar();
     141             :     SbiSymDef* GetRealVar();        // last variable in x.y.z
     142             :     SbiExprNode* GetRealNode();     // last node in x.y.z
     143             :     short GetDepth();               // compute a tree's depth
     144         432 :     const OUString& GetString()     { return aStrVal; }
     145           0 :     short GetNumber()               { return (short)nVal; }
     146           0 :     SbiExprList* GetParameters()    { return aVar.pPar; }
     147             :     SbiExprListVector* GetMoreParameters()  { return aVar.pvMorePar; }
     148             : 
     149             :     void Optimize();                // tree matching
     150             : 
     151             :     void Gen( RecursiveMode eRecMode = UNDEFINED ); // giving out a node
     152             : };
     153             : 
     154             : class SbiExpression {
     155             :     friend class SbiExprList;
     156             :     friend class SbiParameters;
     157             :     friend class SbiDimList;
     158             : protected:
     159             :     OUString      aArgName;
     160             :     SbiParser*    pParser;
     161             :     SbiExpression* pNext;            // link at parameter lists
     162             :     SbiExprNode*   pExpr;            // expression tree
     163             :     SbiExprType   eCurExpr;         // type of expression
     164             :     SbiExprMode   m_eMode;          // expression context
     165             :     bool          bBased;           // true: easy DIM-part (+BASE)
     166             :     bool          bError;
     167             :     bool          bByVal;           // true: ByVal-Parameter
     168             :     bool          bBracket;         // true: Parameter list with brackets
     169             :     sal_uInt16        nParenLevel;
     170             :     SbiExprNode* Term( const KeywordSymbolInfo* pKeywordSymbolInfo = NULL );
     171             :     SbiExprNode* ObjTerm( SbiSymDef& );
     172             :     SbiExprNode* Operand( bool bUsedForTypeOf = false );
     173             :     SbiExprNode* Unary();
     174             :     SbiExprNode* Exp();
     175             :     SbiExprNode* MulDiv();
     176             :     SbiExprNode* IntDiv();
     177             :     SbiExprNode* Mod();
     178             :     SbiExprNode* AddSub();
     179             :     SbiExprNode* Cat();
     180             :     SbiExprNode* Like();
     181             :     SbiExprNode* VBA_Not();
     182             :     SbiExprNode* Comp();
     183             :     SbiExprNode* Boolean();
     184             : public:
     185             :     SbiExpression( SbiParser*, SbiExprType = SbSTDEXPR,
     186             :         SbiExprMode eMode = EXPRMODE_STANDARD, const KeywordSymbolInfo* pKeywordSymbolInfo = NULL ); // parsing Ctor
     187             :     SbiExpression( SbiParser*, double, SbxDataType = SbxDOUBLE );
     188             :     SbiExpression( SbiParser*, const SbiSymDef&, SbiExprList* = NULL );
     189             :    ~SbiExpression();
     190       18368 :     OUString& GetName()             { return aArgName;            }
     191          56 :     void SetBased()                 { bBased = true;              }
     192           0 :     bool IsBased()                  { return bBased;              }
     193           0 :     void SetByVal()                 { bByVal = true;              }
     194             :     bool IsByVal()                  { return bByVal;              }
     195        1440 :     bool IsBracket()                { return bBracket;            }
     196        9554 :     bool IsValid()                  { return pExpr->IsValid();    }
     197             :     bool IsConstant()               { return pExpr->IsConstant(); }
     198         186 :     bool IsVariable()               { return pExpr->IsVariable(); }
     199        4696 :     bool IsLvalue()                 { return pExpr->IsLvalue();   }
     200          56 :     bool IsIntConstant()            { return pExpr->IsIntConst(); }
     201         312 :     const OUString& GetString()     { return pExpr->GetString();  }
     202             :     SbiSymDef* GetVar()             { return pExpr->GetVar();     }
     203        6920 :     SbiSymDef* GetRealVar()         { return pExpr->GetRealVar(); }
     204          56 :     SbiExprNode* GetExprNode()      { return pExpr; }
     205         292 :     SbxDataType GetType()           { return pExpr->GetType();    }
     206             :     void SetType( SbxDataType eType){ pExpr->eType = eType;       }
     207             :     void Gen( RecursiveMode eRecMode = UNDEFINED );
     208             : };
     209             : 
     210         244 : class SbiConstExpression : public SbiExpression {
     211             :     double nVal;
     212             :     OUString aVal;
     213             :     SbxDataType eType;
     214             : public:                             // numeric constant
     215             :     SbiConstExpression( SbiParser* );
     216         364 :     SbxDataType GetType() { return eType; }
     217         124 :     const OUString& GetString() { return aVal; }
     218         120 :     double GetValue() { return nVal; }
     219             :     short GetShortValue();
     220             : };
     221             : 
     222             : class SbiExprList {                  // base class for parameters and dims
     223             : protected:
     224             :     SbiParser* pParser;
     225             :     SbiExpression* pFirst;
     226             :     short nExpr;
     227             :     short nDim;
     228             :     bool  bError;
     229             :     bool  bBracket;
     230             : public:
     231             :     SbiExprList( SbiParser* );
     232             :     virtual ~SbiExprList();
     233        5040 :     bool  IsBracket()               { return bBracket;        }
     234        6214 :     bool  IsValid()                 { return !bError; }
     235       22076 :     short GetSize()                 { return nExpr;           }
     236         268 :     short GetDims()                 { return nDim;            }
     237             :     SbiExpression* Get( short );
     238             :     void  Gen();                    // code generation
     239             :     void addExpression( SbiExpression* pExpr );
     240             : };
     241             : 
     242       39628 : class SbiParameters : public SbiExprList {
     243             : public:
     244             :     SbiParameters( SbiParser*, bool bStandaloneExpression = false, bool bPar = true);// parsing Ctor
     245             : };
     246             : 
     247         180 : class SbiDimList : public SbiExprList {
     248             :     bool  bConst;                   // true: everything integer constants
     249             : public:
     250             :     SbiDimList( SbiParser* );         // parsing Ctor
     251             :     bool  IsConstant()              { return bConst; }
     252             : };
     253             : 
     254             : #endif
     255             : 
     256             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10