127 lines
2.3 KiB
C++
127 lines
2.3 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 T>
|
|
location apply(primitive_literal_base<T> const & node)
|
|
{
|
|
return node.location;
|
|
}
|
|
|
|
location apply(identifier const & node)
|
|
{
|
|
return node.location;
|
|
}
|
|
|
|
location apply(unary_operation const & node)
|
|
{
|
|
return node.location;
|
|
}
|
|
|
|
location apply(binary_operation const & node)
|
|
{
|
|
return node.location;
|
|
}
|
|
|
|
location apply(cast_operation const & node)
|
|
{
|
|
return node.location;
|
|
}
|
|
|
|
location apply(function_call const & node)
|
|
{
|
|
return node.location;
|
|
}
|
|
|
|
location apply(array const & node)
|
|
{
|
|
return node.location;
|
|
}
|
|
|
|
location apply(array_access const & node)
|
|
{
|
|
return node.location;
|
|
}
|
|
|
|
location apply(field_access 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>{}});
|
|
}
|
|
|
|
types::type_ptr apply(identifier const & node)
|
|
{
|
|
return node.inferred_type;
|
|
}
|
|
|
|
types::type_ptr apply(unary_operation const & node)
|
|
{
|
|
return node.inferred_type;
|
|
}
|
|
|
|
types::type_ptr apply(binary_operation const & node)
|
|
{
|
|
return node.inferred_type;
|
|
}
|
|
|
|
types::type_ptr apply(cast_operation const & node)
|
|
{
|
|
return node.inferred_type;
|
|
}
|
|
|
|
types::type_ptr apply(function_call const & node)
|
|
{
|
|
return node.inferred_type;
|
|
}
|
|
|
|
types::type_ptr apply(array const & node)
|
|
{
|
|
return node.inferred_type;
|
|
}
|
|
|
|
types::type_ptr apply(array_access const & node)
|
|
{
|
|
return node.inferred_type;
|
|
}
|
|
|
|
types::type_ptr apply(field_access 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);
|
|
}
|
|
|
|
}
|