mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-12-18 09:25:25 +00:00
semantic: Add Function::Parameters(), MemberAccessorExpression subtypes
Add semantic::Swizzle and semantic::StructMemberAccess, both deriving from MemberAccessorExpression Add semantic::Function::Parameters() to list the semantic::Variable parameters for the function. Change-Id: I8cc69f3738380c14f61d051ee2989be6194d148d Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/47220 Commit-Queue: Ben Clayton <bclayton@chromium.org> Reviewed-by: James Price <jrprice@google.com> Reviewed-by: Antonio Maiorano <amaiorano@google.com>
This commit is contained in:
committed by
Commit Bot service account
parent
f8f31a458f
commit
e9c4984489
@@ -46,12 +46,14 @@ class Function : public Castable<Function, CallTarget> {
|
||||
|
||||
/// Constructor
|
||||
/// @param declaration the ast::Function
|
||||
/// @param parameters the parameters to the function
|
||||
/// @param referenced_module_vars the referenced module variables
|
||||
/// @param local_referenced_module_vars the locally referenced module
|
||||
/// @param return_statements the function return statements
|
||||
/// variables
|
||||
/// @param ancestor_entry_points the ancestor entry points
|
||||
Function(ast::Function* declaration,
|
||||
std::vector<const Variable*> parameters,
|
||||
std::vector<const Variable*> referenced_module_vars,
|
||||
std::vector<const Variable*> local_referenced_module_vars,
|
||||
std::vector<const ast::ReturnStatement*> return_statements,
|
||||
@@ -63,6 +65,9 @@ class Function : public Castable<Function, CallTarget> {
|
||||
/// @returns the ast::Function declaration
|
||||
ast::Function* Declaration() const { return declaration_; }
|
||||
|
||||
/// @return the parameters to the function
|
||||
const std::vector<const Variable*> Parameters() const { return parameters_; }
|
||||
|
||||
/// Note: If this function calls other functions, the return will also include
|
||||
/// all of the referenced variables from the callees.
|
||||
/// @returns the referenced module variables
|
||||
@@ -147,6 +152,7 @@ class Function : public Castable<Function, CallTarget> {
|
||||
bool multisampled) const;
|
||||
|
||||
ast::Function* const declaration_;
|
||||
std::vector<const Variable*> const parameters_;
|
||||
std::vector<const Variable*> const referenced_module_vars_;
|
||||
std::vector<const Variable*> const local_referenced_module_vars_;
|
||||
std::vector<const ast::ReturnStatement*> const return_statements_;
|
||||
|
||||
@@ -20,8 +20,18 @@
|
||||
#include "src/semantic/expression.h"
|
||||
|
||||
namespace tint {
|
||||
|
||||
/// Forward declarations
|
||||
namespace ast {
|
||||
class MemberAccessorExpression;
|
||||
} // namespace ast
|
||||
|
||||
namespace semantic {
|
||||
|
||||
/// Forward declarations
|
||||
class Struct;
|
||||
class StructMember;
|
||||
|
||||
/// MemberAccessorExpression holds the semantic information for a
|
||||
/// ast::MemberAccessorExpression node.
|
||||
class MemberAccessorExpression
|
||||
@@ -31,24 +41,60 @@ class MemberAccessorExpression
|
||||
/// @param declaration the AST node
|
||||
/// @param type the resolved type of the expression
|
||||
/// @param statement the statement that owns this expression
|
||||
/// @param swizzle if this member access is for a vector swizzle, the swizzle
|
||||
/// indices
|
||||
MemberAccessorExpression(ast::Expression* declaration,
|
||||
MemberAccessorExpression(ast::MemberAccessorExpression* declaration,
|
||||
type::Type* type,
|
||||
Statement* statement,
|
||||
std::vector<uint32_t> swizzle);
|
||||
Statement* statement);
|
||||
|
||||
/// Destructor
|
||||
~MemberAccessorExpression() override;
|
||||
};
|
||||
|
||||
/// @return true if this member access is for a vector swizzle
|
||||
bool IsSwizzle() const { return !swizzle_.empty(); }
|
||||
/// StructMemberAccess holds the semantic information for a
|
||||
/// ast::MemberAccessorExpression node that represents an access to a structure
|
||||
/// member.
|
||||
class StructMemberAccess
|
||||
: public Castable<StructMemberAccess, MemberAccessorExpression> {
|
||||
public:
|
||||
/// Constructor
|
||||
/// @param declaration the AST node
|
||||
/// @param type the resolved type of the expression
|
||||
/// @param member the structure member
|
||||
StructMemberAccess(ast::MemberAccessorExpression* declaration,
|
||||
type::Type* type,
|
||||
Statement* statement,
|
||||
const StructMember* member);
|
||||
|
||||
/// @return the swizzle indices, if this is a vector swizzle
|
||||
const std::vector<uint32_t>& Swizzle() const { return swizzle_; }
|
||||
/// Destructor
|
||||
~StructMemberAccess() override;
|
||||
|
||||
/// @returns the structure member
|
||||
StructMember const* Member() const { return member_; }
|
||||
|
||||
private:
|
||||
std::vector<uint32_t> const swizzle_;
|
||||
StructMember const* const member_;
|
||||
};
|
||||
|
||||
/// Swizzle holds the semantic information for a ast::MemberAccessorExpression
|
||||
/// node that represents a vector swizzle.
|
||||
class Swizzle : public Castable<Swizzle, MemberAccessorExpression> {
|
||||
public:
|
||||
/// Constructor
|
||||
/// @param declaration the AST node
|
||||
/// @param type the resolved type of the expression
|
||||
/// @param indices the swizzle indices
|
||||
Swizzle(ast::MemberAccessorExpression* declaration,
|
||||
type::Type* type,
|
||||
Statement* statement,
|
||||
std::vector<uint32_t> indices);
|
||||
|
||||
/// Destructor
|
||||
~Swizzle() override;
|
||||
|
||||
/// @return the swizzle indices, if this is a vector swizzle
|
||||
const std::vector<uint32_t>& Indices() const { return indices_; }
|
||||
|
||||
private:
|
||||
std::vector<uint32_t> const indices_;
|
||||
};
|
||||
|
||||
} // namespace semantic
|
||||
|
||||
@@ -41,12 +41,14 @@ ParameterList GetParameters(ast::Function* ast) {
|
||||
} // namespace
|
||||
|
||||
Function::Function(ast::Function* declaration,
|
||||
std::vector<const Variable*> parameters,
|
||||
std::vector<const Variable*> referenced_module_vars,
|
||||
std::vector<const Variable*> local_referenced_module_vars,
|
||||
std::vector<const ast::ReturnStatement*> return_statements,
|
||||
std::vector<Symbol> ancestor_entry_points)
|
||||
: Base(declaration->return_type(), GetParameters(declaration)),
|
||||
declaration_(declaration),
|
||||
parameters_(std::move(parameters)),
|
||||
referenced_module_vars_(std::move(referenced_module_vars)),
|
||||
local_referenced_module_vars_(std::move(local_referenced_module_vars)),
|
||||
return_statements_(std::move(return_statements)),
|
||||
|
||||
@@ -12,21 +12,40 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include "src/ast/member_accessor_expression.h"
|
||||
#include "src/semantic/member_accessor_expression.h"
|
||||
|
||||
TINT_INSTANTIATE_TYPEINFO(tint::semantic::MemberAccessorExpression);
|
||||
TINT_INSTANTIATE_TYPEINFO(tint::semantic::StructMemberAccess);
|
||||
TINT_INSTANTIATE_TYPEINFO(tint::semantic::Swizzle);
|
||||
|
||||
namespace tint {
|
||||
namespace semantic {
|
||||
|
||||
MemberAccessorExpression::MemberAccessorExpression(
|
||||
ast::Expression* declaration,
|
||||
ast::MemberAccessorExpression* declaration,
|
||||
type::Type* type,
|
||||
Statement* statement,
|
||||
std::vector<uint32_t> swizzle)
|
||||
: Base(declaration, type, statement), swizzle_(std::move(swizzle)) {}
|
||||
Statement* statement)
|
||||
: Base(declaration, type, statement) {}
|
||||
|
||||
MemberAccessorExpression::~MemberAccessorExpression() = default;
|
||||
|
||||
StructMemberAccess::StructMemberAccess(
|
||||
ast::MemberAccessorExpression* declaration,
|
||||
type::Type* type,
|
||||
Statement* statement,
|
||||
const StructMember* member)
|
||||
: Base(declaration, type, statement), member_(member) {}
|
||||
|
||||
StructMemberAccess::~StructMemberAccess() = default;
|
||||
|
||||
Swizzle::Swizzle(ast::MemberAccessorExpression* declaration,
|
||||
type::Type* type,
|
||||
Statement* statement,
|
||||
std::vector<uint32_t> indices)
|
||||
: Base(declaration, type, statement), indices_(std::move(indices)) {}
|
||||
|
||||
Swizzle::~Swizzle() = default;
|
||||
|
||||
} // namespace semantic
|
||||
} // namespace tint
|
||||
|
||||
Reference in New Issue
Block a user