|
@@ -22,9 +22,8 @@ public:
|
|
|
~TranslationUnit();
|
|
|
|
|
|
void adopt_declaration(NonnullRefPtr<FunctionDeclaration>&& declaration);
|
|
|
- FunctionDefinitionRef adopt_function(NonnullRefPtr<FunctionDefinition>&& definition);
|
|
|
-
|
|
|
- FunctionDeclarationRef find_declaration_by_name(StringView name) const;
|
|
|
+ void adopt_function(NonnullRefPtr<FunctionDefinition>&& definition);
|
|
|
+ FunctionDeclarationRef find_abstract_operation_by_name(StringView name) const;
|
|
|
|
|
|
StringView filename() const { return m_filename; }
|
|
|
DiagnosticEngine& diag() { return m_diagnostic_engine; }
|
|
@@ -37,7 +36,7 @@ private:
|
|
|
DiagnosticEngine m_diagnostic_engine;
|
|
|
Vector<FunctionDefinitionRef> m_functions_to_compile;
|
|
|
Vector<NonnullRefPtr<FunctionDeclaration>> m_declarations_owner;
|
|
|
- HashMap<StringView, FunctionDeclarationRef> m_function_index;
|
|
|
+ HashMap<FlyString, FunctionDeclarationRef> m_abstract_operation_index;
|
|
|
HashMap<StringView, EnumeratorRef> m_enumerator_nodes;
|
|
|
};
|
|
|
|
|
@@ -46,20 +45,95 @@ struct FunctionArgument {
|
|
|
size_t optional_arguments_group;
|
|
|
};
|
|
|
|
|
|
+class QualifiedName {
|
|
|
+public:
|
|
|
+ QualifiedName() { }
|
|
|
+
|
|
|
+ QualifiedName(ReadonlySpan<StringView> parsed_name)
|
|
|
+ {
|
|
|
+ m_components.ensure_capacity(parsed_name.size());
|
|
|
+ for (auto component : parsed_name)
|
|
|
+ m_components.unchecked_append(MUST(FlyString::from_utf8(component)));
|
|
|
+ }
|
|
|
+
|
|
|
+ QualifiedName(ReadonlySpan<FlyString> parsed_name)
|
|
|
+ {
|
|
|
+ m_components.ensure_capacity(parsed_name.size());
|
|
|
+ for (auto component : parsed_name)
|
|
|
+ m_components.unchecked_append(component);
|
|
|
+ }
|
|
|
+
|
|
|
+ String to_string() const
|
|
|
+ {
|
|
|
+ return MUST(String::join("."sv, m_components));
|
|
|
+ }
|
|
|
+
|
|
|
+ Vector<FlyString> const& components() const
|
|
|
+ {
|
|
|
+ return m_components;
|
|
|
+ }
|
|
|
+
|
|
|
+ FlyString last_component() const
|
|
|
+ {
|
|
|
+ return m_components.last();
|
|
|
+ }
|
|
|
+
|
|
|
+ ReadonlySpan<FlyString> without_last_component() const
|
|
|
+ {
|
|
|
+ return components().span().slice(0, components().size() - 1);
|
|
|
+ }
|
|
|
+
|
|
|
+ QualifiedName slice(size_t start, size_t length) const
|
|
|
+ {
|
|
|
+ return { m_components.span().slice(start, length) };
|
|
|
+ }
|
|
|
+
|
|
|
+ QualifiedName with_appended(FlyString component) const
|
|
|
+ {
|
|
|
+ auto new_components = m_components;
|
|
|
+ new_components.append(component);
|
|
|
+ return { new_components };
|
|
|
+ }
|
|
|
+
|
|
|
+private:
|
|
|
+ Vector<FlyString> m_components;
|
|
|
+};
|
|
|
+
|
|
|
+struct AbstractOperationDeclaration {
|
|
|
+ FlyString name;
|
|
|
+ Vector<FunctionArgument> arguments;
|
|
|
+};
|
|
|
+
|
|
|
+struct AccessorDeclaration {
|
|
|
+ QualifiedName name;
|
|
|
+};
|
|
|
+
|
|
|
+struct MethodDeclaration {
|
|
|
+ QualifiedName name;
|
|
|
+ Vector<FunctionArgument> arguments;
|
|
|
+};
|
|
|
+
|
|
|
+using Declaration = Variant<AbstractOperationDeclaration, AccessorDeclaration, MethodDeclaration>;
|
|
|
+
|
|
|
class FunctionDeclaration : public RefCounted<FunctionDeclaration> {
|
|
|
public:
|
|
|
- FunctionDeclaration(StringView name, Vector<FunctionArgument>&& arguments);
|
|
|
+ FunctionDeclaration(Declaration&& declaration, Location location);
|
|
|
|
|
|
virtual ~FunctionDeclaration() = default;
|
|
|
|
|
|
- TranslationUnitRef m_translation_unit = nullptr;
|
|
|
- StringView m_name;
|
|
|
- Vector<FunctionArgument> m_arguments;
|
|
|
+ Declaration const& declaration() const { return m_declaration; }
|
|
|
+ Location location() const { return m_location; }
|
|
|
+ String name() const;
|
|
|
+ ReadonlySpan<FunctionArgument> arguments() const;
|
|
|
+
|
|
|
+private:
|
|
|
+ Declaration m_declaration;
|
|
|
+ Location m_location;
|
|
|
};
|
|
|
|
|
|
class FunctionDefinition : public FunctionDeclaration {
|
|
|
public:
|
|
|
- FunctionDefinition(StringView name, Tree ast, Vector<FunctionArgument>&& arguments);
|
|
|
+ FunctionDefinition(Declaration&& declaration, Location location, Tree ast);
|
|
|
|
|
|
void reindex_ssa_variables();
|
|
|
|