// Copyright 2015 The Shaderc Authors. All rights reserved.1//2// Licensed under the Apache License, Version 2.0 (the "License");3// you may not use this file except in compliance with the License.4// You may obtain a copy of the License at5//6// http://www.apache.org/licenses/LICENSE-2.07//8// Unless required by applicable law or agreed to in writing, software9// distributed under the License is distributed on an "AS IS" BASIS,10// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.11// See the License for the specific language governing permissions and12// limitations under the License.1314#ifndef GLSLC_FILE_INCLUDER_H_15#define GLSLC_FILE_INCLUDER_H_1617#include <mutex>18#include <string>19#include <unordered_map>20#include <unordered_set>21#include <utility>22#include <vector>23#include <unordered_set>2425#include "libshaderc_util/file_finder.h"26#include "shaderc/shaderc.hpp"2728namespace glslc {2930// An includer for files implementing shaderc's includer interface. It responds31// to the file including query from the compiler with the full path and content32// of the file to be included. In the case that the file is not found or cannot33// be opened, the full path field of in the response will point to an empty34// string, and error message will be passed to the content field.35// This class provides the basic thread-safety guarantee.36class FileIncluder : public shaderc::CompileOptions::IncluderInterface {37public:38explicit FileIncluder(const shaderc_util::FileFinder* file_finder)39: file_finder_(*file_finder) {}4041~FileIncluder() override;4243// Resolves a requested source file of a given type from a requesting44// source into a shaderc_include_result whose contents will remain valid45// until it's released.46shaderc_include_result* GetInclude(const char* requested_source,47shaderc_include_type type,48const char* requesting_source,49size_t include_depth) override;50// Releases an include result.51void ReleaseInclude(shaderc_include_result* include_result) override;5253// Returns a reference to the member storing the set of included files.54const std::unordered_set<std::string>& file_path_trace() const {55return included_files_;56}5758private:59// Used by GetInclude() to get the full filepath.60const shaderc_util::FileFinder& file_finder_;61// The full path and content of a source file.62struct FileInfo {63const std::string full_path;64std::vector<char> contents;65};6667// The set of full paths of included files.68std::unordered_set<std::string> included_files_;69};7071} // namespace glslc7273#endif // GLSLC_FILE_INCLUDER_H_747576