OpcUaCanOpen
CANopen OPC-UA server
muParserBytecode.h
Go to the documentation of this file.
1 /*
2  __________
3  _____ __ __\______ \_____ _______ ______ ____ _______
4  / \ | | \| ___/\__ \ \_ __ \/ ___/_/ __ \\_ __ \
5  | Y Y \| | /| | / __ \_| | \/\___ \ \ ___/ | | \/
6  |__|_| /|____/ |____| (____ /|__| /____ > \___ >|__|
7  \/ \/ \/ \/
8  Copyright (C) 2004-2013 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 
42 namespace mu
43 {
44  struct SToken
45  {
47  int StackPos;
48 
49  union
50  {
51  struct //SValData
52  {
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  {
71  value_type *ptr;
72  int offset;
73  } Oprt;
74  };
75  };
76 
77 
88 {
89 private:
90 
93 
95  typedef std::vector<SToken> rpn_type;
96 
98  unsigned m_iStackPos;
99 
101  std::size_t m_iMaxStackSize;
102 
105 
107 
108  void ConstantFolding(ECmdCode a_Oprt);
109 
110 public:
111 
112  ParserByteCode();
113  ParserByteCode(const ParserByteCode &a_ByteCode);
114  ParserByteCode& operator=(const ParserByteCode &a_ByteCode);
115  void Assign(const ParserByteCode &a_ByteCode);
116 
117  void AddVar(value_type *a_pVar);
118  void AddVal(value_type a_fVal);
119  void AddOp(ECmdCode a_Oprt);
120  void AddIfElse(ECmdCode a_Oprt);
122  void AddFun(generic_fun_type a_pFun, int a_iArgc);
123  void AddBulkFun(generic_fun_type a_pFun, int a_iArgc);
124  void AddStrFun(generic_fun_type a_pFun, int a_iArgc, int a_iIdx);
125 
126  void EnableOptimizer(bool bStat);
127 
128  void Finalize();
129  void clear();
130  std::size_t GetMaxStackSize() const;
131  std::size_t GetSize() const;
132 
133  const SToken* GetBase() const;
134  void AsciiDump();
135 };
136 
137 } // namespace mu
138 
139 #endif
140 
141