Add stub definitions to the type determiner.
This adds enough infrastructure to type determiner to start building out the statement and expression determination. Bug: tint:5 Change-Id: I5e095cf652b5e3358e6fbabd66dd703348950857 Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/18826 Reviewed-by: David Neto <dneto@google.com>
This commit is contained in:
parent
d0479d22ea
commit
417a90d2ee
|
@ -23,8 +23,62 @@ TypeDeterminer::TypeDeterminer(Context* ctx) : ctx_(*ctx) {
|
||||||
|
|
||||||
TypeDeterminer::~TypeDeterminer() = default;
|
TypeDeterminer::~TypeDeterminer() = default;
|
||||||
|
|
||||||
bool TypeDeterminer::Determine(ast::Module*) {
|
bool TypeDeterminer::Determine(ast::Module* mod) {
|
||||||
|
for (const auto& var : mod->global_variables()) {
|
||||||
|
variable_stack_.set_global(var->name(), var.get());
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const auto& func : mod->functions()) {
|
||||||
|
name_to_function_[func->name()] = func.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!DetermineFunctions(mod->functions())) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool TypeDeterminer::DetermineFunctions(const ast::FunctionList& funcs) {
|
||||||
|
for (const auto& func : funcs) {
|
||||||
|
if (!DetermineFunction(func.get())) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool TypeDeterminer::DetermineFunction(ast::Function* func) {
|
||||||
|
variable_stack_.push_scope();
|
||||||
|
if (!DetermineResultType(func->body())) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
variable_stack_.pop_scope();
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool TypeDeterminer::DetermineResultType(const ast::StatementList& stmts) {
|
||||||
|
for (const auto& stmt : stmts) {
|
||||||
|
if (!DetermineResultType(stmt.get())) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool TypeDeterminer::DetermineResultType(ast::Statement*) {
|
||||||
|
error_ = "unknown statement type for type determination";
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool TypeDeterminer::DetermineResultType(ast::Expression* expr) {
|
||||||
|
// This is blindly called above, so in some cases the expression won't exist.
|
||||||
|
if (!expr) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
error_ = "unknown expression for type determination";
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace tint
|
} // namespace tint
|
||||||
|
|
|
@ -38,14 +38,34 @@ class TypeDeterminer {
|
||||||
explicit TypeDeterminer(Context* ctx);
|
explicit TypeDeterminer(Context* ctx);
|
||||||
~TypeDeterminer();
|
~TypeDeterminer();
|
||||||
|
|
||||||
/// Runs the type determiner
|
|
||||||
/// @param module the module to update with typing information
|
|
||||||
/// @returns true if the type determiner was successful
|
|
||||||
bool Determine(ast::Module* module);
|
|
||||||
|
|
||||||
/// @returns error messages from the type determiner
|
/// @returns error messages from the type determiner
|
||||||
const std::string& error() { return error_; }
|
const std::string& error() { return error_; }
|
||||||
|
|
||||||
|
/// Runs the type determiner
|
||||||
|
/// @param mod the module to update with typing information
|
||||||
|
/// @returns true if the type determiner was successful
|
||||||
|
bool Determine(ast::Module* mod);
|
||||||
|
/// Determines type information for functions
|
||||||
|
/// @param funcs the functions to check
|
||||||
|
/// @returns true if the determination was successful
|
||||||
|
bool DetermineFunctions(const ast::FunctionList& funcs);
|
||||||
|
/// Determines type information for a function
|
||||||
|
/// @param func the function to check
|
||||||
|
/// @returns true if the determination was successful
|
||||||
|
bool DetermineFunction(ast::Function* func);
|
||||||
|
/// Determines type information for a set of statements
|
||||||
|
/// @param stmts the statements to check
|
||||||
|
/// @returns true if the determination was successful
|
||||||
|
bool DetermineResultType(const ast::StatementList& stmts);
|
||||||
|
/// Determines type information for a statement
|
||||||
|
/// @param stmt the statement to check
|
||||||
|
/// @returns true if the determination was successful
|
||||||
|
bool DetermineResultType(ast::Statement* stmt);
|
||||||
|
/// Determines type information for an expression
|
||||||
|
/// @param expr the expression to check
|
||||||
|
/// @returns true if the determination was successful
|
||||||
|
bool DetermineResultType(ast::Expression* expr);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Context& ctx_;
|
Context& ctx_;
|
||||||
std::string error_;
|
std::string error_;
|
||||||
|
|
Loading…
Reference in New Issue