Mana
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
SyntaxNode.h
Go to the documentation of this file.
1 
8 #pragma once
9 #include "../runner/common/Setup.h"
10 #include <memory>
11 #include <vector>
12 
13 namespace mana
14 {
15  class Symbol;
16  class TypeDescriptor;
17  class TypeDescriptorFactory;
18 
22  class SyntaxNode final : public std::enable_shared_from_this<SyntaxNode>
23  {
24  public:
26  enum class Id : uint8_t
27  {
28  Array,
29  Assign,
30  CallArgument,
32  Const,
33  Call,
34  Add,
35  Sub,
36  Mul,
37  Div,
38  Rem,
39  Neg,
40  Pow,
41  Not,
42  And,
43  Or,
44  Xor,
45  LeftShift,
46  RightShift,
47  Less,
48  LessEqual,
49  Equal,
50  NotEqual,
51  GreaterEqual,
52  Greater,
53  String,
56  LogicalOr,
57  LogicalAnd,
58  LogicalNot,
59  Halt,
60  Yield,
61  Request,
62  AwaitStart,
64  Accept,
65  Reject,
66  Join,
67  Sender,
68  Self,
69  Priority,
70  ExpressionIf,
71  Print,
72  Return,
73  Rollback,
74 
75  Block,
76  If,
77  Switch,
78  Case,
79  Default,
80  While,
81  Do,
82  For,
83  Loop,
84  Lock,
85  Goto,
86  Label,
87  Break,
88  Continue,
89 
90  Identifier,
92  Declarator,
93 
95  Sizeof,
96 
97  Actor,
98  Phantom,
99  Module,
100  Struct,
101  Action,
102  Extend,
103  Allocate,
104  Static,
107 
110 
113 
114  VariableSize,
115  };
116  static constexpr size_t IdSize = static_cast<size_t>(Id::VariableSize);
117 
118  public:
119  explicit SyntaxNode(const Id id);
120  ~SyntaxNode() = default;
121 
122  std::shared_ptr<SyntaxNode> Clone() const;
123 
124  bool Is(const Id id) const;
125  bool IsNot(const Id id) const;
126  Id GetId() const;
127 
128  address_t GetMemorySize() const;
129 
130  std::shared_ptr<SyntaxNode> GetLeftNode() const;
131  void SetLeftNode(const std::shared_ptr<SyntaxNode>& left);
132 
133  std::shared_ptr<SyntaxNode> GetRightNode() const;
134  void SetRightNode(const std::shared_ptr<SyntaxNode>& right);
135 
136  std::shared_ptr<SyntaxNode> GetBodyNode() const;
137  void SetBodyNode(const std::shared_ptr<SyntaxNode>& body);
138 
139  std::shared_ptr<SyntaxNode> GetNextNode() const;
140  void SetNextNode(const std::shared_ptr<SyntaxNode>& next);
141 
142  std::shared_ptr<Symbol> GetSymbol() const;
143  std::shared_ptr<TypeDescriptor> GetTypeDescriptor() const;
144 
146  int_t GetInt() const;
147  float_t GetFloat() const;
148  const std::string_view& GetString() const;
149 
150  const std::string_view& GetFilename() const;
151  int32_t GetLineno() const;
152 
153  void Set(const std::shared_ptr<Symbol>& symbol);
154  void Set(const std::shared_ptr<TypeDescriptor>& type);
155  void Set(const IntermediateLanguage code);
156  void Set(const int_t value);
157  void Set(const float_t value);
158  void Set(const std::string_view text);
159 
160  std::shared_ptr<SyntaxNode> Cast(const std::shared_ptr<TypeDescriptor>& type, const std::shared_ptr<TypeDescriptorFactory>& typeDescriptorFactory);
161 
162 #if MANA_BUILD_TARGET < MANA_BUILD_RELEASE
163  void Dump() const;
164 #endif
165 
166  private:
167  SyntaxNode() = default;
168 
169  std::shared_ptr<SyntaxNode> CreateCast(const std::shared_ptr<TypeDescriptor>& type, const std::shared_ptr<TypeDescriptorFactory>& typeDescriptorFactory);
170 
171 #if MANA_BUILD_TARGET < MANA_BUILD_RELEASE
172  void OnDump(FILE* file) const;
173 #endif
174 
175  private:
176 #if MANA_BUILD_TARGET < MANA_BUILD_RELEASE
177  char mMagic[8] = "";
178 #endif
179  Id mId = Id::VariableSize;
180  std::shared_ptr<SyntaxNode> mLeft;
181  std::shared_ptr<SyntaxNode> mRight;
182  std::shared_ptr<SyntaxNode> mBody;
183  std::shared_ptr<SyntaxNode> mNext;
184 
185  std::shared_ptr<Symbol> mSymbol;
186  std::shared_ptr<TypeDescriptor> mType;
187 
189  int_t mDigit = 0;
190  float_t mReal = 0;
191  std::string_view mString;
192 
193  std::string_view mFilename;
194  int32_t mLineNo = -1;
195  };
196 }
Definition: SyntaxNode.h:23
const std::string_view & GetString() const
Definition: SyntaxNode.cpp:187
~SyntaxNode()=default
void SetBodyNode(const std::shared_ptr< SyntaxNode > &body)
Definition: SyntaxNode.cpp:147
Id
構文木識別子
Definition: SyntaxNode.h:27
@ IntegerToFloat
整数から実数へ変換
@ Actor
アクターの宣言
@ Array
variable[argument] =
@ Priority
priority (integer)
@ ExpressionIf
三項演算子 '?'
@ FloatToInteger
実数から整数へ変換
@ Sender
sender (actor)
@ Self
self (actor)
@ CallArgument
引数(呼び出し)
@ DeclareArgument
引数(宣言)
@ Call
関数呼び出し
@ Accept
comply (req許可)
@ Reject
refuse (req拒否)
@ Block
ブロック
@ Neg
±符号反転
std::shared_ptr< SyntaxNode > GetBodyNode() const
Definition: SyntaxNode.cpp:142
int_t GetInt() const
Definition: SyntaxNode.cpp:177
float_t GetFloat() const
Definition: SyntaxNode.cpp:182
std::shared_ptr< Symbol > GetSymbol() const
Definition: SyntaxNode.cpp:162
address_t GetMemorySize() const
Definition: SyntaxNode.cpp:69
std::shared_ptr< TypeDescriptor > GetTypeDescriptor() const
Definition: SyntaxNode.cpp:167
std::shared_ptr< SyntaxNode > Cast(const std::shared_ptr< TypeDescriptor > &type, const std::shared_ptr< TypeDescriptorFactory > &typeDescriptorFactory)
Definition: SyntaxNode.cpp:257
void SetLeftNode(const std::shared_ptr< SyntaxNode > &left)
Definition: SyntaxNode.cpp:127
void SetRightNode(const std::shared_ptr< SyntaxNode > &right)
Definition: SyntaxNode.cpp:137
static constexpr size_t IdSize
Definition: SyntaxNode.h:116
std::shared_ptr< SyntaxNode > GetLeftNode() const
Definition: SyntaxNode.cpp:122
std::shared_ptr< SyntaxNode > GetRightNode() const
Definition: SyntaxNode.cpp:132
bool Is(const Id id) const
Definition: SyntaxNode.cpp:54
void Set(const std::shared_ptr< Symbol > &symbol)
Definition: SyntaxNode.cpp:202
bool IsNot(const Id id) const
Definition: SyntaxNode.cpp:59
Id GetId() const
Definition: SyntaxNode.cpp:64
int32_t GetLineno() const
Definition: SyntaxNode.cpp:197
const std::string_view & GetFilename() const
Definition: SyntaxNode.cpp:192
std::shared_ptr< SyntaxNode > Clone() const
Definition: SyntaxNode.cpp:33
IntermediateLanguage GetOpecode() const
std::shared_ptr< SyntaxNode > GetNextNode() const
Definition: SyntaxNode.cpp:152
void SetNextNode(const std::shared_ptr< SyntaxNode > &next)
Definition: SyntaxNode.cpp:157
string body
Definition: Version.py:24
Definition: CodeBuffer.cpp:12
std::uint32_t address_t
Definition: Type.h:31
IntermediateLanguage
Definition: FileFormat.h:80
std::int32_t int_t
Definition: Type.h:29
float float_t
Definition: Type.h:28