Mana
LocalSemanticAnalyzer.h
Go to the documentation of this file.
1 
8 #pragma once
9 #include "SemanticAnalyzer.h"
10 #include "SymbolFactory.h"
11 #include "SyntaxNode.h"
12 #include "TypeDescriptor.h"
13 #include <unordered_map>
14 #include <vector>
15 
16 namespace mana
17 {
18  class NamespaceRegistry;
19 
20  /*
21  アクションや関数などローカルな範囲の文法を解析します
22  */
24  {
25  public:
27  const std::shared_ptr<SymbolFactory>& symbolFactory,
28  const std::shared_ptr<TypeDescriptorFactory>& typeDescriptorFactory,
29  const std::shared_ptr<StringPool>& stringPool,
30  const std::shared_ptr<NamespaceRegistry>& namespaceRegistry
31  );
32  ~LocalSemanticAnalyzer() override = default;
33 
34  void BeginNamespaceScope(const std::string_view& name);
35  void EndNamespaceScope();
36 
37  void PostResolverResolve(std::shared_ptr<SyntaxNode> node);
38 
39  private:
40  struct UsingScope
41  {
42  std::vector<std::string_view> namespacePaths;
43  std::unordered_map<std::string_view, std::string_view> symbolAliases;
44  };
45 
46  [[nodiscard]] std::string_view JoinQualifiedName(const std::string_view& left, const std::string_view& right) const;
47  [[nodiscard]] std::string_view GetCurrentNamespace() const;
48  [[nodiscard]] bool IsQualifiedName(const std::string_view& name) const;
49  [[nodiscard]] std::string_view GetLastSegment(const std::string_view& name) const;
50  [[nodiscard]] bool IsActorSymbol(const std::string_view& name) const;
51  [[nodiscard]] bool IsTypeSymbol(const std::string_view& name) const;
52  [[nodiscard]] std::string_view ResolveAlias(const std::string_view& name) const;
53  [[nodiscard]] std::string_view ResolveTypeName(const std::string_view& name) const;
54  [[nodiscard]] std::string_view ResolveSymbolName(const std::string_view& name) const;
55  void ResolveTypeDescriptionScoped(const std::shared_ptr<SyntaxNode>& node);
56  void RejectActorTypeName(const std::shared_ptr<SyntaxNode>& node);
57  void ResolveVariableDescription(const std::shared_ptr<SyntaxNode>& node, const Symbol::MemoryTypeId memoryTypeId, const bool isStaticVariable);
58  std::string_view ResolveConstSymbolName(const std::string_view& name) const;
59  void ResolveConstExpressionSymbols(const std::shared_ptr<SyntaxNode>& node);
60 
61  void EnterNamespace(const std::string_view& name);
62  void ExitNamespace();
63  void ResolveUsingDeclaration(const std::shared_ptr<SyntaxNode>& node);
64  void ResolveActionReference(const std::shared_ptr<SyntaxNode>& node, const std::string_view& actionName);
65  static bool HasAction(const std::shared_ptr<Symbol>& actorSymbol, const std::string_view& actionName);
66 
67  static bool GetNodeType(TypeDescriptor::Id* t1, TypeDescriptor::Id* t2, const std::shared_ptr<const SyntaxNode>& node);
68  void AutoCast(const std::shared_ptr<SyntaxNode>& node);
69 
70  std::vector<std::string_view> mNamespaceStack;
71  std::vector<UsingScope> mUsingScopes;
72  std::shared_ptr<NamespaceRegistry> mNamespaceRegistry;
73  };
74 }
Definition: LocalSemanticAnalyzer.h:24
void EndNamespaceScope()
Definition: LocalSemanticAnalyzer.cpp:35
void PostResolverResolve(std::shared_ptr< SyntaxNode > node)
Definition: LocalSemanticAnalyzer.cpp:582
LocalSemanticAnalyzer(const std::shared_ptr< SymbolFactory > &symbolFactory, const std::shared_ptr< TypeDescriptorFactory > &typeDescriptorFactory, const std::shared_ptr< StringPool > &stringPool, const std::shared_ptr< NamespaceRegistry > &namespaceRegistry)
Definition: LocalSemanticAnalyzer.cpp:19
~LocalSemanticAnalyzer() override=default
void BeginNamespaceScope(const std::string_view &name)
Definition: LocalSemanticAnalyzer.cpp:30
Definition: SemanticAnalyzer.h:20
MemoryTypeId
Definition: Symbol.h:62
Id
type identifier
Definition: TypeDescriptor.h:31
Definition: CodeBuffer.cpp:12