Gyoji Compiler
Loading...
Searching...
No Matches
type-lowering.hpp
1/* Copyright 2025 Jonathan S. Arney
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * https://github.com/jarney/gyoji/blob/master/LICENSE
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15#pragma once
16
17#include <gyoji-mir.hpp>
18#include <gyoji-frontend.hpp>
19
21
36 public:
38 Gyoji::context::CompilerContext & _compiler_context,
39 const Gyoji::frontend::tree::TranslationUnit & _translation_unit,
40 Gyoji::mir::MIR & _mir);
48
55 void lower();
56
65
66 Gyoji::mir::Type *get_or_create(
67 std::string pointer_name,
69 bool complete,
70 const Gyoji::context::SourceReference & source_ref
71 );
72
73 private:
74 Gyoji::mir::MIR & mir;
75 Gyoji::context::CompilerContext & compiler_context;
76 const Gyoji::frontend::tree::TranslationUnit & translation_unit;
77
78 const Gyoji::mir::Type* extract_from_type_specifier_simple(const Gyoji::frontend::tree::TypeSpecifierSimple & type_specifier);
79 const Gyoji::mir::Type* extract_from_type_specifier_template(const Gyoji::frontend::tree::TypeSpecifierTemplate & type_specifier);
80 const Gyoji::mir::Type* extract_from_type_specifier_function_pointer(const Gyoji::frontend::tree::TypeSpecifierFunctionPointer & type_specifier);
81 const Gyoji::mir::Type* extract_from_type_specifier_pointer_to(const Gyoji::frontend::tree::TypeSpecifierPointerTo & type_specifier);
82 const Gyoji::mir::Type* extract_from_type_specifier_reference_to(const Gyoji::frontend::tree::TypeSpecifierReferenceTo & type_specifier);
83 const Gyoji::mir::Type* extract_from_type_specifier_array(const Gyoji::frontend::tree::TypeSpecifierArray & type_specifier);
84
85 void extract_from_class_declaration(const Gyoji::frontend::tree::ClassDeclaration & declaration);
86
87 void extract_from_class_method_types(
88 Gyoji::mir::Type & class_type,
90 std::string simple_name,
91 std::string fully_qualified_name,
92 Gyoji::mir::Symbol::SymbolType symbol_type,
93 const Gyoji::frontend::tree::UnsafeModifier & method_unsafe_modifier,
94 const Gyoji::mir::Type *method_return_type,
95 const Gyoji::frontend::tree::FunctionDefinitionArgList & function_definition_arg_list,
96 const Gyoji::context::SourceReference & source_ref
97 );
98
99 void extract_from_class_members(Gyoji::mir::Type & type, const Gyoji::frontend::tree::ClassDefinition & definition);
100 void extract_from_class_definition(const Gyoji::frontend::tree::ClassDefinition & definition);
101 void extract_from_enum_definition(const Gyoji::frontend::tree::EnumDefinition & enum_definition);
102 void extract_from_type_definition(const Gyoji::frontend::tree::TypeDefinition & type_definition);
103 void extract_from_namespace(const Gyoji::frontend::tree::FileStatementNamespace & namespace_declaration);
104 void extract_types(const std::vector<Gyoji::owned<Gyoji::frontend::tree::FileStatement>> & statements);
105
106 void extract_from_function_specifications(
108 Gyoji::mir::Symbol::SymbolType symbol_type,
109 const Gyoji::mir::Type *return_type,
110 const Gyoji::context::SourceReference & return_type_source_ref,
112 const Gyoji::frontend::tree::UnsafeModifier & unsafe_modifier
113 );
114
115 void extract_from_function_definition(const Gyoji::frontend::tree::FileStatementFunctionDefinition & function_definition);
116 void extract_from_function_declaration(const Gyoji::frontend::tree::FileStatementFunctionDeclaration & function_declaration);
117
118
119 // Move to analysis
120 void check_complete_type(Gyoji::mir::Type *type) const;
121
122 };
123};
124
125
Compiler Context.
Definition gyoji-context.hpp:44
References a location in the source-file.
Definition source-reference.hpp:30
The TypeLowering is the lowering process for types. This function reads the result of a parse and pro...
Definition type-lowering.hpp:35
~TypeLowering()
Move along, nothing to see here.
Definition type-lowering.cpp:34
const Gyoji::mir::Type * extract_from_type_specifier(const Gyoji::frontend::tree::TypeSpecifier &type_specifier)
Definition type-lowering.cpp:214
void lower()
Definition type-lowering.cpp:37
Represents the declaration of a function.
Definition tree.hpp:982
Represents the list of arguments to a function definition.
Definition tree.hpp:913
Represents tokens from the lexer used to represent keywords and identifiers found in the source.
Definition tree.hpp:103
Represents the top-level syntax unit for a source file.
Definition tree.hpp:2889
Represents a pointer to a function.
Definition tree.hpp:631
Represents an unsafe poniter to a specific type.
Definition tree.hpp:701
Represents a safe reference to a specific type.
Definition tree.hpp:792
Represents a simple type.
Definition tree.hpp:545
Represents a type with type-arguments modifying the type's definition.
Definition tree.hpp:595
Represents a type being specified.
Definition tree.hpp:855
Represents the safety/borrow check semantics for a function or block.
Definition tree.hpp:376
The middle-tier intermediate representation (MIR) of a translation unit.
Definition gyoji-mir.hpp:71
This represents a type as declared in a translation unit.
Definition types.hpp:313
TypeType
Type of type.
Definition types.hpp:335
Converts the strongly-typed syntax tree into the MIR representation.
Definition function-lowering.hpp:37