53 lines
1 KiB
C++
53 lines
1 KiB
C++
#include <pslang/ast/expression.hpp>
|
|
#include <pslang/ast/expression_visitor.hpp>
|
|
#include <pslang/types/type.hpp>
|
|
|
|
namespace pslang::ast
|
|
{
|
|
|
|
namespace
|
|
{
|
|
|
|
struct get_location_visitor
|
|
: const_expression_visitor<get_location_visitor>
|
|
{
|
|
using const_expression_visitor::apply;
|
|
|
|
template <typename Node>
|
|
location apply(Node const & node)
|
|
{
|
|
return node.location;
|
|
}
|
|
};
|
|
|
|
struct get_type_visitor
|
|
: const_expression_visitor<get_type_visitor>
|
|
{
|
|
using const_expression_visitor::apply;
|
|
|
|
template <typename T>
|
|
types::type_ptr apply(primitive_literal_base<T> const & node)
|
|
{
|
|
return std::make_unique<types::type>(types::primitive_type{types::primitive_type_base<T>{}});
|
|
}
|
|
|
|
template <typename Node>
|
|
types::type_ptr apply(Node const & node)
|
|
{
|
|
return node.inferred_type;
|
|
}
|
|
};
|
|
|
|
}
|
|
|
|
location get_location(expression const & expression)
|
|
{
|
|
return get_location_visitor{}.apply(expression);
|
|
}
|
|
|
|
types::type_ptr get_type(expression const & expression)
|
|
{
|
|
return get_type_visitor{}.apply(expression);
|
|
}
|
|
|
|
}
|