@@ -79,6 +79,12 @@ struct function_declaration_param {
|
||||
type type;
|
||||
};
|
||||
|
||||
enum class function_declaration_node_t {
|
||||
Normal = 0,
|
||||
Import,
|
||||
Native,
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Function declaration AST node.
|
||||
*/
|
||||
@@ -92,11 +98,16 @@ public:
|
||||
* @param type Return type of the function.
|
||||
*/
|
||||
template <typename T, typename ParamsFwd>
|
||||
function_declaration_node(struct location location, T&& name, std::optional<type>&& returnType, ParamsFwd&& params)
|
||||
function_declaration_node(struct location location,
|
||||
T&& name,
|
||||
std::optional<type>&& returnType,
|
||||
ParamsFwd&& params,
|
||||
function_declaration_node_t type = function_declaration_node_t::Normal)
|
||||
: declaration_node(location),
|
||||
p_name(std::forward<T>(name)),
|
||||
p_returnType(std::move(returnType)),
|
||||
p_params(std::forward<ParamsFwd>(params)) {}
|
||||
p_params(std::forward<ParamsFwd>(params)),
|
||||
p_type(type) {}
|
||||
public:
|
||||
/**
|
||||
* @brief Returns this node's declaration type.
|
||||
@@ -125,6 +136,13 @@ public:
|
||||
* @return Function's parameters.
|
||||
*/
|
||||
const std::vector<function_declaration_param>& params() const { return p_params; }
|
||||
|
||||
/**
|
||||
* @brief Returns function's type.
|
||||
*
|
||||
* @return Function's type.
|
||||
*/
|
||||
function_declaration_node_t type() const { return p_type; }
|
||||
public:
|
||||
void accept(visitor& visitor) const override;
|
||||
|
||||
@@ -140,12 +158,17 @@ protected:
|
||||
/**
|
||||
* @brief Return type of the function.
|
||||
*/
|
||||
std::optional<type> p_returnType;
|
||||
std::optional<class type> p_returnType;
|
||||
|
||||
/**
|
||||
* @brief Parameters of the function.
|
||||
*/
|
||||
std::vector<function_declaration_param> p_params;
|
||||
|
||||
/**
|
||||
* @brief Type of the function declaration.
|
||||
*/
|
||||
function_declaration_node_t p_type;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -164,7 +187,7 @@ public:
|
||||
template <typename T, typename ParamsFwd>
|
||||
function_definition_node(struct location location,
|
||||
T&& name,
|
||||
std::optional<type>&& type,
|
||||
std::optional<class type>&& type,
|
||||
ParamsFwd&& params,
|
||||
body&& body)
|
||||
: function_declaration_node(location, std::forward<T>(name), std::move(type), std::forward<ParamsFwd>(params)),
|
||||
|
||||
@@ -153,6 +153,8 @@ enum class keyword_token {
|
||||
If, /**< `if` */
|
||||
Else, /**< `else` */
|
||||
While, /**< `while` */
|
||||
Import, /**< `import` */
|
||||
Native, /**< `native` */
|
||||
|
||||
Int32, /**< `int32` */
|
||||
};
|
||||
@@ -165,6 +167,8 @@ static inline std::ostream& operator<<(std::ostream& os, keyword_token keyword)
|
||||
case keyword_token::If: return os << "if";
|
||||
case keyword_token::Else: return os << "else";
|
||||
case keyword_token::While: return os << "while";
|
||||
case keyword_token::Import: return os << "import";
|
||||
case keyword_token::Native: return os << "native";
|
||||
case keyword_token::Int32: return os << "int32";
|
||||
}
|
||||
return os;
|
||||
@@ -178,6 +182,8 @@ static inline std::string operator+(const std::string& str, keyword_token keywor
|
||||
case keyword_token::If: return str + "if";
|
||||
case keyword_token::Else: return str + "else";
|
||||
case keyword_token::While: return str + "while";
|
||||
case keyword_token::Import: return str + "import";
|
||||
case keyword_token::Native: return str + "native";
|
||||
case keyword_token::Int32: return str + "int32";
|
||||
}
|
||||
return str;
|
||||
|
||||
Reference in New Issue
Block a user