2011-02-16 01:40:07 +00:00
|
|
|
//===--- port.h - OS/cpu specific stuff for include-what-you-use ----------===//
|
2011-02-08 06:12:32 +00:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Source file for architecture-specific logic.
|
|
|
|
|
|
|
|
#ifndef DEVTOOLS_MAINTENANCE_INCLUDE_WHAT_YOU_USE_PORT_H_
|
|
|
|
#define DEVTOOLS_MAINTENANCE_INCLUDE_WHAT_YOU_USE_PORT_H_
|
|
|
|
|
2011-09-20 23:12:17 +01:00
|
|
|
#include <stdlib.h> // for abort
|
|
|
|
#include <iostream>
|
|
|
|
|
|
|
|
namespace include_what_you_use {
|
|
|
|
|
|
|
|
// Helper class that allows programmers to log extra information in CHECK_s.
|
|
|
|
class FatalMessageEmitter {
|
|
|
|
public:
|
|
|
|
FatalMessageEmitter(const char* file, int line, const char* message) {
|
|
|
|
stream() << file << ":" << line << ": Assertion failed: " << message;
|
|
|
|
}
|
|
|
|
~FatalMessageEmitter() {
|
|
|
|
stream() << ::std::endl;
|
|
|
|
::abort();
|
|
|
|
}
|
|
|
|
::std::ostream& stream() { return ::std::cerr; }
|
|
|
|
};
|
|
|
|
|
|
|
|
// Helper class that allows an ostream to 'appear' as a void expression.
|
|
|
|
class OstreamVoidifier {
|
|
|
|
public:
|
|
|
|
// This has to be an operator with a precedence lower than << but
|
|
|
|
// higher than ?:
|
|
|
|
void operator&(::std::ostream&) {}
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace include_what_you_use
|
|
|
|
|
|
|
|
// Usage: CHECK_(condition) << extra << information;
|
|
|
|
// The file, line, condition and extra information will be printed to cerr,
|
|
|
|
// then the program will abort.
|
|
|
|
#define CHECK_(x) (x) ? (void)0 : \
|
|
|
|
::include_what_you_use::OstreamVoidifier() & \
|
|
|
|
::include_what_you_use::FatalMessageEmitter( \
|
|
|
|
__FILE__, __LINE__, #x).stream()
|
2011-03-04 00:29:56 +00:00
|
|
|
|
2011-02-08 06:12:32 +00:00
|
|
|
#if defined(_MSC_VER)
|
|
|
|
|
|
|
|
# define NOMINMAX
|
|
|
|
# include <windows.h>
|
|
|
|
|
|
|
|
# define getcwd _getcwd
|
|
|
|
# define snprintf _snprintf
|
|
|
|
|
2011-05-25 00:12:28 +01:00
|
|
|
# include "Shlwapi.h" // for PathMatchSpec
|
2011-05-04 19:30:53 +01:00
|
|
|
|
2011-02-08 06:12:32 +00:00
|
|
|
# pragma comment(lib, "Shlwapi.lib")
|
2011-05-13 00:10:38 +01:00
|
|
|
|
2011-05-25 00:12:28 +01:00
|
|
|
inline bool GlobMatchesPath(const char *glob, const char *path) {
|
|
|
|
return PathMatchSpec(path, glob);
|
2011-05-13 00:10:38 +01:00
|
|
|
}
|
2011-02-08 06:12:32 +00:00
|
|
|
|
2011-02-08 19:43:58 +00:00
|
|
|
// FIXME: This undef is necessary to prevent conflicts between llvm
|
|
|
|
// and Windows headers. Eventually fnmatch functionality
|
|
|
|
// should be wrapped inside llvm's PathV2 library.
|
|
|
|
# undef interface // used in Shlwapi.h
|
|
|
|
|
2011-05-13 00:10:38 +01:00
|
|
|
#else // #if defined(_MSC_VER)
|
|
|
|
|
2011-05-25 00:12:28 +01:00
|
|
|
#include <fnmatch.h>
|
|
|
|
|
|
|
|
inline bool GlobMatchesPath(const char *glob, const char *path) {
|
|
|
|
return fnmatch(glob, path, FNM_PATHNAME) == 0;
|
|
|
|
}
|
2011-05-13 00:10:38 +01:00
|
|
|
|
2011-02-08 06:12:32 +00:00
|
|
|
#endif // #if defined(_MSC_VER)
|
|
|
|
|
|
|
|
#endif // DEVTOOLS_MAINTENANCE_INCLUDE_WHAT_YOU_USE_PORT_H_
|