Mana
SyntaxNode.h
Go to the documentation of this file.
1 
8 #pragma once
9 #include "../runner/common/Setup.h"
10 #include <memory>
11 
12 namespace mana
13 {
14  class Symbol;
15  class TypeDescriptor;
16  class TypeDescriptorFactory;
17 
21  class SyntaxNode final : public std::enable_shared_from_this<SyntaxNode>
22  {
23  public:
25  enum class Id : uint8_t
26  {
27  Array,
28  Assign,
29  CallArgument,
31  Const,
32  Call,
33  Add,
34  Sub,
35  Mul,
36  Div,
37  Rem,
38  Neg,
39  Pow,
40  Not,
41  And,
42  Or,
43  Xor,
44  LeftShift,
45  RightShift,
46  Less,
47  LessEqual,
48  Equal,
49  NotEqual,
50  GreaterEqual,
51  Greater,
52  String,
55  LogicalOr,
56  LogicalAnd,
57  LogicalNot,
58  Halt,
59  Yield,
60  Request,
61  AwaitStart,
63  Accept,
64  Reject,
65  Join,
66  Sender,
67  Self,
68  Priority,
69  ExpressionIf,
70  Print,
71  Return,
72  Rollback,
73 
74  Block,
75  If,
76  Switch,
77  Case,
78  Default,
79  While,
80  Do,
81  For,
82  Loop,
83  Lock,
84  Goto,
85  Label,
86  Break,
87  Continue,
88 
89  Identifier,
91  Declarator,
92 
95  Sizeof,
96 
97  Actor,
98  Phantom,
99  Module,
100  Struct,
101  Action,
102  Extend,
103  Allocate,
104  Static,
107  Namespace,
108  Using,
109 
112 
115 
116  VariableSize,
117  };
118  static constexpr size_t IdSize = static_cast<size_t>(Id::VariableSize);
119 
120  public:
121  explicit SyntaxNode(const Id id);
122  ~SyntaxNode() = default;
123 
124  std::shared_ptr<SyntaxNode> Clone() const;
125 
126  bool Is(const Id id) const;
127  bool IsNot(const Id id) const;
128  Id GetId() const;
129 
130  address_t GetMemorySize() const;
131 
132  std::shared_ptr<SyntaxNode> GetLeftNode() const;
133  void SetLeftNode(const std::shared_ptr<SyntaxNode>& left);
134 
135  std::shared_ptr<SyntaxNode> GetRightNode() const;
136  void SetRightNode(const std::shared_ptr<SyntaxNode>& right);
137 
138  std::shared_ptr<SyntaxNode> GetBodyNode() const;
139  void SetBodyNode(const std::shared_ptr<SyntaxNode>& body);
140 
141  std::shared_ptr<SyntaxNode> GetNextNode() const;
142  void SetNextNode(const std::shared_ptr<SyntaxNode>& next);
143 
144  std::shared_ptr<Symbol> GetSymbol() const;
145  std::shared_ptr<TypeDescriptor> GetTypeDescriptor() const;
146 
148  int_t GetInt() const;
149  float_t GetFloat() const;
150  const std::string_view& GetString() const;
151 
152  const std::string_view& GetFilename() const;
153  int32_t GetLineno() const;
154 
155  void Set(const std::shared_ptr<Symbol>& symbol);
156  void Set(const std::shared_ptr<TypeDescriptor>& type);
157  void Set(const IntermediateLanguage code);
158  void Set(const int_t value);
159  void Set(const float_t value);
160  void Set(const std::string_view text);
161 
162  std::shared_ptr<SyntaxNode> Cast(const std::shared_ptr<TypeDescriptor>& type, const std::shared_ptr<TypeDescriptorFactory>& typeDescriptorFactory);
163 
164  void Dump(std::ofstream& output) const;
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  std::string GetMagic() const;
172  void DumpRecursive(std::ofstream& output) const;
173 
174 #if defined(MANA_MEMORY_LEAK_ANALYSIS)
175  char mMagicName[8];
176 #endif
177 
178  std::shared_ptr<SyntaxNode> mLeft;
179  std::shared_ptr<SyntaxNode> mRight;
180  std::shared_ptr<SyntaxNode> mBody;
181  std::shared_ptr<SyntaxNode> mNext;
182 
183  std::shared_ptr<Symbol> mSymbol;
184  std::shared_ptr<TypeDescriptor> mType;
185 
186  uint32_t mMagic;
187 
188  Id mId = Id::VariableSize;
189 
191 
192  int16_t mLineNo = -1;
193 
194  int_t mDigit = 0;
195  float_t mReal = 0;
196  std::string_view mString;
197 
198  std::string_view mFilename;
199  };
200 }
Definition: SyntaxNode.h:22
const std::string_view & GetString() const
Definition: SyntaxNode.cpp:182
~SyntaxNode()=default
void SetBodyNode(const std::shared_ptr< SyntaxNode > &body)
Definition: SyntaxNode.cpp:142
Id
構文木識別子
Definition: SyntaxNode.h:26
@ 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:137
int_t GetInt() const
Definition: SyntaxNode.cpp:172
float_t GetFloat() const
Definition: SyntaxNode.cpp:177
std::shared_ptr< Symbol > GetSymbol() const
Definition: SyntaxNode.cpp:157
address_t GetMemorySize() const
Definition: SyntaxNode.cpp:64
std::shared_ptr< TypeDescriptor > GetTypeDescriptor() const
Definition: SyntaxNode.cpp:162
std::shared_ptr< SyntaxNode > Cast(const std::shared_ptr< TypeDescriptor > &type, const std::shared_ptr< TypeDescriptorFactory > &typeDescriptorFactory)
Definition: SyntaxNode.cpp:252
void SetLeftNode(const std::shared_ptr< SyntaxNode > &left)
Definition: SyntaxNode.cpp:122
void SetRightNode(const std::shared_ptr< SyntaxNode > &right)
Definition: SyntaxNode.cpp:132
static constexpr size_t IdSize
Definition: SyntaxNode.h:118
std::shared_ptr< SyntaxNode > GetLeftNode() const
Definition: SyntaxNode.cpp:117
void Dump(std::ofstream &output) const
Definition: SyntaxNode.cpp:310
std::shared_ptr< SyntaxNode > GetRightNode() const
Definition: SyntaxNode.cpp:127
bool Is(const Id id) const
Definition: SyntaxNode.cpp:49
void Set(const std::shared_ptr< Symbol > &symbol)
Definition: SyntaxNode.cpp:197
bool IsNot(const Id id) const
Definition: SyntaxNode.cpp:54
Id GetId() const
Definition: SyntaxNode.cpp:59
int32_t GetLineno() const
Definition: SyntaxNode.cpp:192
const std::string_view & GetFilename() const
Definition: SyntaxNode.cpp:187
std::shared_ptr< SyntaxNode > Clone() const
Definition: SyntaxNode.cpp:28
IntermediateLanguage GetOpecode() const
std::shared_ptr< SyntaxNode > GetNextNode() const
Definition: SyntaxNode.cpp:147
void SetNextNode(const std::shared_ptr< SyntaxNode > &next)
Definition: SyntaxNode.cpp:152
string body
Definition: Version.py:24
Definition: CodeBuffer.cpp:12
std::uint32_t address_t
Definition: Type.h:30
IntermediateLanguage
Definition: FileFormat.h:79
std::int32_t int_t
Definition: Type.h:28
float float_t
Definition: Type.h:27