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.
|
|
|
|
|
|
|
|
#ifndef SRC_TYPE_MANAGER_H_
|
|
|
|
#define SRC_TYPE_MANAGER_H_
|
|
|
|
|
|
|
|
#include <memory>
|
|
|
|
#include <string>
|
|
|
|
#include <unordered_map>
|
|
|
|
|
|
|
|
#include "src/ast/type/type.h"
|
|
|
|
|
|
|
|
namespace tint {
|
|
|
|
|
|
|
|
/// The type manager holds all the pointers to the known types.
|
|
|
|
class TypeManager {
|
|
|
|
public:
|
2020-03-25 19:16:36 +00:00
|
|
|
TypeManager();
|
|
|
|
~TypeManager();
|
2020-03-02 20:47:43 +00:00
|
|
|
|
2020-03-27 00:47:16 +00:00
|
|
|
/// Clears all registered types.
|
|
|
|
void Reset();
|
|
|
|
|
2020-03-02 20:47:43 +00:00
|
|
|
/// Get the given type from the type manager
|
|
|
|
/// @param type The type to register
|
|
|
|
/// @return the pointer to the registered type
|
|
|
|
ast::type::Type* Get(std::unique_ptr<ast::type::Type> type);
|
|
|
|
|
2020-03-27 00:47:16 +00:00
|
|
|
/// Returns the type map, for testing purposes.
|
|
|
|
/// @returns the mapping from name string to type.
|
|
|
|
const std::unordered_map<std::string, std::unique_ptr<ast::type::Type>>&
|
|
|
|
TypesForTesting() {
|
|
|
|
return types_;
|
|
|
|
}
|
|
|
|
|
2020-03-02 20:47:43 +00:00
|
|
|
private:
|
|
|
|
std::unordered_map<std::string, std::unique_ptr<ast::type::Type>> types_;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace tint
|
|
|
|
|
|
|
|
#endif // SRC_TYPE_MANAGER_H_
|