Skip to content

Commit

Permalink
Fix run-clang-format.sh to also run over headers.
Browse files Browse the repository at this point in the history
Since the headers moved to its include/... directory a while
back, the run-clang-format.sh was not seeing them anymore, as it
only was looking in src. Fix that, and run clang-format.
  • Loading branch information
hzeller committed Nov 9, 2024
1 parent 58e81cb commit 98983f6
Show file tree
Hide file tree
Showing 69 changed files with 330 additions and 263 deletions.
2 changes: 1 addition & 1 deletion .github/bin/run-clang-format.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
FORMAT_OUT=${TMPDIR:-/tmp}/clang-format-diff.out

# Run on all c++ files.
find src -name "*.h" -o -name "*.cpp" | xargs clang-format --style=Google -i
find include src -name "*.h" -o -name "*.cpp" | xargs clang-format --style=Google -i

# Check if we got any diff, then print it out in in the CI.
# TODO: make these suggested diffs in the pull request.
Expand Down
17 changes: 9 additions & 8 deletions include/Surelog/API/SLAPI.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,16 +78,17 @@ void SLaddMLErrorContext(SV3_1aPythonListener* prog,
void SLaddMLError(ErrorContainer* container, const char* messageId,
const char* fileName1, uint32_t line1, uint32_t col1,
const char* objectName1, const char* fileName2,
uint32_t line2, uint32_t col2,
const char* objectName2);
uint32_t line2, uint32_t col2, const char* objectName2);

/* File Listener API */
std::string SLgetFile(SV3_1aPythonListener* prog,
antlr4::ParserRuleContext* context);

int32_t SLgetLine(SV3_1aPythonListener* prog, antlr4::ParserRuleContext* context);
int32_t SLgetLine(SV3_1aPythonListener* prog,
antlr4::ParserRuleContext* context);

int32_t SLgetColumn(SV3_1aPythonListener* prog, antlr4::ParserRuleContext* context);
int32_t SLgetColumn(SV3_1aPythonListener* prog,
antlr4::ParserRuleContext* context);

std::string SLgetText(SV3_1aPythonListener* prog,
antlr4::ParserRuleContext* context);
Expand Down Expand Up @@ -119,10 +120,10 @@ std::string SLgetName(FileContent* fC, RawNodeId index);
uint32_t SLgetType(FileContent* fC, RawNodeId index);

RawNodeId SLgetChild(FileContent* fC, RawNodeId parent,
uint32_t type); // Get first child item of type
uint32_t type); // Get first child item of type

RawNodeId SLgetParent(FileContent* fC, RawNodeId parent,
uint32_t type); // Get first parent item of type
uint32_t type); // Get first parent item of type

UIntVector SLgetAll(FileContent* fC, RawNodeId parent,
uint32_t type); // get all child items of type
Expand All @@ -143,8 +144,8 @@ UIntVector SLcollectAll(
bool first); // Recursively search for all items of types

UIntVector SLcollectAll(FileContent* fC, RawNodeId parent,
const UIntVector& types,
const UIntVector& stopPoints, bool first);
const UIntVector& types, const UIntVector& stopPoints,
bool first);
// Recursively search for all items of types
// and stops at types stopPoints
/* Design API */
Expand Down
2 changes: 1 addition & 1 deletion include/Surelog/Cache/PPCache.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class PPCache : Cache {
const SymbolTable& sourceSymbols);

void cacheTimeInfos(::PPCache::Builder builder, SymbolTable& targetSymbols,
const SymbolTable& sourceSymbols);
const SymbolTable& sourceSymbols);

