Mana
SemanticAnalyzer.h
Go to the documentation of this file.
1 
8 #pragma once
9 #include "../runner/common/Setup.h"
10 #include "Symbol.h"
11 #include "SymbolFactory.h"
12 #include "SyntaxNode.h"
13 
14 namespace mana
15 {
16  class StringPool;
17 
19  {
20  public:
21  explicit SemanticAnalyzer(
22  const std::shared_ptr<SymbolFactory>& symbolFactory,
23  const std::shared_ptr<TypeDescriptorFactory>& typeDescriptorFactory,
24  const std::shared_ptr<StringPool>& stringPool);
25 
26  virtual ~SemanticAnalyzer() = default;
27 
28  static void SetCurrentFileInformation(const std::shared_ptr<SyntaxNode>& node);
29 
34  bool SearchSymbolFromName(const std::shared_ptr<SyntaxNode>& node);
35 
40  void ResolveTypeDescription(const std::shared_ptr<SyntaxNode>& node);
41 
47  std::shared_ptr<TypeDescriptor> ResolveVariableSize(const std::shared_ptr<SyntaxNode>& node);
48 
55  void ResolveDeclarator(const std::shared_ptr<SyntaxNode>& node, const bool isStaticVariable);
56 
64  void ResolveVariableDescription(const std::shared_ptr<SyntaxNode>& node, const Symbol::MemoryTypeId memoryTypeId, const bool isStaticVariable);
65 
70  static void ResolveTypeFromChildNode(const std::shared_ptr<SyntaxNode>& node);
71 
72  protected:
73  [[nodiscard]] std::shared_ptr<Symbol> Lookup(const std::string_view name) const;
74 
75  const std::shared_ptr<SymbolFactory>& GetSymbolFactory() const;
76  const std::shared_ptr<StringPool>& GetStringPool() const;
77  const std::shared_ptr<TypeDescriptorFactory>& GetTypeDescriptorFactory() const;
78 
79  private:
80  std::shared_ptr<SymbolFactory> mSymbolFactory;
81  std::shared_ptr<StringPool> mStringPool;
82  std::shared_ptr<TypeDescriptorFactory> mTypeDescriptorFactory;
83  };
84 }
Definition: SemanticAnalyzer.h:19
const std::shared_ptr< TypeDescriptorFactory > & GetTypeDescriptorFactory() const
Definition: SemanticAnalyzer.cpp:192
SemanticAnalyzer(const std::shared_ptr< SymbolFactory > &symbolFactory, const std::shared_ptr< TypeDescriptorFactory > &typeDescriptorFactory, const std::shared_ptr< StringPool > &stringPool)
Definition: SemanticAnalyzer.cpp:15
static void SetCurrentFileInformation(const std::shared_ptr< SyntaxNode > &node)
Definition: SemanticAnalyzer.cpp:25
void ResolveTypeDescription(const std::shared_ptr< SyntaxNode > &node)
Definition: SemanticAnalyzer.cpp:55
void ResolveDeclarator(const std::shared_ptr< SyntaxNode > &node, const bool isStaticVariable)
Definition: SemanticAnalyzer.cpp:74
std::shared_ptr< Symbol > Lookup(const std::string_view name) const
Definition: SemanticAnalyzer.cpp:177
static void ResolveTypeFromChildNode(const std::shared_ptr< SyntaxNode > &node)
Definition: SemanticAnalyzer.cpp:149
const std::shared_ptr< StringPool > & GetStringPool() const
Definition: SemanticAnalyzer.cpp:187
bool SearchSymbolFromName(const std::shared_ptr< SyntaxNode > &node)
Definition: SemanticAnalyzer.cpp:32
void ResolveVariableDescription(const std::shared_ptr< SyntaxNode > &node, const Symbol::MemoryTypeId memoryTypeId, const bool isStaticVariable)
Definition: SemanticAnalyzer.cpp:136
std::shared_ptr< TypeDescriptor > ResolveVariableSize(const std::shared_ptr< SyntaxNode > &node)
Definition: SemanticAnalyzer.cpp:94
virtual ~SemanticAnalyzer()=default
const std::shared_ptr< SymbolFactory > & GetSymbolFactory() const
Definition: SemanticAnalyzer.cpp:182
MemoryTypeId
Definition: Symbol.h:62
Definition: CodeBuffer.cpp:12
Definition: Noncopyable.h:18