mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-12-08 13:14:56 +00:00
sem: Add FunctionBlockStatement
BlockStatement for the root block of a function Add some basic tests for this lot. Bug: tint:812 Change-Id: I26b65717798cbff576a44bd78fbcb5c8f0d013e6 Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/51368 Commit-Queue: Ben Clayton <bclayton@google.com> Reviewed-by: Antonio Maiorano <amaiorano@google.com> Reviewed-by: Alastair Donaldson <allydonaldson@googlemail.com>
This commit is contained in:
committed by
Tint LUCI CQ
parent
19d3205e15
commit
22d891c6c4
@@ -15,8 +15,11 @@
|
||||
#include "src/sem/block_statement.h"
|
||||
|
||||
#include "src/ast/block_statement.h"
|
||||
#include "src/ast/function.h"
|
||||
#include "src/sem/function.h"
|
||||
|
||||
TINT_INSTANTIATE_TYPEINFO(tint::sem::BlockStatement);
|
||||
TINT_INSTANTIATE_TYPEINFO(tint::sem::FunctionBlockStatement);
|
||||
TINT_INSTANTIATE_TYPEINFO(tint::sem::LoopBlockStatement);
|
||||
TINT_INSTANTIATE_TYPEINFO(tint::sem::LoopContinuingBlockStatement);
|
||||
TINT_INSTANTIATE_TYPEINFO(tint::sem::SwitchCaseBlockStatement);
|
||||
@@ -38,6 +41,11 @@ void BlockStatement::AddDecl(ast::Variable* var) {
|
||||
decls_.push_back(var);
|
||||
}
|
||||
|
||||
FunctionBlockStatement::FunctionBlockStatement(const ast::Function* function)
|
||||
: Base(function->body(), nullptr), function_(function) {}
|
||||
|
||||
FunctionBlockStatement::~FunctionBlockStatement() = default;
|
||||
|
||||
LoopBlockStatement::LoopBlockStatement(const ast::BlockStatement* declaration,
|
||||
const Statement* parent)
|
||||
: Base(declaration, parent) {}
|
||||
|
||||
@@ -19,14 +19,16 @@
|
||||
|
||||
#include "src/sem/statement.h"
|
||||
|
||||
namespace tint {
|
||||
|
||||
// Forward declarations
|
||||
namespace tint {
|
||||
namespace ast {
|
||||
class BlockStatement;
|
||||
class Function;
|
||||
class Variable;
|
||||
} // namespace ast
|
||||
} // namespace tint
|
||||
|
||||
namespace tint {
|
||||
namespace sem {
|
||||
|
||||
/// Holds semantic information about a block, such as parent block and variables
|
||||
@@ -84,6 +86,24 @@ class BlockStatement : public Castable<BlockStatement, Statement> {
|
||||
std::vector<const ast::Variable*> decls_;
|
||||
};
|
||||
|
||||
/// The root block statement for a function
|
||||
class FunctionBlockStatement
|
||||
: public Castable<FunctionBlockStatement, BlockStatement> {
|
||||
public:
|
||||
/// Constructor
|
||||
/// @param function the owning function
|
||||
explicit FunctionBlockStatement(const ast::Function* function);
|
||||
|
||||
/// Destructor
|
||||
~FunctionBlockStatement() override;
|
||||
|
||||
/// @returns the function owning this block
|
||||
const ast::Function* Function() const { return function_; }
|
||||
|
||||
private:
|
||||
ast::Function const* const function_;
|
||||
};
|
||||
|
||||
/// Holds semantic information about a loop block
|
||||
class LoopBlockStatement : public Castable<LoopBlockStatement, BlockStatement> {
|
||||
public:
|
||||
|
||||
@@ -65,5 +65,14 @@ const BlockStatement* Statement::Block() const {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
const ast::Function* Statement::Function() const {
|
||||
if (auto* block = Block()) {
|
||||
if (auto* fbs = block->FindFirstParent<FunctionBlockStatement>()) {
|
||||
return fbs->Function();
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
} // namespace sem
|
||||
} // namespace tint
|
||||
|
||||
@@ -17,16 +17,19 @@
|
||||
|
||||
#include "src/sem/node.h"
|
||||
|
||||
namespace tint {
|
||||
|
||||
// Forward declarations
|
||||
namespace tint {
|
||||
namespace ast {
|
||||
class Function;
|
||||
class Statement;
|
||||
} // namespace ast
|
||||
|
||||
namespace sem {
|
||||
|
||||
class BlockStatement;
|
||||
} // namespace sem
|
||||
} // namespace tint
|
||||
|
||||
namespace tint {
|
||||
namespace sem {
|
||||
|
||||
/// Statement holds the semantic information for a statement.
|
||||
class Statement : public Castable<Statement, Node> {
|
||||
@@ -45,6 +48,9 @@ class Statement : public Castable<Statement, Node> {
|
||||
/// @return the closest enclosing block for this statement
|
||||
const BlockStatement* Block() const;
|
||||
|
||||
/// @returns the function that owns this statement
|
||||
const ast::Function* Function() const;
|
||||
|
||||
private:
|
||||
ast::Statement const* const declaration_;
|
||||
Statement const* const parent_;
|
||||
|
||||
Reference in New Issue
Block a user