void cacheLineTranslationInfos(::PPCache::Builder builder,
SymbolTable& targetSymbols,
Expand Down
8 changes: 4 additions & 4 deletions include/Surelog/Cache/ParseCache.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,11 @@ class ParseCache final : Cache {
// to IDs used on the cache on disk.
// Updates "targetSymbols" if new IDs are needed.
void cacheVObjects(::ParseCache::Builder builder, const FileContent* fC,
SymbolTable& targetSymbols, const SymbolTable& sourceSymbols,
PathId fileId);
SymbolTable& targetSymbols,
const SymbolTable& sourceSymbols, PathId fileId);

void cacheDesignElements(::ParseCache::Builder builder,
const FileContent* fC, SymbolTable& targetSymbols,
void cacheDesignElements(::ParseCache::Builder builder, const FileContent* fC,
SymbolTable& targetSymbols,
const SymbolTable& sourceSymbols);

bool restore(PathId cacheFileId);
Expand Down
6 changes: 3 additions & 3 deletions include/Surelog/CommandLine/CommandLineParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,16 @@
#define SURELOG_COMMANDLINEPARSER_H
#pragma once

#include <functional>
#include <utility>
#include <string_view>
#include <Surelog/Common/PathId.h>
#include <Surelog/Common/SymbolId.h>

#include <filesystem>
#include <functional>
#include <map>
#include <set>
#include <string>
#include <string_view>
#include <utility>
#include <vector>

namespace SURELOG {
Expand Down
45 changes: 26 additions & 19 deletions include/Surelog/Common/FileSystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,20 @@
#define SURELOG_FILESYSTEM_H
#pragma once

#include <functional>
#include <set>
#include <utility>
#include <vector>
#include <Surelog/Common/PathId.h>

#include <cstdint>
#include <filesystem>
#include <functional>
#include <istream>
#include <map>
#include <regex>
#include <set>
#include <sstream>
#include <string>
#include <string_view>
#include <utility>
#include <vector>

namespace SURELOG {
class SymbolTable;
Expand Down Expand Up @@ -77,7 +77,8 @@ class SymbolTable;
*
* NOTE:
* toPath(id) == toPath(toPathId(toPath(id))) but
* toPlatformAbsPath(id) <> toPlatformAbsPath(toPathId(toPlatformAbsPath(id)))
* toPlatformAbsPath(id) <>
* toPlatformAbsPath(toPathId(toPlatformAbsPath(id)))
*
* i.e. string representation can be converted to id (and vice-versa)
* using toPathId & toPath but the same is not necessarily guaranteed
Expand Down Expand Up @@ -132,7 +133,7 @@ class FileSystem {
// and can be used for, say, system commands.
virtual std::filesystem::path toPlatformAbsPath(PathId id) = 0;
virtual std::filesystem::path toPlatformRelPath(PathId id) = 0;
// Returns base and relative paths
// Returns base and relative paths
virtual std::pair<std::filesystem::path, std::filesystem::path>
toSplitPlatformPath(PathId id) = 0;

Expand All @@ -147,15 +148,17 @@ class FileSystem {
// Open/Close an input stream represented by the input PathId.
// openForRead defaults the ios_base::openmode to ios_base::text
// openForLoad defaults the ios_base::openmode to ios_base::binary
virtual std::istream &openInput(PathId fileId, std::ios_base::openmode mode) = 0;
virtual std::istream &openInput(PathId fileId,
std::ios_base::openmode mode) = 0;
std::istream &openForRead(PathId fileId);
std::istream &openForLoad(PathId fileId);
virtual bool close(std::istream &strm) = 0;

// Open/Close an output stream represented by the input PathId.
// openForWrite defaults the ios_base::openmode to ios_base::text
// openForSave defaults the ios_base::openmode to ios_base::binary
virtual std::ostream &openOutput(PathId fileId, std::ios_base::openmode mode) = 0;
virtual std::ostream &openOutput(PathId fileId,
std::ios_base::openmode mode) = 0;
std::ostream &openForWrite(PathId fileId);
std::ostream &openForSave(PathId fileId);
virtual bool close(std::ostream &strm) = 0;
Expand Down Expand Up @@ -203,9 +206,12 @@ class FileSystem {
virtual PathId getProgramFile(std::string_view hint,
SymbolTable *symbolTable) = 0;

virtual PathId getWorkingDir(std::string_view dir, SymbolTable *symbolTable) = 0;
virtual PathId getOutputDir(std::string_view dir, SymbolTable *symbolTable) = 0;
virtual PathId getPrecompiledDir(PathId programId, SymbolTable *symbolTable) = 0;
virtual PathId getWorkingDir(std::string_view dir,
SymbolTable *symbolTable) = 0;
virtual PathId getOutputDir(std::string_view dir,
SymbolTable *symbolTable) = 0;
virtual PathId getPrecompiledDir(PathId programId,
SymbolTable *symbolTable) = 0;

virtual PathId getLogFile(bool isUnitCompilation, std::string_view filename,
SymbolTable *symbolTable) = 0;
Expand All @@ -222,23 +228,23 @@ class FileSystem {
std::string_view libraryName,
SymbolTable *symbolTable) = 0;
PathId getPpOutputFile(bool isUnitCompilation, PathId sourceFileId,
SymbolId libraryNameId,
SymbolTable *symbolTable);
SymbolId libraryNameId, SymbolTable *symbolTable);

virtual PathId getPpCacheFile(bool isUnitCompilation, PathId sourceFileId,
std::string_view libraryName,
bool isPrecompiled, SymbolTable *symbolTable) = 0;
bool isPrecompiled,
SymbolTable *symbolTable) = 0;
PathId getPpCacheFile(bool isUnitCompilation, PathId sourceFileId,
SymbolId libraryNameId, bool isPrecompiled,
SymbolTable *symbolTable);
SymbolId libraryNameId, bool isPrecompiled,
SymbolTable *symbolTable);

virtual PathId getParseCacheFile(bool isUnitCompilation, PathId ppFileId,
std::string_view libraryName,
bool isPrecompiled,
SymbolTable *symbolTable) = 0;
PathId getParseCacheFile(bool isUnitCompilation, PathId ppFileId,
SymbolId libraryNameId, bool isPrecompiled,
SymbolTable *symbolTable);
SymbolId libraryNameId, bool isPrecompiled,
SymbolTable *symbolTable);

virtual PathId getPythonCacheFile(bool isUnitCompilation, PathId sourceFileId,
std::string_view libraryName,
Expand All @@ -257,7 +263,8 @@ class FileSystem {

virtual PathId getCheckerDir(bool isUnitCompilation,
SymbolTable *symbolTable) = 0;
virtual PathId getCheckerFile(PathId uhdmFileId, SymbolTable *symbolTable) = 0;
virtual PathId getCheckerFile(PathId uhdmFileId,
SymbolTable *symbolTable) = 0;
virtual PathId getCheckerHtmlFile(PathId uhdmFileId,
SymbolTable *symbolTable) = 0;
virtual PathId getCheckerHtmlFile(PathId uhdmFileId, int32_t index,
Expand Down
51 changes: 39 additions & 12 deletions include/Surelog/Common/NodeId.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
#include <cstdint>
#include <ostream>
#include <set>
#include <unordered_set>
#include <type_traits>
#include <unordered_set>

namespace SURELOG {
/**
Expand All @@ -33,7 +33,8 @@ namespace SURELOG {
*
*/
typedef uint32_t RawNodeId;
inline static constexpr RawNodeId InvalidRawNodeId = 0; // Max of 28 bits as per cache!
inline static constexpr RawNodeId InvalidRawNodeId =
0; // Max of 28 bits as per cache!
class NodeId final {
public:
constexpr NodeId() : NodeId(InvalidRawNodeId) {}
Expand Down Expand Up @@ -64,28 +65,54 @@ class NodeId final {
NodeId operator-(const NodeId &rhs) const { return NodeId(id - rhs.id); }
NodeId operator+(const NodeId &rhs) const { return NodeId(id + rhs.id); }

NodeId &operator-=(const NodeId &rhs) { id -= rhs.id; return *this; }
NodeId &operator+=(const NodeId &rhs) { id += rhs.id; return *this; }
NodeId &operator-=(const NodeId &rhs) {
id -= rhs.id;
return *this;
}
NodeId &operator+=(const NodeId &rhs) {
id += rhs.id;
return *this;
}

template <typename U, typename = typename std::enable_if<
std::is_integral<U>::value>::type>
bool operator<(const U &rhs) const { return id < rhs; }
bool operator<(const U &rhs) const {
return id < rhs;
}
template <typename U, typename = typename std::enable_if<
std::is_integral<U>::value>::type>
bool operator<=(const U &rhs) const { return id <= rhs; }
bool operator<=(const U &rhs) const {
return id <= rhs;
}

template <typename U, typename = typename std::enable_if<
std::is_integral<U>::value>::type>
bool operator>(const U &rhs) const { return id > rhs; }
bool operator>(const U &rhs) const {
return id > rhs;
}
template <typename U, typename = typename std::enable_if<
std::is_integral<U>::value>::type>
bool operator>=(const U &rhs) const { return id >= rhs; }
bool operator>=(const U &rhs) const {
return id >= rhs;
}

NodeId &operator++() { ++id; return *this; }
NodeId operator++(int) { const NodeId rid(id++); return rid; }
NodeId &operator++() {
++id;
return *this;
}
NodeId operator++(int) {
const NodeId rid(id++);
return rid;
}

NodeId &operator--() { --id; return *this; }
NodeId operator--(int) { const NodeId rid(id--); return rid; }
NodeId &operator--() {
--id;
return *this;
}
NodeId operator--(int) {
const NodeId rid(id--);
return rid;
}

NodeId &operator=(const NodeId &rhs) {
if (this != &rhs) {
Expand Down
12 changes: 5 additions & 7 deletions include/Surelog/Common/PathId.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
#define SURELOG_PATHID_H
#pragma once

#include "Surelog/config.h"

#include <Surelog/Common/SymbolId.h>

#include <cstdint>
Expand All @@ -29,6 +27,8 @@
#include <unordered_set>
#include <vector>

#include "Surelog/config.h"

namespace SURELOG {
/**
* class PathId
Expand All @@ -52,8 +52,7 @@ class SymbolTable;
class PathId final {
public:
#if SURELOG_PATHID_DEBUG_ENABLED
PathId()
: m_symbolTable(nullptr), m_id(BadRawPathId), m_value(BadRawPath) {}
PathId() : m_symbolTable(nullptr), m_id(BadRawPathId), m_value(BadRawPath) {}
PathId(const SymbolTable *const symbolTable, RawPathId id,
std::string_view value)
: m_symbolTable(symbolTable), m_id(id), m_value(value) {}
Expand All @@ -66,8 +65,7 @@ class PathId final {
PathId(const SymbolTable *const symbolTable, RawPathId id,
std::string_view value)
: m_symbolTable(symbolTable), m_id(id) {}
PathId(const PathId &rhs)
: PathId(rhs.m_symbolTable, rhs.m_id, BadRawPath) {}
PathId(const PathId &rhs) : PathId(rhs.m_symbolTable, rhs.m_id, BadRawPath) {}
PathId(const SymbolTable *const symbolTable, SymbolId id)
: PathId(symbolTable, (RawSymbolId)id, BadRawPath) {}
#endif
Expand Down Expand Up @@ -117,7 +115,7 @@ inline std::ostream &operator<<(std::ostream &strm, const PathId &pathId) {
return strm << pathId.m_id;
}

struct PathIdPP final { // Pretty Printer
struct PathIdPP final { // Pretty Printer
const PathId &m_id;

explicit PathIdPP(const PathId &id) : m_id(id) {}
Expand Down
10 changes: 5 additions & 5 deletions include/Surelog/Common/PlatformFileSystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,16 @@
#define SURELOG_PLATFORMFILESYSTEM_H
#pragma once

#include <functional>
#include <utility>
#include <vector>
#include <string_view>
#include <string>
#include <Surelog/Common/FileSystem.h>

#include <functional>
#include <memory>
#include <mutex>
#include <set>
#include <string>
#include <string_view>
#include <utility>
#include <vector>

namespace SURELOG {
class SymbolTable;
Expand Down
6 changes: 3 additions & 3 deletions include/Surelog/Common/SymbolId.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ using UHDM::RawSymbolId;
using UHDM::SymbolId;
using UHDM::SymbolIdPP;

using UHDM::BadRawSymbolId;
using UHDM::BadRawSymbol;
using UHDM::BadRawSymbolId;
using UHDM::BadSymbolId;

using UHDM::operator<<;

using UHDM::SymbolIdLessThanComparer;
using UHDM::SymbolIdHasher;
using UHDM::SymbolIdEqualityComparer;
using UHDM::SymbolIdHasher;
using UHDM::SymbolIdLessThanComparer;

using UHDM::SymbolIdSet;
using UHDM::SymbolIdUnorderedSet;
Expand Down
Loading

0 comments on commit 98983f6

Please sign in to comment.