mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-12-18 09:25:25 +00:00
Add semantic::Statement::Block() for getting the owning BlockStatement
Required special casing the ElseStatement, as this isn't actually owned by a BlockStatement. Change-Id: Ic33c207598b838a12b865a7694e596b2629c9208 Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/46443 Reviewed-by: Antonio Maiorano <amaiorano@google.com> Commit-Queue: Ben Clayton <bclayton@google.com>
This commit is contained in:
committed by
Commit Bot service account
parent
285b8b6e75
commit
dba65b7a34
@@ -12,6 +12,10 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
#include "src/ast/block_statement.h"
|
||||
#include "src/debug.h"
|
||||
#include "src/semantic/statement.h"
|
||||
|
||||
TINT_INSTANTIATE_TYPEINFO(tint::semantic::Statement);
|
||||
@@ -19,7 +23,17 @@ TINT_INSTANTIATE_TYPEINFO(tint::semantic::Statement);
|
||||
namespace tint {
|
||||
namespace semantic {
|
||||
|
||||
Statement::Statement(ast::Statement* declaration) : declaration_(declaration) {}
|
||||
Statement::Statement(const ast::Statement* declaration,
|
||||
const ast::BlockStatement* block)
|
||||
: declaration_(declaration), block_(block) {
|
||||
#ifndef NDEBUG
|
||||
if (block) {
|
||||
auto& stmts = block->statements();
|
||||
TINT_ASSERT(std::find(stmts.begin(), stmts.end(), declaration) !=
|
||||
stmts.end());
|
||||
}
|
||||
#endif // NDEBUG
|
||||
}
|
||||
|
||||
} // namespace semantic
|
||||
} // namespace tint
|
||||
|
||||
@@ -21,6 +21,7 @@ namespace tint {
|
||||
|
||||
// Forward declarations
|
||||
namespace ast {
|
||||
class BlockStatement;
|
||||
class Statement;
|
||||
} // namespace ast
|
||||
|
||||
@@ -31,13 +32,19 @@ class Statement : public Castable<Statement, Node> {
|
||||
public:
|
||||
/// Constructor
|
||||
/// @param declaration the AST node for this statement
|
||||
explicit Statement(ast::Statement* declaration);
|
||||
/// @param block the owning AST block statement
|
||||
Statement(const ast::Statement* declaration,
|
||||
const ast::BlockStatement* block);
|
||||
|
||||
/// @return the AST node for this statement
|
||||
ast::Statement* Declaration() const { return declaration_; }
|
||||
const ast::Statement* Declaration() const { return declaration_; }
|
||||
|
||||
/// @return the owning AST block statement for this statement
|
||||
const ast::BlockStatement* Block() const { return block_; }
|
||||
|
||||
private:
|
||||
ast::Statement* const declaration_;
|
||||
ast::Statement const* const declaration_;
|
||||
ast::BlockStatement const* const block_;
|
||||
};
|
||||
|
||||
} // namespace semantic
|
||||
|
||||
@@ -25,6 +25,7 @@ class CallExpression;
|
||||
class Expression;
|
||||
class Function;
|
||||
class MemberAccessorExpression;
|
||||
class Statement;
|
||||
class StructMember;
|
||||
class Variable;
|
||||
} // namespace ast
|
||||
@@ -41,6 +42,7 @@ class Call;
|
||||
class Expression;
|
||||
class Function;
|
||||
class MemberAccessorExpression;
|
||||
class Statement;
|
||||
class Struct;
|
||||
class StructMember;
|
||||
class Variable;
|
||||
@@ -56,6 +58,7 @@ struct TypeMappings {
|
||||
Expression* operator()(ast::Expression*);
|
||||
Function* operator()(ast::Function*);
|
||||
MemberAccessorExpression* operator()(ast::MemberAccessorExpression*);
|
||||
Statement* operator()(ast::Statement*);
|
||||
Struct* operator()(type::Struct*);
|
||||
StructMember* operator()(ast::StructMember*);
|
||||
Variable* operator()(ast::Variable*);
|
||||
|
||||
Reference in New Issue
Block a user