tint: Add sem::IndexAccessorExpression

Also store expression object in MemberAccessorExpression, as well as the
struct on sem::StructMember.

These are used to implement spir-v reader atomics in a follow-up CL.

Bug: tint:1441
Change-Id: Iea49cfb7f9d2e7898d89d2dac6a16a14022c546f
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/94523
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Antonio Maiorano <amaiorano@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
This commit is contained in:
Antonio Maiorano
2022-06-24 20:34:00 +00:00
committed by Dawn LUCI CQ
parent 90ec3d1368
commit dfeaf29055
16 changed files with 304 additions and 20 deletions

View File

@@ -0,0 +1,37 @@
// Copyright 2021 The Tint Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include "src/tint/sem/index_accessor_expression.h"
#include <utility>
TINT_INSTANTIATE_TYPEINFO(tint::sem::IndexAccessorExpression);
namespace tint::sem {
IndexAccessorExpression::IndexAccessorExpression(const ast::IndexAccessorExpression* declaration,
const sem::Type* type,
const Expression* object,
const Expression* index,
const Statement* statement,
Constant constant,
bool has_side_effects,
const Variable* source_var /* = nullptr */)
: Base(declaration, type, statement, constant, has_side_effects, source_var),
object_(object),
index_(index) {}
IndexAccessorExpression::~IndexAccessorExpression() = default;
} // namespace tint::sem

View File

@@ -0,0 +1,66 @@
// Copyright 2022 The Tint Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef SRC_TINT_SEM_INDEX_ACCESSOR_EXPRESSION_H_
#define SRC_TINT_SEM_INDEX_ACCESSOR_EXPRESSION_H_
#include <vector>
#include "src/tint/sem/expression.h"
// Forward declarations
namespace tint::ast {
class IndexAccessorExpression;
} // namespace tint::ast
namespace tint::sem {
/// IndexAccessorExpression holds the semantic information for a ast::IndexAccessorExpression node.
class IndexAccessorExpression final : public Castable<IndexAccessorExpression, Expression> {
public:
/// Constructor
/// @param declaration the AST node
/// @param type the resolved type of the expression
/// @param object the object expression that is being indexed
/// @param index the index expression
/// @param statement the statement that owns this expression
/// @param constant the constant value of the expression. May be invalid
/// @param has_side_effects whether this expression may have side effects
/// @param source_var the (optional) source variable for this expression
IndexAccessorExpression(const ast::IndexAccessorExpression* declaration,
const sem::Type* type,
const Expression* object,
const Expression* index,
const Statement* statement,
Constant constant,
bool has_side_effects,
const Variable* source_var = nullptr);
/// Destructor
~IndexAccessorExpression() override;
/// @returns the object expression that is being indexed
Expression const* Object() const { return object_; }
/// @returns the index expression
Expression const* Index() const { return index_; }
private:
Expression const* const object_;
Expression const* const index_;
};
} // namespace tint::sem
#endif // SRC_TINT_SEM_INDEX_ACCESSOR_EXPRESSION_H_

View File

