Skip to content

Commit

Permalink
Fix Windows shared lib build
Browse files Browse the repository at this point in the history
  • Loading branch information
MikePopoloski committed May 3, 2023
1 parent 3378842 commit 5414450
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 9 deletions.
8 changes: 5 additions & 3 deletions include/slang/diagnostics/DiagnosticEngine.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
#include <filesystem>
#include <memory>
#include <string>
#include <typeindex>
#include <typeinfo>

#include "slang/diagnostics/Diagnostics.h"
#include "slang/util/Hash.h"
Expand Down Expand Up @@ -156,14 +158,14 @@ class SLANG_EXPORT DiagnosticEngine {
/// provide formatting for diagnostic arguments of a custom type.
template<typename ForType>
void setFormatter(std::shared_ptr<DiagArgFormatter> formatter) {
formatters[type_index::of<ForType>()] = std::move(formatter);
formatters[SLANG_TYPEOF(ForType)] = std::move(formatter);
}

/// Sets a custom formatter for the given type that should apply by default to
/// all new DiagnosticEngine instances that get created.
template<typename ForType>
static void setDefaultFormatter(std::shared_ptr<DiagArgFormatter> formatter) {
defaultFormatters[type_index::of<ForType>()] = std::move(formatter);
defaultFormatters[SLANG_TYPEOF(ForType)] = std::move(formatter);
}

/// Formats the given diagnostic using its arguments and the currently mapped
Expand Down Expand Up @@ -266,7 +268,7 @@ class SLANG_EXPORT DiagnosticEngine {

// A map from type_index to a formatter for that type. Used to register custom
// formatters for subsystem-specific types.
using FormatterMap = flat_hash_map<type_index, std::shared_ptr<DiagArgFormatter>>;
using FormatterMap = flat_hash_map<SLANG_TYPEINDEX, std::shared_ptr<DiagArgFormatter>>;
mutable FormatterMap formatters;

// A set of default formatters that will be assigned to each new DiagnosticEngine instance
Expand Down
2 changes: 1 addition & 1 deletion include/slang/diagnostics/Diagnostics.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ SLANG_EXPORT std::string_view toString(DiagCode code);
/// Wraps up a reported diagnostic along with location in source and any arguments.
class SLANG_EXPORT Diagnostic {
public:
using CustomArgType = std::pair<type_index, std::any>;
using CustomArgType = std::pair<SLANG_TYPEINDEX, std::any>;

// Diagnostic-specific arguments that can be used to better report messages.
using Arg = std::variant<std::string, int64_t, uint64_t, char, ConstantValue, CustomArgType>;
Expand Down
10 changes: 6 additions & 4 deletions include/slang/util/Bag.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
#pragma once

#include <any>
#include <typeindex>
#include <typeinfo>

#include "slang/util/Hash.h"
#include "slang/util/TypeTraits.h"
Expand All @@ -33,21 +35,21 @@ class SLANG_EXPORT Bag {
/// (making a copy in the process).
template<typename T>
void set(const T& item) {
items[type_index::of<T>()] = item;
items[SLANG_TYPEOF(T)] = item;
}

/// Adds or overwrites an existing element of type T in the bag
/// (moving in the new item in the process).
template<typename T>
void set(T&& item) {
items[type_index::of<T>()] = std::forward<T>(item);
items[SLANG_TYPEOF(T)] = std::forward<T>(item);
}

/// Gets an element of type T from the bag, if it exists.
/// Otherwise returns nullptr.
template<typename T>
const T* get() const {
auto it = items.find(type_index::of<T>());
auto it = items.find(SLANG_TYPEOF(T));
if (it == items.end())
return nullptr;
return std::any_cast<T>(&it->second);
Expand All @@ -64,7 +66,7 @@ class SLANG_EXPORT Bag {
}

private:
flat_hash_map<type_index, std::any> items;
flat_hash_map<SLANG_TYPEINDEX, std::any> items;
};

} // namespace slang
8 changes: 8 additions & 0 deletions include/slang/util/Util.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,14 @@
# define SLANG_RTTI_ENABLED
#endif

#if defined(SLANG_RTTI_ENABLED)
# define SLANG_TYPEOF(x) std::type_index(typeid(x))
# define SLANG_TYPEINDEX std::type_index
#else
# define SLANG_TYPEOF(x) type_index::of<x>()
# define SLANG_TYPEINDEX type_index
#endif

#if !defined(SLANG_ASSERT_ENABLED)
# if !defined(NDEBUG)
# define SLANG_ASSERT_ENABLED 1
Expand Down
2 changes: 1 addition & 1 deletion source/ast/types/Type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1247,7 +1247,7 @@ const Type& Type::getPredefinedType(Compilation& compilation, SyntaxKind kind, b

Diagnostic& operator<<(Diagnostic& diag, const Type& arg) {
SLANG_ASSERT(!arg.isError());
diag.args.emplace_back(Diagnostic::CustomArgType{type_index::of<const Type*>(), &arg});
diag.args.emplace_back(Diagnostic::CustomArgType{SLANG_TYPEOF(const Type*), &arg});
return diag;
}

Expand Down

0 comments on commit 5414450

Please sign in to comment.