Introduce a procedure type
This commit is contained in:
@ -132,6 +132,7 @@ namespace elna::source
|
||||
enum class operation
|
||||
{
|
||||
dereference,
|
||||
argument
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -10,6 +10,7 @@ namespace elna::source
|
||||
std::shared_ptr<symbol_table> table;
|
||||
const std::filesystem::path filename;
|
||||
std::list<std::unique_ptr<error>> m_errors;
|
||||
const std::size_t pointer_size;
|
||||
|
||||
std::shared_ptr<const type> convert_declaration_type(const type_expression& ast_type) const;
|
||||
|
||||
@ -17,8 +18,10 @@ namespace elna::source
|
||||
/**
|
||||
* \param table Symbol table.
|
||||
* \param path Source filename.
|
||||
* \param target_pointer_size Pointer size on the target platform.
|
||||
*/
|
||||
name_analysis_visitor(std::shared_ptr<symbol_table> table, const std::filesystem::path& filename);
|
||||
name_analysis_visitor(std::shared_ptr<symbol_table> table, const std::filesystem::path& filename,
|
||||
const std::size_t target_pointer_size);
|
||||
|
||||
/**
|
||||
* \return Collected errors.
|
||||
@ -67,7 +70,7 @@ namespace elna::source
|
||||
* \param target_pointer_size Pointer size on the target platform.
|
||||
*/
|
||||
type_analysis_visitor(std::shared_ptr<symbol_table> table, const std::filesystem::path& filename,
|
||||
std::size_t target_pointer_size);
|
||||
const std::size_t target_pointer_size);
|
||||
|
||||
/**
|
||||
* \return Collected errors.
|
||||
@ -75,9 +78,11 @@ namespace elna::source
|
||||
const std::list<std::unique_ptr<error>>& errors() const noexcept;
|
||||
|
||||
void visit(program *program) override;
|
||||
void visit(procedure_definition *definition) override;
|
||||
void visit(procedure_definition *procedure) override;
|
||||
void visit(integer_literal *literal) override;
|
||||
void visit(boolean_literal *literal) override;
|
||||
void visit(unary_expression *expression) override;
|
||||
void visit(call_statement *statement) override;
|
||||
void visit(constant_definition *definition) override;
|
||||
};
|
||||
}
|
||||
|
@ -4,7 +4,6 @@
|
||||
#include <unordered_map>
|
||||
#include <string>
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
namespace elna::source
|
||||
{
|
||||
@ -40,11 +39,14 @@ namespace elna::source
|
||||
*/
|
||||
class constant_info final : public info
|
||||
{
|
||||
std::shared_ptr<const class type> m_type;
|
||||
std::int32_t m_value;
|
||||
|
||||
public:
|
||||
constant_info(const std::int32_t value);
|
||||
constant_info(std::shared_ptr<const class type> type, const std::int32_t value);
|
||||
~constant_info() override;
|
||||
|
||||
std::shared_ptr<const class type> type() const noexcept;
|
||||
std::int32_t value() const noexcept;
|
||||
};
|
||||
|
||||
@ -83,10 +85,13 @@ namespace elna::source
|
||||
*/
|
||||
class intrinsic_info : public info
|
||||
{
|
||||
public:
|
||||
std::vector<parameter_info> parameter_infos;
|
||||
std::shared_ptr<const class procedure_type> m_type;
|
||||
|
||||
public:
|
||||
explicit intrinsic_info(const class procedure_type& type);
|
||||
~intrinsic_info() override;
|
||||
|
||||
std::shared_ptr<const class procedure_type> type() const noexcept;
|
||||
std::size_t parameter_stack_size() const noexcept;
|
||||
};
|
||||
|
||||
@ -101,7 +106,7 @@ namespace elna::source
|
||||
std::size_t local_stack_size{ 0 };
|
||||
std::size_t argument_stack_size{ 0 };
|
||||
|
||||
explicit procedure_info(std::shared_ptr<symbol_table> outer_scope);
|
||||
procedure_info(const class procedure_type& type, std::shared_ptr<symbol_table> outer_scope);
|
||||
~procedure_info() override;
|
||||
|
||||
std::shared_ptr<symbol_table> scope();
|
||||
|
@ -2,6 +2,7 @@
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace elna::source
|
||||
{
|
||||
@ -61,6 +62,23 @@ namespace elna::source
|
||||
pointer_type(std::shared_ptr<const type> base_type, const std::size_t byte_size);
|
||||
};
|
||||
|
||||
/**
|
||||
* Type of a procedure.
|
||||
*/
|
||||
struct procedure_type : public type
|
||||
{
|
||||
/// Argument types.
|
||||
std::vector<std::shared_ptr<const type>> arguments;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* \param arguments Argument types.
|
||||
* \param byte_size Function pointer size.
|
||||
*/
|
||||
procedure_type(std::vector<std::shared_ptr<const type>> arguments, const std::size_t byte_size);
|
||||
};
|
||||
|
||||
inline const primitive_type boolean_type{ "Boolean", 1 };
|
||||
inline const primitive_type int_type{ "Int", 4 };
|
||||
}
|
||||
|
Reference in New Issue
Block a user