@@ -26,29 +26,33 @@ namespace tint::sem {
MemberAccessorExpression::MemberAccessorExpression(const ast::MemberAccessorExpression* declaration,
const sem::Type* type,
const Statement* statement,
const Expression* object,
bool has_side_effects,
const Variable* source_var /* = nullptr */)
: Base(declaration, type, statement, Constant{}, has_side_effects, source_var) {}
: Base(declaration, type, statement, Constant{}, has_side_effects, source_var),
object_(object) {}
MemberAccessorExpression::~MemberAccessorExpression() = default;
StructMemberAccess::StructMemberAccess(const ast::MemberAccessorExpression* declaration,
const sem::Type* type,
const Statement* statement,
const Expression* object,
const StructMember* member,
bool has_side_effects,
const Variable* source_var /* = nullptr */)
: Base(declaration, type, statement, has_side_effects, source_var), member_(member) {}
: Base(declaration, type, statement, object, has_side_effects, source_var), member_(member) {}
StructMemberAccess::~StructMemberAccess() = default;
Swizzle::Swizzle(const ast::MemberAccessorExpression* declaration,
const sem::Type* type,
const Statement* statement,
const Expression* object,
std::vector<uint32_t> indices,
bool has_side_effects,
const Variable* source_var /* = nullptr */)
: Base(declaration, type, statement, has_side_effects, source_var),
: Base(declaration, type, statement, object, has_side_effects, source_var),
indices_(std::move(indices)) {}
Swizzle::~Swizzle() = default;

View File

@@ -38,16 +38,24 @@ class MemberAccessorExpression : public Castable<MemberAccessorExpression, Expre
/// @param declaration the AST node
/// @param type the resolved type of the expression
/// @param statement the statement that owns this expression
/// @param object the object that holds the member being accessed
/// @param has_side_effects whether this expression may have side effects
/// @param source_var the (optional) source variable for this expression
MemberAccessorExpression(const ast::MemberAccessorExpression* declaration,
const sem::Type* type,
const Statement* statement,
const Expression* object,
bool has_side_effects,
const Variable* source_var = nullptr);
/// Destructor
~MemberAccessorExpression() override;
/// @returns the object that holds the member being accessed
const Expression* Object() const { return object_; }
private:
Expression const* const object_;
};
/// StructMemberAccess holds the semantic information for a
@@ -59,12 +67,14 @@ class StructMemberAccess final : public Castable<StructMemberAccess, MemberAcces
/// @param declaration the AST node
/// @param type the resolved type of the expression
/// @param statement the statement that owns this expression
/// @param object the object that holds the member being accessed
/// @param member the structure member
/// @param has_side_effects whether this expression may have side effects
/// @param source_var the (optional) source variable for this expression
StructMemberAccess(const ast::MemberAccessorExpression* declaration,
const sem::Type* type,
const Statement* statement,
const Expression* object,
const StructMember* member,
bool has_side_effects,
const Variable* source_var = nullptr);
@@ -87,12 +97,14 @@ class Swizzle final : public Castable<Swizzle, MemberAccessorExpression> {
/// @param declaration the AST node
/// @param type the resolved type of the expression
/// @param statement the statement that owns this expression
/// @param object the object that holds the member being accessed
/// @param indices the swizzle indices
/// @param has_side_effects whether this expression may have side effects
/// @param source_var the (optional) source variable for this expression
Swizzle(const ast::MemberAccessorExpression* declaration,
const sem::Type* type,
const Statement* statement,
const Expression* object,
std::vector<uint32_t> indices,
bool has_side_effects,
const Variable* source_var = nullptr);

View File

@@ -194,9 +194,16 @@ class StructMember : public Castable<StructMember, Node> {
/// @returns the AST declaration node
const ast::StructMember* Declaration() const { return declaration_; }
/// @returns the name of the structure
/// @returns the name of the structure member
Symbol Name() const { return name_; }
/// Sets the owning structure to `s`
/// @param s the new structure owner
void SetStruct(const sem::Struct* s) { struct_ = s; }
/// @returns the structure that owns this member
const sem::Struct* Struct() const { return struct_; }
/// @returns the type of the member
sem::Type* Type() const { return type_; }
@@ -215,6 +222,7 @@ class StructMember : public Castable<StructMember, Node> {
private:
const ast::StructMember* const declaration_;
const Symbol name_;
const sem::Struct* struct_;
sem::Type* const type_;
const uint32_t index_;
const uint32_t offset_;

View File

@@ -25,6 +25,7 @@ class Expression;
class ForLoopStatement;
class Function;
class IfStatement;
class IndexAccessorExpression;
class MemberAccessorExpression;
class Node;
class Override;
@@ -44,6 +45,7 @@ class Expression;
class ForLoopStatement;
class Function;
class IfStatement;
class IndexAccessorExpression;
class MemberAccessorExpression;
class Node;
class GlobalVariable;
@@ -69,6 +71,7 @@ struct TypeMappings {
ForLoopStatement* operator()(ast::ForLoopStatement*);
Function* operator()(ast::Function*);
IfStatement* operator()(ast::IfStatement*);
IndexAccessorExpression* operator()(ast::IndexAccessorExpression*);
MemberAccessorExpression* operator()(ast::MemberAccessorExpression*);
Node* operator()(ast::Node*);
GlobalVariable* operator()(ast::Override*);