2020-03-02 20:47:43 +00:00
|
|
|
// Copyright 2020 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.
|
|
|
|
|
2021-03-09 10:54:37 +00:00
|
|
|
#ifndef SRC_RESOLVER_RESOLVER_H_
|
|
|
|
#define SRC_RESOLVER_RESOLVER_H_
|
2020-03-02 20:47:43 +00:00
|
|
|
|
2021-02-08 22:42:54 +00:00
|
|
|
#include <memory>
|
2020-03-02 20:47:43 +00:00
|
|
|
#include <string>
|
2020-04-06 18:43:56 +00:00
|
|
|
#include <unordered_map>
|
2021-03-17 22:47:33 +00:00
|
|
|
#include <unordered_set>
|
2020-11-03 16:26:09 +00:00
|
|
|
#include <vector>
|
2020-03-02 20:47:43 +00:00
|
|
|
|
2021-02-08 22:42:54 +00:00
|
|
|
#include "src/intrinsic_table.h"
|
2021-01-29 16:43:41 +00:00
|
|
|
#include "src/program_builder.h"
|
2020-04-06 18:43:56 +00:00
|
|
|
#include "src/scope_stack.h"
|
2021-04-16 19:07:51 +00:00
|
|
|
#include "src/sem/struct.h"
|
2021-02-17 13:10:49 +00:00
|
|
|
#include "src/utils/unique_vector.h"
|
2020-03-02 20:47:43 +00:00
|
|
|
|
|
|
|
namespace tint {
|
2020-04-06 18:43:56 +00:00
|
|
|
|
2021-02-16 18:45:45 +00:00
|
|
|
// Forward declarations
|
|
|
|
namespace ast {
|
2020-04-07 12:57:42 +00:00
|
|
|
class ArrayAccessorExpression;
|
2020-04-07 19:27:41 +00:00
|
|
|
class BinaryExpression;
|
2020-09-22 22:07:13 +00:00
|
|
|
class BitcastExpression;
|
2020-04-07 16:41:10 +00:00
|
|
|
class CallExpression;
|
2021-03-09 15:06:37 +00:00
|
|
|
class CaseStatement;
|
2020-04-07 12:46:30 +00:00
|
|
|
class ConstructorExpression;
|
2020-04-07 19:26:39 +00:00
|
|
|
class Function;
|
2020-04-07 12:57:27 +00:00
|
|
|
class IdentifierExpression;
|
2020-04-07 16:41:33 +00:00
|
|
|
class MemberAccessorExpression;
|
2021-03-17 14:24:04 +00:00
|
|
|
class ReturnStatement;
|
2021-03-25 12:55:27 +00:00
|
|
|
class SwitchStatement;
|
2020-04-07 19:27:11 +00:00
|
|
|
class UnaryOpExpression;
|
2020-04-06 18:43:56 +00:00
|
|
|
class Variable;
|
|
|
|
} // namespace ast
|
2021-04-16 19:07:51 +00:00
|
|
|
namespace sem {
|
2021-03-15 10:43:11 +00:00
|
|
|
class Array;
|
2021-02-16 18:45:45 +00:00
|
|
|
class Statement;
|
2021-04-16 19:07:51 +00:00
|
|
|
} // namespace sem
|
2021-04-19 22:51:23 +00:00
|
|
|
namespace sem {
|
|
|
|
class StructType;
|
|
|
|
} // namespace sem
|
2020-03-02 20:47:43 +00:00
|
|
|
|
2021-03-09 15:08:48 +00:00
|
|
|
namespace resolver {
|
|
|
|
|
2021-03-09 10:54:37 +00:00
|
|
|
/// Resolves types for all items in the given tint program
|
|
|
|
class Resolver {
|
2020-03-02 20:47:43 +00:00
|
|
|
public:
|
|
|
|
/// Constructor
|
2021-01-26 16:57:10 +00:00
|
|
|
/// @param builder the program builder
|
2021-03-09 10:54:37 +00:00
|
|
|
explicit Resolver(ProgramBuilder* builder);
|
2021-01-25 18:14:08 +00:00
|
|
|
|
|
|
|
/// Destructor
|
2021-03-09 10:54:37 +00:00
|
|
|
~Resolver();
|
2020-03-02 20:47:43 +00:00
|
|
|
|
2021-03-09 10:54:37 +00:00
|
|
|
/// @returns error messages from the resolver
|
2021-02-17 20:13:34 +00:00
|
|
|
std::string error() const { return diagnostics_.str(); }
|
2020-03-02 20:47:43 +00:00
|
|
|
|
2021-03-09 10:54:37 +00:00
|
|
|
/// @returns true if the resolver was successful
|
|
|
|
bool Resolve();
|
2020-04-06 21:07:41 +00:00
|
|
|
|
2021-03-15 10:43:11 +00:00
|
|
|
/// @param type the given type
|
2021-03-18 20:46:24 +00:00
|
|
|
/// @returns true if the given type is storable
|
2021-04-28 12:38:13 +00:00
|
|
|
static bool IsStorable(const sem::Type* type);
|
2021-03-15 10:43:11 +00:00
|
|
|
|
2021-03-18 20:46:24 +00:00
|
|
|
/// @param type the given type
|
2021-03-18 21:03:24 +00:00
|
|
|
/// @returns true if the given type is host-shareable
|
2021-04-28 12:38:13 +00:00
|
|
|
static bool IsHostShareable(const sem::Type* type);
|
2021-03-18 20:46:24 +00:00
|
|
|
|
2021-03-18 21:14:44 +00:00
|
|
|
/// @param lhs the assignment store type (non-pointer)
|
|
|
|
/// @param rhs the assignment source type (non-pointer or pointer with
|
|
|
|
/// auto-deref)
|
|
|
|
/// @returns true an expression of type `rhs` can be assigned to a variable,
|
|
|
|
/// structure member or array element of type `lhs`
|
2021-04-28 12:38:13 +00:00
|
|
|
static bool IsValidAssignment(const sem::Type* lhs, const sem::Type* rhs);
|
2021-03-18 21:14:44 +00:00
|
|
|
|
2021-04-13 13:32:33 +00:00
|
|
|
/// @param type the input type
|
|
|
|
/// @returns the canonical type for `type`; that is, a type with all aliases
|
|
|
|
/// removed. For example, `Canonical(alias<alias<vec3<alias<f32>>>>)` is
|
|
|
|
/// `vec3<f32>`.
|
2021-04-28 12:38:13 +00:00
|
|
|
const sem::Type* Canonical(const sem::Type* type);
|
2021-04-13 13:32:33 +00:00
|
|
|
|
2020-03-02 20:47:43 +00:00
|
|
|
private:
|
2021-02-16 18:45:45 +00:00
|
|
|
/// Structure holding semantic information about a variable.
|
2021-04-16 19:07:51 +00:00
|
|
|
/// Used to build the sem::Variable nodes at the end of resolving.
|
2021-02-03 17:51:09 +00:00
|
|
|
struct VariableInfo {
|
2021-04-28 13:50:43 +00:00
|
|
|
VariableInfo(const ast::Variable* decl,
|
|
|
|
const sem::Type* type,
|
|
|
|
const std::string& type_name);
|
2021-02-03 17:51:09 +00:00
|
|
|
~VariableInfo();
|
|
|
|
|
2021-04-28 12:38:13 +00:00
|
|
|
ast::Variable const* const declaration;
|
|
|
|
sem::Type const* type;
|
2021-04-28 13:50:43 +00:00
|
|
|
std::string const type_name;
|
2021-02-03 17:51:09 +00:00
|
|
|
ast::StorageClass storage_class;
|
2021-02-16 21:15:01 +00:00
|
|
|
std::vector<ast::IdentifierExpression*> users;
|
2021-02-03 17:51:09 +00:00
|
|
|
};
|
|
|
|
|
2021-02-03 16:43:20 +00:00
|
|
|
/// Structure holding semantic information about a function.
|
2021-04-16 19:07:51 +00:00
|
|
|
/// Used to build the sem::Function nodes at the end of resolving.
|
2021-02-03 16:43:20 +00:00
|
|
|
struct FunctionInfo {
|
|
|
|
explicit FunctionInfo(ast::Function* decl);
|
|
|
|
~FunctionInfo();
|
|
|
|
|
|
|
|
ast::Function* const declaration;
|
2021-04-09 13:56:08 +00:00
|
|
|
std::vector<VariableInfo*> parameters;
|
2021-02-03 17:51:09 +00:00
|
|
|
UniqueVector<VariableInfo*> referenced_module_vars;
|
|
|
|
UniqueVector<VariableInfo*> local_referenced_module_vars;
|
2021-03-17 14:24:04 +00:00
|
|
|
std::vector<const ast::ReturnStatement*> return_statements;
|
2021-04-30 19:24:29 +00:00
|
|
|
sem::Type const* return_type = nullptr;
|
|
|
|
std::string return_type_name;
|
2021-03-03 19:54:44 +00:00
|
|
|
|
|
|
|
// List of transitive calls this function makes
|
|
|
|
UniqueVector<FunctionInfo*> transitive_calls;
|
2021-02-03 16:43:20 +00:00
|
|
|
};
|
|
|
|
|
2021-02-16 18:45:45 +00:00
|
|
|
/// Structure holding semantic information about an expression.
|
2021-04-16 19:07:51 +00:00
|
|
|
/// Used to build the sem::Expression nodes at the end of resolving.
|
2021-02-16 18:45:45 +00:00
|
|
|
struct ExpressionInfo {
|
2021-04-28 12:38:13 +00:00
|
|
|
sem::Type const* type;
|
2021-04-28 13:50:43 +00:00
|
|
|
std::string const type_name; // Declared type name
|
2021-04-16 19:07:51 +00:00
|
|
|
sem::Statement* statement;
|
2021-02-16 18:45:45 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/// Structure holding semantic information about a call expression to an
|
|
|
|
/// ast::Function.
|
2021-04-16 19:07:51 +00:00
|
|
|
/// Used to build the sem::Call nodes at the end of resolving.
|
2021-02-16 18:45:45 +00:00
|
|
|
struct FunctionCallInfo {
|
|
|
|
FunctionInfo* function;
|
2021-04-16 19:07:51 +00:00
|
|
|
sem::Statement* statement;
|
2021-02-16 18:45:45 +00:00
|
|
|
};
|
|
|
|
|
2021-03-17 22:01:53 +00:00
|
|
|
/// Structure holding semantic information about a struct.
|
2021-04-16 19:07:51 +00:00
|
|
|
/// Used to build the sem::Struct nodes at the end of resolving.
|
2021-03-17 22:01:53 +00:00
|
|
|
struct StructInfo {
|
|
|
|
StructInfo();
|
|
|
|
~StructInfo();
|
|
|
|
|
2021-04-16 19:07:51 +00:00
|
|
|
std::vector<const sem::StructMember*> members;
|
2021-03-17 22:01:53 +00:00
|
|
|
uint32_t align = 0;
|
|
|
|
uint32_t size = 0;
|
|
|
|
uint32_t size_no_padding = 0;
|
2021-03-17 22:47:33 +00:00
|
|
|
std::unordered_set<ast::StorageClass> storage_class_usage;
|
2021-04-16 19:07:51 +00:00
|
|
|
std::unordered_set<sem::PipelineStageUsage> pipeline_stage_uses;
|
2021-03-17 22:01:53 +00:00
|
|
|
};
|
|
|
|
|
2021-03-09 10:26:57 +00:00
|
|
|
/// Structure holding semantic information about a block (i.e. scope), such as
|
|
|
|
/// parent block and variables declared in the block.
|
|
|
|
/// Used to validate variable scoping rules.
|
|
|
|
struct BlockInfo {
|
2021-03-09 15:06:37 +00:00
|
|
|
enum class Type { kGeneric, kLoop, kLoopContinuing, kSwitchCase };
|
2021-03-09 10:26:57 +00:00
|
|
|
|
2021-03-31 20:35:46 +00:00
|
|
|
BlockInfo(const ast::BlockStatement* block, Type type, BlockInfo* parent);
|
2021-03-09 10:26:57 +00:00
|
|
|
~BlockInfo();
|
|
|
|
|
|
|
|
template <typename Pred>
|
|
|
|
BlockInfo* FindFirstParent(Pred&& pred) {
|
|
|
|
BlockInfo* curr = this;
|
|
|
|
while (curr && !pred(curr)) {
|
|
|
|
curr = curr->parent;
|
|
|
|
}
|
|
|
|
return curr;
|
|
|
|
}
|
|
|
|
|
2021-03-09 10:54:37 +00:00
|
|
|
BlockInfo* FindFirstParent(BlockInfo::Type ty) {
|
2021-03-09 10:26:57 +00:00
|
|
|
return FindFirstParent(
|
2021-03-09 10:54:37 +00:00
|
|
|
[ty](auto* block_info) { return block_info->type == ty; });
|
2021-03-09 10:26:57 +00:00
|
|
|
}
|
|
|
|
|
2021-03-31 20:35:46 +00:00
|
|
|
ast::BlockStatement const* const block;
|
2021-03-09 15:06:37 +00:00
|
|
|
Type const type;
|
|
|
|
BlockInfo* const parent;
|
2021-03-09 10:26:57 +00:00
|
|
|
std::vector<const ast::Variable*> decls;
|
|
|
|
|
|
|
|
// first_continue is set to the index of the first variable in decls
|
|
|
|
// declared after the first continue statement in a loop block, if any.
|
|
|
|
constexpr static size_t kNoContinue = size_t(~0);
|
|
|
|
size_t first_continue = kNoContinue;
|
|
|
|
};
|
|
|
|
|
2021-03-09 10:54:37 +00:00
|
|
|
/// Resolves the program, without creating final the semantic nodes.
|
|
|
|
/// @returns true on success, false on error
|
|
|
|
bool ResolveInternal();
|
2021-02-03 17:51:09 +00:00
|
|
|
|
2021-04-16 19:07:51 +00:00
|
|
|
/// Creates the nodes and adds them to the sem::Info mappings of the
|
2021-02-03 17:51:09 +00:00
|
|
|
/// ProgramBuilder.
|
|
|
|
void CreateSemanticNodes() const;
|
|
|
|
|
|
|
|
/// Retrieves information for the requested import.
|
|
|
|
/// @param src the source of the import
|
|
|
|
/// @param path the import path
|
|
|
|
/// @param name the method name to get information on
|
|
|
|
/// @param params the parameters to the method call
|
|
|
|
/// @param id out parameter for the external call ID. Must not be a nullptr.
|
|
|
|
/// @returns the return type of `name` in `path` or nullptr on error.
|
2021-04-19 22:51:23 +00:00
|
|
|
sem::Type* GetImportData(const Source& src,
|
|
|
|
const std::string& path,
|
|
|
|
const std::string& name,
|
|
|
|
const ast::ExpressionList& params,
|
|
|
|
uint32_t* id);
|
2021-02-03 17:51:09 +00:00
|
|
|
|
|
|
|
void set_referenced_from_function_if_needed(VariableInfo* var, bool local);
|
2020-04-08 19:58:35 +00:00
|
|
|
|
2021-03-15 10:43:11 +00:00
|
|
|
// AST and Type traversal methods
|
|
|
|
// Each return true on success, false on failure.
|
|
|
|
bool ArrayAccessor(ast::ArrayAccessorExpression*);
|
2021-04-19 19:16:12 +00:00
|
|
|
bool Assignment(ast::AssignmentStatement* a);
|
2021-03-15 10:43:11 +00:00
|
|
|
bool Binary(ast::BinaryExpression*);
|
|
|
|
bool Bitcast(ast::BitcastExpression*);
|
|
|
|
bool BlockStatement(const ast::BlockStatement*);
|
|
|
|
bool Call(ast::CallExpression*);
|
|
|
|
bool CaseStatement(ast::CaseStatement*);
|
|
|
|
bool Constructor(ast::ConstructorExpression*);
|
|
|
|
bool Expression(ast::Expression*);
|
|
|
|
bool Expressions(const ast::ExpressionList&);
|
|
|
|
bool Function(ast::Function*);
|
2021-04-19 19:16:12 +00:00
|
|
|
bool GlobalVariable(ast::Variable* var);
|
2021-03-15 10:43:11 +00:00
|
|
|
bool Identifier(ast::IdentifierExpression*);
|
|
|
|
bool IfStatement(ast::IfStatement*);
|
2021-04-16 19:07:51 +00:00
|
|
|
bool IntrinsicCall(ast::CallExpression*, sem::IntrinsicType);
|
2021-03-15 10:43:11 +00:00
|
|
|
bool MemberAccessor(ast::MemberAccessorExpression*);
|
2021-04-19 19:16:12 +00:00
|
|
|
bool Parameter(ast::Variable* param);
|
|
|
|
bool Return(ast::ReturnStatement* ret);
|
2021-03-15 10:43:11 +00:00
|
|
|
bool Statement(ast::Statement*);
|
|
|
|
bool Statements(const ast::StatementList&);
|
2021-04-19 19:16:12 +00:00
|
|
|
bool Switch(ast::SwitchStatement* s);
|
2021-04-30 20:20:19 +00:00
|
|
|
bool Type(const sem::Type* ty, const Source& source = {});
|
2021-03-15 10:43:11 +00:00
|
|
|
bool UnaryOp(ast::UnaryOpExpression*);
|
|
|
|
bool VariableDeclStatement(const ast::VariableDeclStatement*);
|
|
|
|
|
2021-03-18 21:14:44 +00:00
|
|
|
// AST and Type validation methods
|
|
|
|
// Each return true on success, false on failure.
|
2021-04-21 16:45:02 +00:00
|
|
|
bool ValidateArray(const sem::ArrayType* arr, const Source& source);
|
|
|
|
bool ValidateArrayStrideDecoration(const ast::StrideDecoration* deco,
|
|
|
|
uint32_t el_size,
|
|
|
|
uint32_t el_align,
|
|
|
|
const Source& source);
|
2021-04-19 19:16:12 +00:00
|
|
|
bool ValidateAssignment(const ast::AssignmentStatement* a);
|
2021-03-18 21:14:44 +00:00
|
|
|
bool ValidateBinary(ast::BinaryExpression* expr);
|
2021-04-21 16:13:42 +00:00
|
|
|
bool ValidateEntryPoint(const ast::Function* func, const FunctionInfo* info);
|
|
|
|
bool ValidateFunction(const ast::Function* func, const FunctionInfo* info);
|
2021-04-19 20:20:33 +00:00
|
|
|
bool ValidateGlobalVariable(const VariableInfo* var);
|
2021-04-28 13:50:43 +00:00
|
|
|
bool ValidateMatrixConstructor(const ast::TypeConstructorExpression* ctor,
|
|
|
|
const sem::Matrix* matrix_type,
|
2021-04-19 19:16:12 +00:00
|
|
|
const ast::ExpressionList& values);
|
|
|
|
bool ValidateParameter(const ast::Variable* param);
|
2021-03-22 23:20:17 +00:00
|
|
|
bool ValidateReturn(const ast::ReturnStatement* ret);
|
2021-04-19 22:51:23 +00:00
|
|
|
bool ValidateStructure(const sem::StructType* st);
|
2021-03-25 12:55:27 +00:00
|
|
|
bool ValidateSwitch(const ast::SwitchStatement* s);
|
2021-04-19 19:16:12 +00:00
|
|
|
bool ValidateVariable(const ast::Variable* param);
|
2021-04-28 13:50:43 +00:00
|
|
|
bool ValidateVectorConstructor(const ast::TypeConstructorExpression* ctor,
|
|
|
|
const sem::Vector* vec_type,
|
2021-04-19 19:16:12 +00:00
|
|
|
const ast::ExpressionList& values);
|
2021-03-18 21:14:44 +00:00
|
|
|
|
2021-04-21 13:47:12 +00:00
|
|
|
/// @returns the sem::Type for the ast::Type `ty`, building it if it
|
|
|
|
/// hasn't been constructed already. If an error is raised, nullptr is
|
|
|
|
/// returned.
|
|
|
|
/// @param ty the ast::Type
|
2021-04-30 20:20:19 +00:00
|
|
|
const sem::Type* Type(const ast::Type* ty);
|
2021-04-21 13:47:12 +00:00
|
|
|
|
2021-03-15 10:43:11 +00:00
|
|
|
/// @returns the semantic information for the array `arr`, building it if it
|
|
|
|
/// hasn't been constructed already. If an error is raised, nullptr is
|
|
|
|
/// returned.
|
2021-04-16 01:15:43 +00:00
|
|
|
/// @param arr the Array to get semantic information for
|
|
|
|
/// @param source the Source of the ast node with this array as its type
|
2021-04-28 12:38:13 +00:00
|
|
|
const sem::Array* Array(const sem::ArrayType* arr, const Source& source);
|
2021-03-15 10:43:11 +00:00
|
|
|
|
2021-03-17 22:01:53 +00:00
|
|
|
/// @returns the StructInfo for the structure `str`, building it if it hasn't
|
|
|
|
/// been constructed already. If an error is raised, nullptr is returned.
|
2021-04-28 12:38:13 +00:00
|
|
|
StructInfo* Structure(const sem::StructType* str);
|
2021-03-15 10:43:11 +00:00
|
|
|
|
2021-04-16 01:15:43 +00:00
|
|
|
/// @returns the VariableInfo for the variable `var`, building it if it hasn't
|
|
|
|
/// been constructed already. If an error is raised, nullptr is returned.
|
|
|
|
/// @param var the variable to create or return the `VariableInfo` for
|
|
|
|
/// @param type optional type of `var` to use instead of
|
|
|
|
/// `var->declared_type()`. For type inference.
|
2021-04-28 12:38:13 +00:00
|
|
|
VariableInfo* Variable(ast::Variable* var, const sem::Type* type = nullptr);
|
2021-04-16 01:15:43 +00:00
|
|
|
|
2021-03-17 22:47:33 +00:00
|
|
|
/// Records the storage class usage for the given type, and any transient
|
|
|
|
/// dependencies of the type. Validates that the type can be used for the
|
|
|
|
/// given storage class, erroring if it cannot.
|
2021-03-18 20:46:24 +00:00
|
|
|
/// @param sc the storage class to apply to the type and transitent types
|
|
|
|
/// @param ty the type to apply the storage class on
|
|
|
|
/// @param usage the Source of the root variable declaration that uses the
|
|
|
|
/// given type and storage class. Used for generating sensible error messages.
|
2021-03-17 22:47:33 +00:00
|
|
|
/// @returns true on success, false on error
|
2021-03-18 20:46:24 +00:00
|
|
|
bool ApplyStorageClassUsageToType(ast::StorageClass sc,
|
2021-04-28 12:38:13 +00:00
|
|
|
const sem::Type* ty,
|
2021-04-16 01:15:43 +00:00
|
|
|
const Source& usage);
|
2021-03-17 22:47:33 +00:00
|
|
|
|
2021-03-15 10:43:11 +00:00
|
|
|
/// @param align the output default alignment in bytes for the type `ty`
|
|
|
|
/// @param size the output default size in bytes for the type `ty`
|
2021-04-16 01:15:43 +00:00
|
|
|
/// @param source the Source of the variable declaration of type `ty`
|
2021-03-15 10:43:11 +00:00
|
|
|
/// @returns true on success, false on error
|
2021-04-19 22:51:23 +00:00
|
|
|
bool DefaultAlignAndSize(sem::Type* ty,
|
2021-04-16 01:15:43 +00:00
|
|
|
uint32_t& align,
|
|
|
|
uint32_t& size,
|
|
|
|
const Source& source);
|
2021-02-03 17:51:09 +00:00
|
|
|
|
2021-01-29 16:43:41 +00:00
|
|
|
/// @returns the resolved type of the ast::Expression `expr`
|
|
|
|
/// @param expr the expression
|
2021-04-28 13:50:43 +00:00
|
|
|
const sem::Type* TypeOf(const ast::Expression* expr);
|
|
|
|
|
|
|
|
/// @returns the declared type name of the ast::Expression `expr`
|
|
|
|
/// @param expr the type name
|
|
|
|
std::string TypeNameOf(const ast::Expression* expr);
|
|
|
|
|
|
|
|
/// @returns the semantic type of the AST literal `lit`
|
|
|
|
/// @param lit the literal
|
|
|
|
const sem::Type* TypeOf(const ast::Literal* lit);
|
2021-01-29 16:43:41 +00:00
|
|
|
|
2021-04-16 19:07:51 +00:00
|
|
|
/// Creates a sem::Expression node with the resolved type `type`, and
|
2021-01-29 16:43:41 +00:00
|
|
|
/// assigns this semantic node to the expression `expr`.
|
|
|
|
/// @param expr the expression
|
|
|
|
/// @param type the resolved type
|
2021-04-28 12:38:13 +00:00
|
|
|
void SetType(ast::Expression* expr, const sem::Type* type);
|
2021-01-29 16:43:41 +00:00
|
|
|
|
2021-04-28 13:50:43 +00:00
|
|
|
/// Creates a sem::Expression node with the resolved type `type`, the declared
|
|
|
|
/// type name `type_name` and assigns this semantic node to the expression
|
|
|
|
/// `expr`.
|
|
|
|
/// @param expr the expression
|
|
|
|
/// @param type the resolved type
|
|
|
|
/// @param type_name the declared type name
|
|
|
|
void SetType(ast::Expression* expr,
|
|
|
|
const sem::Type* type,
|
|
|
|
const std::string& type_name);
|
|
|
|
|
2021-03-09 15:06:37 +00:00
|
|
|
/// Constructs a new BlockInfo with the given type and with #current_block_ as
|
|
|
|
/// its parent, assigns this to #current_block_, and then calls `callback`.
|
|
|
|
/// The original #current_block_ is restored on exit.
|
|
|
|
template <typename F>
|
2021-03-31 20:35:46 +00:00
|
|
|
bool BlockScope(const ast::BlockStatement* block,
|
|
|
|
BlockInfo::Type type,
|
|
|
|
F&& callback);
|
2021-03-09 15:06:37 +00:00
|
|
|
|
2021-03-18 15:43:14 +00:00
|
|
|
/// Returns a human-readable string representation of the vector type name
|
|
|
|
/// with the given parameters.
|
|
|
|
/// @param size the vector dimension
|
|
|
|
/// @param element_type scalar vector sub-element type
|
|
|
|
/// @return pretty string representation
|
2021-04-19 22:51:23 +00:00
|
|
|
std::string VectorPretty(uint32_t size, sem::Type* element_type);
|
2021-03-18 15:43:14 +00:00
|
|
|
|
2021-04-19 19:16:12 +00:00
|
|
|
/// Mark records that the given AST node has been visited, and asserts that
|
|
|
|
/// the given node has not already been seen. Diamonds in the AST are illegal.
|
|
|
|
/// @param node the AST node.
|
2021-04-28 12:38:13 +00:00
|
|
|
void Mark(const ast::Node* node);
|
2021-04-19 19:16:12 +00:00
|
|
|
|
2021-02-08 22:31:44 +00:00
|
|
|
ProgramBuilder* const builder_;
|
2021-02-08 22:42:54 +00:00
|
|
|
std::unique_ptr<IntrinsicTable> const intrinsic_table_;
|
2021-02-17 20:13:34 +00:00
|
|
|
diag::List diagnostics_;
|
2021-03-09 15:06:37 +00:00
|
|
|
BlockInfo* current_block_ = nullptr;
|
2021-02-03 17:51:09 +00:00
|
|
|
ScopeStack<VariableInfo*> variable_stack_;
|
2021-02-03 16:43:20 +00:00
|
|
|
std::unordered_map<Symbol, FunctionInfo*> symbol_to_function_;
|
2021-03-19 14:04:51 +00:00
|
|
|
std::unordered_map<const ast::Function*, FunctionInfo*> function_to_info_;
|
2021-03-26 12:47:58 +00:00
|
|
|
std::unordered_map<const ast::Variable*, VariableInfo*> variable_to_info_;
|
2021-02-16 18:45:45 +00:00
|
|
|
std::unordered_map<ast::CallExpression*, FunctionCallInfo> function_calls_;
|
2021-04-28 13:50:43 +00:00
|
|
|
std::unordered_map<const ast::Expression*, ExpressionInfo> expr_info_;
|
2021-04-28 12:38:13 +00:00
|
|
|
std::unordered_map<const sem::StructType*, StructInfo*> struct_info_;
|
|
|
|
std::unordered_map<const sem::Type*, const sem::Type*> type_to_canonical_;
|
|
|
|
std::unordered_set<const ast::Node*> marked_;
|
2021-02-03 16:43:20 +00:00
|
|
|
FunctionInfo* current_function_ = nullptr;
|
2021-04-16 19:07:51 +00:00
|
|
|
sem::Statement* current_statement_ = nullptr;
|
2021-02-03 17:51:09 +00:00
|
|
|
BlockAllocator<VariableInfo> variable_infos_;
|
2021-02-03 16:43:20 +00:00
|
|
|
BlockAllocator<FunctionInfo> function_infos_;
|
2021-03-17 22:01:53 +00:00
|
|
|
BlockAllocator<StructInfo> struct_infos_;
|
2020-03-02 20:47:43 +00:00
|
|
|
};
|
|
|
|
|
2021-03-09 15:08:48 +00:00
|
|
|
} // namespace resolver
|
2020-03-02 20:47:43 +00:00
|
|
|
} // namespace tint
|
|
|
|
|
2021-03-09 10:54:37 +00:00
|
|
|
#endif // SRC_RESOLVER_RESOLVER_H_
|