cURL: follow redirects
[LibreOffice.git] / idlc / inc / astexpression.hxx
blobe092ffd99fd0ff3cbdb7bf53dbe8734342d712ed
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>
28 // Enum to define all the different operators to combine expressions
29 enum ExprComb
31 EC_add, // '+'
32 EC_minus, // '-'
33 EC_mul, // '*'
34 EC_div, // '/'
35 EC_mod, // '%'
36 EC_or, // '|'
37 EC_xor, // '^'
38 EC_and, // '&'
39 EC_left, // '<<'
40 EC_right, // '>>'
41 EC_u_plus, // unary '+'
42 EC_u_minus, // unary '-'
43 EC_bit_neg, // '~'
44 EC_none, // No operator (missing)
45 EC_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* SAL_CALL 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; }
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 // Fill out the lineno, filename and definition scope details
121 void fillDefinitionDetails();
122 // Evaluate different sets of operators
123 std::unique_ptr<AstExprValue> eval_bin_op();
124 std::unique_ptr<AstExprValue> eval_bit_op();
125 std::unique_ptr<AstExprValue> eval_un_op();
126 AstExprValue* eval_symbol();
128 AstScope* m_pScope; // scope defined in
129 sal_Int32 m_lineNo; // line number defined in
130 OString m_fileName; // fileName defined in
132 ExprComb m_combOperator;
133 AstExpression* m_subExpr1;
134 AstExpression* m_subExpr2;
135 AstExprValue* m_exprValue;
136 OString* m_pSymbolicName;
139 #endif // INCLUDED_IDLC_INC_ASTEXPRESSION_HXX
141 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */