Mana
GlobalSemanticAnalyzer.h
Go to the documentation of this file.
1 
8 #pragma once
9 #include "SemanticAnalyzer.h"
10 #include <unordered_map>
11 #include <vector>
12 
13 namespace mana
14 {
15  class NamespaceRegistry;
16  class SyntaxNode;
17 
18  /*
19  構造体、アクター、モジュール、関数などグローバルな範囲の文法を解析します
20  */
22  {
23  public:
25  const std::shared_ptr<SymbolFactory>& symbolFactory,
26  const std::shared_ptr<TypeDescriptorFactory>& typeDescriptorFactory,
27  const std::shared_ptr<StringPool>& stringPool,
28  const std::shared_ptr<NamespaceRegistry>& namespaceRegistry);
29  ~GlobalSemanticAnalyzer() override = default;
30 
35  void Resolve(std::shared_ptr<SyntaxNode> node);
36 
37  private:
38  struct UsingScope
39  {
40  std::vector<std::string_view> namespacePaths;
41  std::unordered_map<std::string_view, std::string_view> symbolAliases;
42  };
43 
44  static size_t CalcArgumentCount(const size_t count, const std::shared_ptr<const SyntaxNode>& node);
45  [[nodiscard]] std::string_view JoinQualifiedName(const std::string_view& left, const std::string_view& right) const;
46  [[nodiscard]] std::string_view GetCurrentNamespace() const;
47  [[nodiscard]] bool IsQualifiedName(const std::string_view& name) const;
48  [[nodiscard]] std::string_view GetLastSegment(const std::string_view& name) const;
49  [[nodiscard]] bool IsActorSymbol(const std::string_view& name) const;
50  [[nodiscard]] bool IsTypeSymbol(const std::string_view& name) const;
51  [[nodiscard]] std::string_view ResolveAlias(const std::string_view& name) const;
52  std::string_view QualifyName(const std::string_view& name);
53  std::string_view QualifyNameIfUnqualified(const std::string_view& name);
54  std::string_view ResolveTypeName(const std::string_view& name);
55  std::string_view ResolveExtendName(const std::string_view& name) const;
56  void ResolveTypeDescriptionScoped(const std::shared_ptr<SyntaxNode>& node);
57  void RejectActorTypeName(const std::shared_ptr<SyntaxNode>& node);
58  void ResolveVariableDescription(const std::shared_ptr<SyntaxNode>& node, const Symbol::MemoryTypeId memoryTypeId, const bool isStaticVariable);
59  std::string_view ResolveConstSymbolName(const std::string_view& name) const;
60  void ResolveConstExpressionSymbols(const std::shared_ptr<SyntaxNode>& node);
61  void EnterNamespace(const std::string_view& name);
62  void ExitNamespace();
63  void RegisterNamespaceHierarchy(const std::string_view& fullName);
64  void ResolveUsingDeclaration(const std::shared_ptr<SyntaxNode>& node);
65 
66  private:
67  bool mStaticBlockOpened = false;
68  std::vector<std::string_view> mNamespaceStack;
69  std::vector<UsingScope> mUsingScopes;
70  std::shared_ptr<NamespaceRegistry> mNamespaceRegistry;
71  };
72 }
Definition: GlobalSemanticAnalyzer.h:22
void Resolve(std::shared_ptr< SyntaxNode > node)
Definition: GlobalSemanticAnalyzer.cpp:568
GlobalSemanticAnalyzer(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: GlobalSemanticAnalyzer.cpp:18
~GlobalSemanticAnalyzer() override=default
Definition: SemanticAnalyzer.h:20
MemoryTypeId
Definition: Symbol.h:62
Definition: CodeBuffer.cpp:12