bump product version to 6.3.0.0.beta1
[LibreOffice.git] / idlc / inc / astexpression.hxx
blob527746245bfffb18d4b39ab35add1617473fb95a
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
19 #ifndef INCLUDED_IDLC_INC_ASTEXPRESSION_HXX
20 #define INCLUDED_IDLC_INC_ASTEXPRESSION_HXX
22 #include <sal/config.h>
24 #include <memory>
26 #include "idlc.hxx"
27 #include <boost/optional.hpp>
29 // Enum to define all the different operators to combine expressions
30 enum class ExprComb
32 Add, // '+'
33 Minus, // '-'
34 Mul, // '*'
35 Div, // '/'
36 Mod, // '%'
37 Or, // '|'
38 Xor, // '^'
39 And, // '&'
40 Left, // '<<'
41 Right, // '>>'
42 UPlus, // unary '+'
43 UMinus, // unary '-'
44 NONE, // No operator (missing)
45 Symbol // a symbol (function or constant name)
48 // Enum to define expression type
49 enum ExprType
51 ET_short, // Expression value is short
52 ET_ushort, // Expression value is unsigned short
53 ET_long, // Expression value is long
54 ET_ulong, // Expression value is unsigned long
55 ET_hyper, // Expression value is hyper (64 bit)
56 ET_uhyper, // Expression value is unsigned hyper
57 ET_float, // Expression value is 32-bit float
58 ET_double, // Expression value is 64-bit float
59 ET_char, // Expression value is char
60 ET_byte, // Expression value is byte
61 ET_boolean, // Expression value is boolean
62 ET_string, // Expression value is char *
63 ET_any, // Expression value is any of above
64 ET_void, // Expression value is void (absent)
65 ET_type, // Expression value is type
66 ET_none // Expression value is missing
69 // Structure to describe value of constant expression and its type
70 struct AstExprValue
72 union
74 sal_uInt8 byval; // Contains byte expression value
75 sal_Int16 sval; // Contains short expression value
76 sal_uInt16 usval; // Contains unsigned short expr value
77 sal_Int32 lval; // Contains long expression value
78 sal_uInt32 ulval; // Contains unsigned long expr value
79 sal_Int64 hval; // Contains hyper expression value
80 sal_uInt64 uhval; // Contains unsigned hyper expr value
81 bool bval; // Contains boolean expression value
82 float fval; // Contains 32-bit float expr value
83 double dval; // Contains 64-bit float expr value
84 } u;
85 ExprType et;
88 const sal_Char* exprTypeToString(ExprType t);
90 class AstExpression final
92 public:
93 // Constructor(s)
94 AstExpression(ExprComb c, AstExpression *pExpr1, AstExpression *pExpr2);
96 AstExpression(sal_Int32 l);
97 AstExpression(sal_Int32 l, ExprType et);
98 AstExpression(sal_Int64 h);
99 AstExpression(sal_uInt64 uh);
100 AstExpression(double d);
101 AstExpression(OString* scopedName);
103 ~AstExpression();
105 // Data Accessors
106 AstExprValue* getExprValue()
107 { return m_exprValue.get(); }
109 // Evaluation and value coercion
110 bool coerce(ExprType type);
112 // Evaluate then store value inside this AstExpression
113 void evaluate();
115 // Compare LONG AstExpression values
116 bool compareLong(AstExpression *pExpr);
118 OString toString();
119 private:
120 // Evaluate different sets of operators
121 std::unique_ptr<AstExprValue> eval_bin_op();
122 std::unique_ptr<AstExprValue> eval_bit_op();
123 std::unique_ptr<AstExprValue> eval_un_op();
124 std::unique_ptr<AstExprValue> eval_symbol();
126 ExprComb m_combOperator;
127 std::unique_ptr<AstExpression>
128 m_subExpr1;
129 std::unique_ptr<AstExpression>
130 m_subExpr2;
131 std::unique_ptr<AstExprValue>
132 m_exprValue;
133 boost::optional<OString>
134 m_xSymbolicName;
137 #endif // INCLUDED_IDLC_INC_ASTEXPRESSION_HXX
139 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */