mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-12-18 09:25:25 +00:00
Add semantic::Statement
Add Stmt() accessor on all semantic::Expressions so the owning statement can be retrieved. Change-Id: I5d584335a6d137fdeab0b8d74a161fcae9b46080 Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/41545 Reviewed-by: James Price <jrprice@google.com> Reviewed-by: dan sinclair <dsinclair@chromium.org> Commit-Queue: dan sinclair <dsinclair@chromium.org> Auto-Submit: Ben Clayton <bclayton@google.com>
This commit is contained in:
committed by
Commit Bot service account
parent
e7dab3c9ea
commit
f97b9c9310
@@ -27,7 +27,8 @@ class Call : public Castable<Call, Expression> {
|
||||
public:
|
||||
/// Constructor
|
||||
/// @param target the call target
|
||||
explicit Call(const CallTarget* target);
|
||||
/// @param statement the statement that owns this expression
|
||||
explicit Call(const CallTarget* target, Statement* statement);
|
||||
|
||||
/// Destructor
|
||||
~Call() override;
|
||||
|
||||
@@ -20,10 +20,11 @@
|
||||
namespace tint {
|
||||
|
||||
// Forward declarations
|
||||
namespace semantic {
|
||||
class Statement;
|
||||
} // namespace semantic
|
||||
namespace type {
|
||||
|
||||
class Type;
|
||||
|
||||
} // namespace type
|
||||
|
||||
namespace semantic {
|
||||
@@ -33,13 +34,18 @@ class Expression : public Castable<Expression, Node> {
|
||||
public:
|
||||
/// Constructor
|
||||
/// @param type the resolved type of the expression
|
||||
explicit Expression(type::Type* type);
|
||||
/// @param statement the statement that owns this expression
|
||||
explicit Expression(type::Type* type, Statement* statement);
|
||||
|
||||
/// @return the resolved type of the expression
|
||||
type::Type* Type() const { return type_; }
|
||||
|
||||
/// @return the statement that owns this expression
|
||||
Statement* Stmt() const { return statement_; }
|
||||
|
||||
private:
|
||||
type::Type* const type_;
|
||||
Statement* const statement_;
|
||||
};
|
||||
|
||||
} // namespace semantic
|
||||
|
||||
@@ -27,8 +27,11 @@ class MemberAccessorExpression
|
||||
public:
|
||||
/// Constructor
|
||||
/// @param type the resolved type of the expression
|
||||
/// @param statement the statement that owns this expression
|
||||
/// @param is_swizzle true if this member access is for a vector swizzle
|
||||
MemberAccessorExpression(type::Type* type, bool is_swizzle);
|
||||
MemberAccessorExpression(type::Type* type,
|
||||
Statement* statement,
|
||||
bool is_swizzle);
|
||||
|
||||
/// @return true if this member access is for a vector swizzle
|
||||
bool IsSwizzle() const { return is_swizzle_; }
|
||||
|
||||
@@ -19,8 +19,8 @@ TINT_INSTANTIATE_CLASS_ID(tint::semantic::Call);
|
||||
namespace tint {
|
||||
namespace semantic {
|
||||
|
||||
Call::Call(const CallTarget* target)
|
||||
: Base(target->ReturnType()), target_(target) {}
|
||||
Call::Call(const CallTarget* target, Statement* statement)
|
||||
: Base(target->ReturnType(), statement), target_(target) {}
|
||||
|
||||
Call::~Call() = default;
|
||||
|
||||
|
||||
@@ -21,7 +21,8 @@ TINT_INSTANTIATE_CLASS_ID(tint::semantic::Expression);
|
||||
namespace tint {
|
||||
namespace semantic {
|
||||
|
||||
Expression::Expression(type::Type* type) : type_(type->UnwrapIfNeeded()) {}
|
||||
Expression::Expression(type::Type* type, Statement* statement)
|
||||
: type_(type->UnwrapIfNeeded()), statement_(statement) {}
|
||||
|
||||
} // namespace semantic
|
||||
} // namespace tint
|
||||
|
||||
@@ -20,8 +20,9 @@ namespace tint {
|
||||
namespace semantic {
|
||||
|
||||
MemberAccessorExpression::MemberAccessorExpression(type::Type* type,
|
||||
Statement* statement,
|
||||
bool is_swizzle)
|
||||
: Base(type), is_swizzle_(is_swizzle) {}
|
||||
: Base(type, statement), is_swizzle_(is_swizzle) {}
|
||||
|
||||
} // namespace semantic
|
||||
} // namespace tint
|
||||
|
||||
27
src/semantic/sem_statement.cc
Normal file
27
src/semantic/sem_statement.cc
Normal file
@@ -0,0 +1,27 @@
|
||||
// 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/semantic/statement.h"
|
||||
|
||||
#include "src/type/type.h"
|
||||
|
||||
TINT_INSTANTIATE_CLASS_ID(tint::semantic::Statement);
|
||||
|
||||
namespace tint {
|
||||
namespace semantic {
|
||||
|
||||
Statement::Statement(ast::Statement* declaration) : declaration_(declaration) {}
|
||||
|
||||
} // namespace semantic
|
||||
} // namespace tint
|
||||
46
src/semantic/statement.h
Normal file
46
src/semantic/statement.h
Normal file
@@ -0,0 +1,46 @@
|
||||
// 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.
|
||||
|
||||
#ifndef SRC_SEMANTIC_STATEMENT_H_
|
||||
#define SRC_SEMANTIC_STATEMENT_H_
|
||||
|
||||
#include "src/semantic/node.h"
|
||||
|
||||
namespace tint {
|
||||
|
||||
// Forward declarations
|
||||
namespace ast {
|
||||
class Statement;
|
||||
} // namespace ast
|
||||
|
||||
namespace semantic {
|
||||
|
||||
/// Statement holds the semantic information for a statement.
|
||||
class Statement : public Castable<Statement, Node> {
|
||||
public:
|
||||
/// Constructor
|
||||
/// @param declaration the AST node for this statement
|
||||
explicit Statement(ast::Statement* declaration);
|
||||
|
||||
/// @return the AST node for this statement
|
||||
ast::Statement* Declaration() const { return declaration_; }
|
||||
|
||||
private:
|
||||
ast::Statement* const declaration_;
|
||||
};
|
||||
|
||||
} // namespace semantic
|
||||
} // namespace tint
|
||||
|
||||
#endif // SRC_SEMANTIC_STATEMENT_H_
|
||||
Reference in New Issue
Block a user