2022-10-17 22:26:36 -03:00
|
|
|
#ifndef OBELISK_AST_CALL_EXPRESSION_AST_H
|
|
|
|
#define OBELISK_AST_CALL_EXPRESSION_AST_H
|
|
|
|
|
|
|
|
#include "ast/expression_ast.h"
|
|
|
|
|
|
|
|
#include <memory>
|
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
namespace obelisk
|
|
|
|
{
|
2023-02-20 22:01:14 -03:00
|
|
|
/**
|
|
|
|
* @brief The call AST expression node used to call functions.
|
|
|
|
*
|
|
|
|
*/
|
2022-10-17 22:26:36 -03:00
|
|
|
class CallExpressionAST : public ExpressionAST
|
|
|
|
{
|
|
|
|
private:
|
2023-02-20 22:01:14 -03:00
|
|
|
/**
|
|
|
|
* @brief The function being called.
|
|
|
|
*
|
|
|
|
*/
|
2022-10-17 22:26:36 -03:00
|
|
|
std::string callee_;
|
2023-02-20 22:01:14 -03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief The arguments passed to the function.
|
|
|
|
*
|
|
|
|
*/
|
2022-10-17 22:26:36 -03:00
|
|
|
std::vector<std::unique_ptr<ExpressionAST>> args_;
|
|
|
|
|
2023-02-20 22:01:14 -03:00
|
|
|
/**
|
|
|
|
* @brief Get the callee.
|
|
|
|
*
|
2023-02-20 22:05:57 -03:00
|
|
|
* @return std::string Returns the name of the function being
|
|
|
|
* called.
|
2023-02-20 22:01:14 -03:00
|
|
|
*/
|
2022-10-17 22:26:36 -03:00
|
|
|
std::string getCallee();
|
2023-02-20 22:01:14 -03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Set the callee.
|
|
|
|
*
|
|
|
|
* @param[in] callee The name of the function.
|
|
|
|
*/
|
2022-10-17 22:26:36 -03:00
|
|
|
void setCallee(std::string callee);
|
|
|
|
|
2023-02-20 22:01:14 -03:00
|
|
|
/**
|
|
|
|
* @brief Get the arguments being used by the function.
|
|
|
|
*
|
2023-02-20 22:05:57 -03:00
|
|
|
* @return std::vector<std::unique_ptr<ExpressionAST>> Returns an
|
|
|
|
* AST expression containing the args.
|
2023-02-20 22:01:14 -03:00
|
|
|
*/
|
2022-10-17 22:26:36 -03:00
|
|
|
std::vector<std::unique_ptr<ExpressionAST>> getArgs();
|
2023-02-20 22:01:14 -03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Set the arguments to be used by the function.
|
|
|
|
*
|
|
|
|
* @param[in] args The args to set.
|
|
|
|
*/
|
2022-10-17 22:26:36 -03:00
|
|
|
void setArgs(std::vector<std::unique_ptr<ExpressionAST>> args);
|
|
|
|
|
|
|
|
public:
|
2023-02-20 22:01:14 -03:00
|
|
|
/**
|
|
|
|
* @brief Construct a new CallExpressionAST object.
|
|
|
|
*
|
|
|
|
* @param[in] callee The function to call.
|
|
|
|
* @param[in] args The args to pass into the function.
|
|
|
|
*/
|
2023-02-20 22:05:57 -03:00
|
|
|
CallExpressionAST(const std::string &callee,
|
|
|
|
std::vector<std::unique_ptr<ExpressionAST>> args) :
|
2022-10-17 22:26:36 -03:00
|
|
|
callee_(callee),
|
|
|
|
args_(std::move(args))
|
|
|
|
{
|
|
|
|
}
|
2022-11-21 21:24:44 -03:00
|
|
|
|
2023-02-20 22:01:14 -03:00
|
|
|
/**
|
|
|
|
* @brief Generate the calle IR code.
|
|
|
|
*
|
|
|
|
* @return llvm::Value*
|
|
|
|
*/
|
2022-11-21 21:24:44 -03:00
|
|
|
llvm::Value *codegen() override;
|
2022-10-17 22:26:36 -03:00
|
|
|
};
|
|
|
|
} // namespace obelisk
|
|
|
|
|
|
|
|
#endif
|