mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-07-23 21:46:00 +00:00
All includes from .cc to .h are preserved, even when transitively included. It's clear that there are far too many includes in header files, and we should be more aggressive with forward declarations. tint:532 will continue to track this work. There are, however, plenty of includes that have accumulated over time which are no longer required directly or transitively, so this change starts with a clean slate of *required* includes. Bug: tint:532 Change-Id: Ie1718dad565f8309fa180ef91bcf3920e76dba18 Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/44042 Commit-Queue: Ben Clayton <bclayton@google.com> Reviewed-by: Antonio Maiorano <amaiorano@google.com>
172 lines
5.1 KiB
C++
172 lines
5.1 KiB
C++
// 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_PROGRAM_H_
|
|
#define SRC_PROGRAM_H_
|
|
|
|
#include <string>
|
|
|
|
#include "src/ast/function.h"
|
|
#include "src/semantic/info.h"
|
|
#include "src/symbol_table.h"
|
|
#include "src/type/type_manager.h"
|
|
|
|
namespace tint {
|
|
|
|
// Forward declarations
|
|
class CloneContext;
|
|
|
|
namespace ast {
|
|
|
|
class Module;
|
|
|
|
} // namespace ast
|
|
|
|
/// Program holds the AST, Type information and SymbolTable for a tint program.
|
|
class Program {
|
|
public:
|
|
/// ASTNodeAllocator is an alias to BlockAllocator<ast::Node>
|
|
using ASTNodeAllocator = BlockAllocator<ast::Node>;
|
|
|
|
/// SemNodeAllocator is an alias to BlockAllocator<semantic::Node>
|
|
using SemNodeAllocator = BlockAllocator<semantic::Node>;
|
|
|
|
/// Constructor
|
|
Program();
|
|
|
|
/// Move constructor
|
|
/// @param rhs the Program to move
|
|
Program(Program&& rhs);
|
|
|
|
/// Move constructor from builder
|
|
/// @param builder the builder used to construct the program
|
|
explicit Program(ProgramBuilder&& builder);
|
|
|
|
/// Destructor
|
|
~Program();
|
|
|
|
/// Move assignment operator
|
|
/// @param rhs the Program to move
|
|
/// @return this Program
|
|
Program& operator=(Program&& rhs);
|
|
|
|
/// @returns a reference to the program's types
|
|
const type::Manager& Types() const {
|
|
AssertNotMoved();
|
|
return types_;
|
|
}
|
|
|
|
/// @returns a reference to the program's AST nodes storage
|
|
const ASTNodeAllocator& ASTNodes() const {
|
|
AssertNotMoved();
|
|
return ast_nodes_;
|
|
}
|
|
|
|
/// @returns a reference to the program's semantic nodes storage
|
|
const SemNodeAllocator& SemNodes() const {
|
|
AssertNotMoved();
|
|
return sem_nodes_;
|
|
}
|
|
|
|
/// @returns a reference to the program's AST root Module
|
|
const ast::Module& AST() const {
|
|
AssertNotMoved();
|
|
return *ast_;
|
|
}
|
|
|
|
/// @returns a reference to the program's semantic info
|
|
const semantic::Info& Sem() const {
|
|
AssertNotMoved();
|
|
return sem_;
|
|
}
|
|
|
|
/// @returns a reference to the program's SymbolTable
|
|
const SymbolTable& Symbols() const {
|
|
AssertNotMoved();
|
|
return symbols_;
|
|
}
|
|
|
|
/// @returns a reference to the program's diagnostics
|
|
const diag::List& Diagnostics() const {
|
|
AssertNotMoved();
|
|
return diagnostics_;
|
|
}
|
|
|
|
/// Performs a deep clone of this program.
|
|
/// The returned Program will contain no pointers to objects owned by this
|
|
/// Program, and so after calling, this Program can be safely destructed.
|
|
/// @return a new Program copied from this Program
|
|
Program Clone() const;
|
|
|
|
/// Performs a deep clone of this Program's AST nodes, types and symbols into
|
|
/// a new ProgramBuilder. Semantic nodes are not cloned, as these will be
|
|
/// rebuilt when the ProgramBuilder builds its Program.
|
|
/// The returned ProgramBuilder will contain no pointers to objects owned by
|
|
/// this Program, and so after calling, this Program can be safely destructed.
|
|
/// @return a new ProgramBuilder copied from this Program
|
|
ProgramBuilder CloneAsBuilder() const;
|
|
|
|
/// @returns true if the program has no error diagnostics and is not missing
|
|
/// information
|
|
bool IsValid() const;
|
|
|
|
/// Helper for returning the resolved semantic type of the expression `expr`.
|
|
/// @param expr the AST expression
|
|
/// @return the resolved semantic type for the expression, or nullptr if the
|
|
/// expression has no resolved type.
|
|
type::Type* TypeOf(const ast::Expression* expr) const;
|
|
|
|
/// @param demangle whether to automatically demangle the symbols in the
|
|
/// returned string
|
|
/// @returns a string describing this program.
|
|
std::string to_str(bool demangle) const;
|
|
|
|
/// @returns a demangled string describing this program.
|
|
std::string to_str() const { return to_str(true); }
|
|
|
|
/// Writes a representation of the node to the output stream
|
|
/// @note unlike str(), to_str() does not automatically demangle the string.
|
|
/// @param node the AST node
|
|
/// @param out the stream to write to
|
|
/// @param indent number of spaces to indent the node when writing
|
|
void to_str(const ast::Node* node, std::ostream& out, size_t indent) const {
|
|
node->to_str(Sem(), out, indent);
|
|
}
|
|
|
|
/// Returns a demangled, string representation of `node`.
|
|
/// @param node the AST node
|
|
/// @returns a string representation of the node
|
|
std::string str(const ast::Node* node) const;
|
|
|
|
private:
|
|
Program(const Program&) = delete;
|
|
|
|
/// Asserts that the program has not been moved.
|
|
void AssertNotMoved() const;
|
|
|
|
type::Manager types_;
|
|
ASTNodeAllocator ast_nodes_;
|
|
SemNodeAllocator sem_nodes_;
|
|
ast::Module* ast_ = nullptr;
|
|
semantic::Info sem_;
|
|
SymbolTable symbols_;
|
|
diag::List diagnostics_;
|
|
bool is_valid_ = false; // Not valid until it is built
|
|
bool moved_ = false;
|
|
};
|
|
|
|
} // namespace tint
|
|
|
|
#endif // SRC_PROGRAM_H_
|