NumeRe v1.1.4
NumeRe: Framework für Numerische Rechnungen
muParserBytecode.h
Go to the documentation of this file.
1/*
2 __________
3 _____ __ __\______ \_____ _______ ______ ____ _______
4 / \ | | \| ___/\__ \ \_ __ \/ ___/_/ __ \\_ __ \
5 | Y Y \| | /| | / __ \_| | \/\___ \ \ ___/ | | \/
6 |__|_| /|____/ |____| (____ /|__| /____ > \___ >|__|
7 \/ \/ \/ \/
8 Copyright (C) 2004-2012 Ingo Berg
9
10 Permission is hereby granted, free of charge, to any person obtaining a copy of this
11 software and associated documentation files (the "Software"), to deal in the Software
12 without restriction, including without limitation the rights to use, copy, modify,
13 merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
14 permit persons to whom the Software is furnished to do so, subject to the following conditions:
15
16 The above copyright notice and this permission notice shall be included in all copies or
17 substantial portions of the Software.
18
19 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
20 NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
22 DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24*/
25#ifndef MU_PARSER_BYTECODE_H
26#define MU_PARSER_BYTECODE_H
27
28#include <cassert>
29#include <string>
30#include <stack>
31#include <vector>
32
33#include "muParserDef.h"
34#include "muParserError.h"
35#include "muParserToken.h"
36
42namespace mu
43{
44 struct SToken
45 {
47
48 union
49 {
50 struct //SValData
51 {
55 bool isVect;
56 } Val;
57
58 struct //SFunData
59 {
60 // Note: generic_fun_type is merely a placeholder. The real type could be
61 // anything between gun_type1 and fun_type9. I can't use a void
62 // pointer due to constraints in the ANSI standard which allows
63 // data pointers and function pointers to differ in size.
65 int argc;
66 int idx;
67 } Fun;
68
69 struct //SOprtData
70 {
72 int offset;
74 };
75
76 SToken() {Cmd = cmUNKNOWN; Val.ptr = nullptr;}
77 };
78
79
90 {
91 private:
92
95
97 typedef std::vector<SToken> rpn_type;
98
100 unsigned m_iStackPos;
101
103 std::size_t m_iMaxStackSize;
104
107
109
110 void ConstantFolding(ECmdCode a_Oprt);
111
112 public:
113
115 ParserByteCode(const ParserByteCode& a_ByteCode);
116 ParserByteCode& operator=(const ParserByteCode& a_ByteCode);
117 void Assign(const ParserByteCode& a_ByteCode);
118
119 void AddVar(value_type* a_pVar);
120 void AddVal(value_type a_fVal);
121 void AddOp(ECmdCode a_Oprt);
122 void AddIfElse(ECmdCode a_Oprt);
123 void AddAssignOp(value_type* a_pVar);
124 void AddFun(generic_fun_type a_pFun, int a_iArgc, bool optimizeAway);
125 void AddBulkFun(generic_fun_type a_pFun, int a_iArgc);
126 void AddStrFun(generic_fun_type a_pFun, int a_iArgc, int a_iIdx);
127
128 void EnableOptimizer(bool bStat);
129
130 void Finalize();
131 void ChangeVar(value_type* a_pOldVar, value_type* a_pNewVar, bool isVect);
132 void clear();
133 std::size_t GetMaxStackSize() const;
134 std::size_t GetSize() const;
135
136 const SToken* GetBase() const;
137 void AsciiDump();
138 };
139
140} // namespace mu
141
142#endif
143
Bytecode implementation of the Math Parser.
void AddStrFun(generic_fun_type a_pFun, int a_iArgc, int a_iIdx)
Add Strung function entry to the parser bytecode.
rpn_type m_vRPN
The actual rpn storage.
ParserByteCode & operator=(const ParserByteCode &a_ByteCode)
Assignment operator.
void ConstantFolding(ECmdCode a_Oprt)
void EnableOptimizer(bool bStat)
std::size_t GetMaxStackSize() const
void AddOp(ECmdCode a_Oprt)
Add an operator identifier to bytecode.
const SToken * GetBase() const
ParserToken< value_type, string_type > token_type
Token type for internal use only.
void ChangeVar(value_type *a_pOldVar, value_type *a_pNewVar, bool isVect)
Changes all old variable pointers to the new addresses. Will be used to compensate for different loca...
void Assign(const ParserByteCode &a_ByteCode)
Copy state of another object to this.
void AddVal(value_type a_fVal)
Add a Variable pointer to bytecode.
void AddBulkFun(generic_fun_type a_pFun, int a_iArgc)
Add a bulk function to bytecode.
ParserByteCode()
Bytecode default constructor.
void clear()
Delete the bytecode.
std::size_t GetSize() const
Returns the number of entries in the bytecode.
void AddFun(generic_fun_type a_pFun, int a_iArgc, bool optimizeAway)
Add a function to the bytecode.
void AsciiDump()
Dump bytecode (for debugging only!).
void AddVar(value_type *a_pVar)
Add a Variable pointer to bytecode.
std::vector< SToken > rpn_type
Token vector for storing the RPN.
std::size_t m_iMaxStackSize
Maximum size needed for the stack.
unsigned m_iStackPos
Position in the Calculation array.
void Finalize()
Add end marker to bytecode.
void AddAssignOp(value_type *a_pVar)
Add an assignement operator.
void AddIfElse(ECmdCode a_Oprt)
This file contains standard definitions used by the parser.
This file defines the error class used by the parser.
This file contains the parser token definition.
Namespace for mathematical applications.
Definition: muParser.cpp:53
MUP_BASETYPE value_type
The numeric datatype used by the parser.
Definition: muParserDef.h:251
ECmdCode
Bytecode values.
Definition: muParserDef.h:153
@ cmUNKNOWN
uninitialized item
Definition: muParserDef.h:197
value_type(* generic_fun_type)()
Callback type used for functions without arguments.
Definition: muParserDef.h:287
value_type * ptr
struct mu::SToken::@11::@14 Fun
generic_fun_type ptr
struct mu::SToken::@11::@13 Val
value_type data2
value_type data
struct mu::SToken::@11::@15 Oprt
ECmdCode Cmd