2021-01-25 18:14:08 +00:00
|
|
|
// 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>
|
|
|
|
|
2021-01-26 16:57:10 +00:00
|
|
|
#include "src/ast/function.h"
|
2021-01-27 18:49:05 +00:00
|
|
|
#include "src/diagnostic/diagnostic.h"
|
2021-01-29 10:55:40 +00:00
|
|
|
#include "src/semantic/info.h"
|
2021-01-26 16:57:10 +00:00
|
|
|
#include "src/symbol_table.h"
|
|
|
|
#include "src/type/type_manager.h"
|
2021-01-25 18:14:08 +00:00
|
|
|
|
|
|
|
namespace tint {
|
|
|
|
|
2021-01-26 16:57:10 +00:00
|
|
|
// Forward declarations
|
|
|
|
class CloneContext;
|
|
|
|
|
|
|
|
namespace ast {
|
|
|
|
|
|
|
|
class Module;
|
|
|
|
|
|
|
|
} // namespace ast
|
|
|
|
|
|
|
|
/// Program holds the AST, Type information and SymbolTable for a tint program.
|
2021-01-25 18:14:08 +00:00
|
|
|
class Program {
|
|
|
|
public:
|
2021-01-26 16:57:10 +00:00
|
|
|
/// ASTNodes is an alias to BlockAllocator<ast::Node>
|
|
|
|
using ASTNodes = BlockAllocator<ast::Node>;
|
|
|
|
|
2021-01-26 16:57:10 +00:00
|
|
|
/// Constructor
|
|
|
|
Program();
|
2021-01-25 18:14:08 +00:00
|
|
|
|
2021-01-26 16:57:10 +00:00
|
|
|
/// Move constructor
|
2021-01-26 16:57:10 +00:00
|
|
|
/// @param rhs the Program to move
|
|
|
|
Program(Program&& rhs);
|
2021-01-26 16:57:10 +00:00
|
|
|
|
2021-01-26 16:57:10 +00:00
|
|
|
/// Move constructor from builder
|
|
|
|
/// @param builder the builder used to construct the program
|
|
|
|
explicit Program(ProgramBuilder&& builder);
|
|
|
|
|
|
|
|
/// Destructor
|
|
|
|
~Program();
|
|
|
|
|
2021-01-26 16:57:10 +00:00
|
|
|
/// Move assignment operator
|
|
|
|
/// @param rhs the Program to move
|
|
|
|
/// @return this Program
|
|
|
|
Program& operator=(Program&& rhs);
|
|
|
|
|
2021-01-26 16:57:10 +00:00
|
|
|
/// @returns a reference to the program's types
|
2021-01-26 16:57:10 +00:00
|
|
|
const type::Manager& Types() const {
|
|
|
|
AssertNotMoved();
|
|
|
|
return types_;
|
|
|
|
}
|
2021-01-26 16:57:10 +00:00
|
|
|
|
|
|
|
/// @returns a reference to the program's AST nodes storage
|
2021-01-26 16:57:10 +00:00
|
|
|
const ASTNodes& Nodes() const {
|
|
|
|
AssertNotMoved();
|
|
|
|
return nodes_;
|
|
|
|
}
|
2021-01-26 16:57:10 +00:00
|
|
|
|
|
|
|
/// @returns a reference to the program's AST root Module
|
2021-01-26 16:57:10 +00:00
|
|
|
const ast::Module& AST() const {
|
|
|
|
AssertNotMoved();
|
|
|
|
return *ast_;
|
|
|
|
}
|
2021-01-26 16:57:10 +00:00
|
|
|
|
2021-01-29 10:55:40 +00:00
|
|
|
/// @returns a reference to the program's semantic info
|
|
|
|
const semantic::Info& Sem() const {
|
|
|
|
AssertNotMoved();
|
|
|
|
return sem_;
|
|
|
|
}
|
|
|
|
|
2021-01-26 16:57:10 +00:00
|
|
|
/// @returns a reference to the program's SymbolTable
|
2021-01-26 16:57:10 +00:00
|
|
|
const SymbolTable& Symbols() const {
|
|
|
|
AssertNotMoved();
|
|
|
|
return symbols_;
|
|
|
|
}
|
2021-01-26 16:57:10 +00:00
|
|
|
|
2021-01-27 18:49:05 +00:00
|
|
|
/// @returns a reference to the program's diagnostics
|
|
|
|
const diag::List& Diagnostics() const {
|
|
|
|
AssertNotMoved();
|
|
|
|
return diagnostics_;
|
|
|
|
}
|
|
|
|
|
2021-01-25 18:14:08 +00:00
|
|
|
/// @return a deep copy of this program
|
2021-01-26 16:57:10 +00:00
|
|
|
Program Clone() const;
|
|
|
|
|
2021-01-26 16:57:10 +00:00
|
|
|
/// @return a deep copy of this Program, as a ProgramBuilder
|
|
|
|
ProgramBuilder CloneAsBuilder() const;
|
2021-01-26 16:57:10 +00:00
|
|
|
|
2021-01-27 18:49:05 +00:00
|
|
|
/// @returns true if the program has no error diagnostics and is not missing
|
|
|
|
/// information
|
2021-01-26 16:57:10 +00:00
|
|
|
bool IsValid() const;
|
|
|
|
|
2021-01-26 16:57:10 +00:00
|
|
|
/// @returns a string describing this program.
|
2021-01-26 16:57:10 +00:00
|
|
|
std::string to_str() const;
|
|
|
|
|
|
|
|
private:
|
|
|
|
Program(const Program&) = delete;
|
|
|
|
|
2021-01-26 16:57:10 +00:00
|
|
|
/// Asserts that the program has not been moved.
|
|
|
|
void AssertNotMoved() const;
|
|
|
|
|
2021-01-26 16:57:10 +00:00
|
|
|
type::Manager types_;
|
|
|
|
ASTNodes nodes_;
|
|
|
|
ast::Module* ast_;
|
2021-01-29 10:55:40 +00:00
|
|
|
semantic::Info sem_;
|
2021-01-26 16:57:10 +00:00
|
|
|
SymbolTable symbols_;
|
2021-01-27 18:49:05 +00:00
|
|
|
diag::List diagnostics_;
|
|
|
|
bool is_valid_ = true;
|
2021-01-26 16:57:10 +00:00
|
|
|
bool moved_ = false;
|
2021-01-25 18:14:08 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace tint
|
|
|
|
|
|
|
|
#endif // SRC_PROGRAM_H_
|