ast_expression.h 2.74 KB
Newer Older
victor's avatar
 
victor committed
1 2 3 4 5
#ifndef AST_EXPRESSION_H
#define AST_EXPRESSION_H

#include <QString>
#include <QList>
victor's avatar
 
victor committed
6
#include <QVariant>
victor's avatar
 
victor committed
7 8

#include "ast_variabletype.h"
9
#include "ast_type.h"
victor's avatar
 
victor committed
10

victor's avatar
 
victor committed
11
#undef ABSTRACTSYNTAXTREE_EXPORT
victor's avatar
 
victor committed
12
#ifdef DATAFORMATS_LIBRARY
victor's avatar
 
victor committed
13 14 15 16 17
#define ABSTRACTSYNTAXTREE_EXPORT Q_DECL_EXPORT
#else
#define ABSTRACTSYNTAXTREE_EXPORT Q_DECL_IMPORT
#endif

victor's avatar
 
victor committed
18 19 20 21 22 23 24 25 26 27
namespace AST {

/** Type of expression structure */
enum ExpressionType {

    /** Dummy expression, when it optional
      * (for example, "step" value in for-loop)
      */
    ExprNone,

victor's avatar
 
victor committed
28
    /** Variable */
victor's avatar
 
victor committed
29 30
    ExprVariable,

victor's avatar
 
victor committed
31 32
    /** Constant */
    ExprConst,
victor's avatar
 
victor committed
33

victor's avatar
 
victor committed
34 35
    /** Array of string element, or slice */
    ExprArrayElement,
victor's avatar
 
victor committed
36 37 38 39 40 41 42 43 44 45

    /** Function call */
    ExprFunctionCall,

    /** Subexpression */
    ExprSubexpression
};

/** Operand delimeter for subexpressions */
enum ExpressionOperator {
victor's avatar
 
victor committed
46
    OpNone,
victor's avatar
 
victor committed
47 48 49 50 51 52 53
    OpSumm,
    OpSubstract,
    OpMultiply,
    OpDivision,
    OpPower,
    OpNot,
    OpAnd,
victor's avatar
 
victor committed
54 55 56 57 58 59 60
    OpOr,
    OpEqual,
    OpNotEqual,
    OpLess,
    OpGreater,
    OpLessOrEqual,
    OpGreaterOrEqual
victor's avatar
 
victor committed
61 62 63
};

/** Expression tree-based representation */
victor's avatar
 
victor committed
64
struct ABSTRACTSYNTAXTREE_EXPORT Expression {
victor's avatar
 
victor committed
65 66 67 68

    /** Kind of expression */
    enum ExpressionType kind;

victor's avatar
 
victor committed
69
    /** Resulting base type of expression */
70
    Type baseType;
victor's avatar
 
victor committed
71 72 73

    /** Resulting dimension of base type */
    int dimension;
victor's avatar
 
victor committed
74 75 76 77 78 79

    /** Reference to variable in cases of
      * kind==StExprVariable or kind==StArrayElement or kind==StSlice;
      * set to NULL otherwise */
    struct Variable * variable;

victor's avatar
 
victor committed
80 81 82
    /** Constant value in case of kind==ExprConst */
    QVariant constant;

victor's avatar
 
victor committed
83 84 85 86 87 88 89 90 91 92
    /** Reference to algorhitm in case of kind==StFunctionCall;
      * set to NULL otherwise */
    struct Algorhitm * function;

    /** 1. Empty in case of kind==StVariable
      * 2. Array bounds expressions in case of kind==StArrayBound
      * 3. SliceBounds expressions in case of kind==StSlice
      * 4. Function arguments expressions in case of kind==StFunctionCall
      * 5. Expressions list of size len(operators)+1 in case of kind==StSubexpression
      */
victor's avatar
 
victor committed
93
    QList<struct Expression *> operands;
victor's avatar
 
victor committed
94

95 96 97 98
    /** True if expression () bounds.
      * This flag is used to avoid CNF-transofmations */
    bool expressionIsClosed;

99 100 101
    /** True if string element or slice */
    bool isStringPart;

victor's avatar
 
victor committed
102 103
    /** Operator in case of kind==StSubexpression, emty otherwise */
    enum ExpressionOperator operatorr;
victor's avatar
 
victor committed
104

victor's avatar
 
victor committed
105 106 107
    /** Expression source lexems */
    QList<struct Lexem*> lexems;

victor's avatar
 
victor committed
108 109 110 111 112
    explicit Expression();
    explicit Expression(const struct Expression * src);
    void updateReferences(const struct Expression * src,
                          const struct Data * srcData,
                          const struct Data * data);
victor's avatar
 
victor committed
113
    QString dump() const;
victor's avatar
 
victor committed
114
    ~Expression();
victor's avatar
 
victor committed
115 116
};

victor's avatar
 
victor committed
117

victor's avatar
 
victor committed
118 119 120
}

#endif // AST_EXPRESSION_H