Skip to content

Commit

Permalink
Add built-in "__FILE_NAME_HASH__" and "__FILE_STEM_HASH__" preprocess…
Browse files Browse the repository at this point in the history
…or macros
  • Loading branch information
crosire committed Sep 22, 2023
1 parent 5c8b8f0 commit 5018887
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
2 changes: 1 addition & 1 deletion source/effect_parser_stmt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
#include "effect_parser.hpp"
#include "effect_codegen.hpp"
#include <cctype> // std::toupper
#include <limits>
#include <cassert>
#include <functional>
#include <string_view>
#include <limits>

struct on_scope_exit
{
Expand Down
12 changes: 12 additions & 0 deletions source/effect_preprocessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1047,12 +1047,24 @@ bool reshadefx::preprocessor::evaluate_identifier_as_macro()
push(escape_string(file_stem.u8string()));
return true;
}
if (_token.literal_as_string == "__FILE_STEM_HASH__")
{
const std::filesystem::path file_stem = std::filesystem::u8path(_token.location.source).stem();
push(std::to_string(std::hash<std::string>()(file_stem.u8string()) & 0xFFFFFFFF));
return true;
}
if (_token.literal_as_string == "__FILE_NAME__")
{
const std::filesystem::path file_name = std::filesystem::u8path(_token.location.source).filename();
push(escape_string(file_name.u8string()));
return true;
}
if (_token.literal_as_string == "__FILE_NAME_HASH__")
{
const std::filesystem::path file_name = std::filesystem::u8path(_token.location.source).filename();
push(std::to_string(std::hash<std::string>()(file_name.u8string()) & 0xFFFFFFFF));
return true;
}

const auto it = _macros.find(_token.literal_as_string);
if (it == _macros.end())
Expand Down
2 changes: 1 addition & 1 deletion source/effect_token.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@

#pragma once

#include <cstdint>
#include <string>
#include <vector>
#include <cstdint>

namespace reshadefx
{
Expand Down

0 comments on commit 5018887

Please sign in to comment.