Browse Source

Formatted code with custom clang-format

merge-requests/37/head
eidheim 8 years ago
parent
commit
791b76b04c
  1. 9
      .clang-format
  2. 30
      README.md
  3. 16
      src/clangmm.h
  4. 3
      src/code_complete_results.h
  5. 3
      src/compilation_database.h
  6. 4
      src/compile_command.h
  7. 2
      src/compile_commands.h
  8. 2
      src/completion_string.h
  9. 7
      src/cursor.cc
  10. 4
      src/cursor.h
  11. 11
      src/diagnostic.h
  12. 1
      src/source_location.cc
  13. 3
      src/source_location.h
  14. 2
      src/source_range.h
  15. 11
      src/token.h
  16. 2
      src/tokens.cc
  17. 6
      src/tokens.h
  18. 15
      src/translation_unit.h
  19. 3
      src/utility.cc
  20. 2
      src/utility.h
  21. 2
      tests/code_complete_results_test.cc
  22. 2
      tests/completion_string_test.cc
  23. 2
      tests/cursor_test.cc
  24. 4
      tests/diagnostics_test.cc
  25. 2
      tests/source_location_test.cc
  26. 2
      tests/token_test.cc
  27. 4
      tests/translation_unit_test.cc

9
.clang-format

@ -0,0 +1,9 @@
IndentWidth: 2
AccessModifierOffset: -2
UseTab: Never
ColumnLimit: 0
MaxEmptyLinesToKeep: 2
SpaceBeforeParens: Never
BreakBeforeBraces: Custom
BraceWrapping: {BeforeElse: true, BeforeCatch: true}
NamespaceIndentation: All

30
README.md

@ -13,7 +13,7 @@ Developed for [juCi++](https://gitlab.com/cppit/jucipp), a lightweight, platform
## Installation ##
See [installation guide](https://gitlab.com/cppit/libclangmm/blob/master/docs/install.md)
# Tests #
## Tests ##
To run the unit tests:
```sh
mkdir build && cd build
@ -21,3 +21,31 @@ cmake -DBUILD_TESTING=1 ..
make
make test
```
## Coding style
Due to poor lambda support in clang-format, a custom clang-format is used with the following patch applied:
```diff
diff --git a/lib/Format/ContinuationIndenter.cpp b/lib/Format/ContinuationIndenter.cpp
index bb8efd61a3..e80a487055 100644
--- a/lib/Format/ContinuationIndenter.cpp
+++ b/lib/Format/ContinuationIndenter.cpp
@@ -276,6 +276,8 @@ LineState ContinuationIndenter::getInitialState(unsigned FirstIndent,
}
bool ContinuationIndenter::canBreak(const LineState &State) {
+ if(Style.ColumnLimit==0)
+ return true;
const FormatToken &Current = *State.NextToken;
const FormatToken &Previous = *Current.Previous;
assert(&Previous == Current.Previous);
@@ -325,6 +327,8 @@ bool ContinuationIndenter::canBreak(const LineState &State) {
}
bool ContinuationIndenter::mustBreak(const LineState &State) {
+ if(Style.ColumnLimit==0)
+ return false;
const FormatToken &Current = *State.NextToken;
const FormatToken &Previous = *Current.Previous;
if (Current.MustBreakBefore || Current.is(TT_InlineASMColon))
```

16
src/clangmm.h

@ -1,17 +1,17 @@
#ifndef CLANGMM_H_
#define CLANGMM_H_
#include "translation_unit.h"
#include "source_location.h"
#include "source_range.h"
#include "token.h"
#include "tokens.h"
#include "code_complete_results.h"
#include "compilation_database.h"
#include "compile_commands.h"
#include "compile_command.h"
#include "code_complete_results.h"
#include "compile_commands.h"
#include "completion_string.h"
#include "index.h"
#include "cursor.h"
#include "diagnostic.h"
#include "index.h"
#include "source_location.h"
#include "source_range.h"
#include "token.h"
#include "tokens.h"
#include "translation_unit.h"
#include "utility.h"
#endif // CLANGMM_H_

3
src/code_complete_results.h

@ -1,9 +1,9 @@
#ifndef CODECOMPLETERESULTS_H_
#define CODECOMPLETERESULTS_H_
#include "completion_string.h"
#include <clang-c/Index.h>
#include <map>
#include <string>
#include "completion_string.h"
namespace clangmm {
class CodeCompleteResults {
@ -11,6 +11,7 @@ namespace clangmm {
CodeCompleteResults(CXTranslationUnit &cx_tu, const std::string &buffer,
unsigned line_num, unsigned column);
public:
CodeCompleteResults(CodeCompleteResults &) = delete;
CodeCompleteResults(CodeCompleteResults &&rhs);

3
src/compilation_database.h

@ -7,6 +7,7 @@
namespace clangmm {
class CompilationDatabase {
CXCompilationDatabase_Error cx_db_error;
public:
explicit CompilationDatabase(const std::string &project_path);
~CompilationDatabase();
@ -15,6 +16,6 @@ namespace clangmm {
CXCompilationDatabase cx_db;
};
}
} // namespace clangmm
#endif // COMPILATIONDATABASE_H_

4
src/compile_command.h

@ -1,8 +1,8 @@
#ifndef COMPILECOMMAND_H_
#define COMPILECOMMAND_H_
#include <clang-c/CXCompilationDatabase.h>
#include <vector>
#include <string>
#include <vector>
namespace clangmm {
class CompileCommand {
@ -12,5 +12,5 @@ namespace clangmm {
CXCompileCommand cx_command;
};
}
} // namespace clangmm
#endif // COMPILECOMMAND_H_

2
src/compile_commands.h

@ -15,5 +15,5 @@ namespace clangmm {
CXCompileCommands cx_commands;
};
}
} // namespace clangmm
#endif // COMPILECOMMANDS_H_

2
src/completion_string.h

@ -1,9 +1,9 @@
#ifndef COMPLETIONSTRING_H_
#define COMPLETIONSTRING_H_
#include "cursor.h"
#include <clang-c/Index.h>
#include <string>
#include <vector>
#include "cursor.h"
namespace clangmm {
enum CompletionChunkKind {

7
src/cursor.cc

@ -159,13 +159,10 @@ clangmm::Cursor clangmm::Cursor::get_semantic_parent() const {
std::vector<clangmm::Cursor> clangmm::Cursor::get_children() const {
std::vector<Cursor> result;
clang_visitChildren(cx_cursor,
[](CXCursor cur, CXCursor /*parent*/, CXClientData data) {
clang_visitChildren(cx_cursor, [](CXCursor cur, CXCursor /*parent*/, CXClientData data) {
static_cast<std::vector<Cursor> *>(data)->emplace_back(cur);
return CXChildVisit_Continue;
},
&result
);
}, &result);
return result;
}

4
src/cursor.h

@ -1,11 +1,11 @@
#ifndef CURSOR_H_
#define CURSOR_H_
#include <clang-c/Index.h>
#include "source_location.h"
#include "source_range.h"
#include <clang-c/Index.h>
#include <string>
#include <vector>
#include <unordered_set>
#include <vector>
namespace clangmm {
class Cursor {

11
src/diagnostic.h

@ -1,14 +1,15 @@
#ifndef DIAGNOSTIC_H_
#define DIAGNOSTIC_H_
#include "source_range.h"
#include <clang-c/Index.h>
#include <string>
#include <vector>
#include <clang-c/Index.h>
#include "source_range.h"
namespace clangmm {
class Diagnostic {
friend class TranslationUnit;
Diagnostic(CXTranslationUnit &cx_tu, CXDiagnostic &cx_diagnostic);
public:
enum class Severity {
Ignored = 0,
@ -20,8 +21,8 @@ namespace clangmm {
class FixIt {
public:
FixIt(const std::string &source, const std::pair<clangmm::Offset, clangmm::Offset> &offsets):
source(source), offsets(offsets) {}
FixIt(const std::string &source, const std::pair<clangmm::Offset, clangmm::Offset> &offsets)
: source(source), offsets(offsets) {}
std::string source;
std::pair<clangmm::Offset, clangmm::Offset> offsets;
};
@ -32,6 +33,6 @@ namespace clangmm {
std::pair<clangmm::Offset, clangmm::Offset> offsets;
std::vector<FixIt> fix_its;
};
}
} // namespace clangmm
#endif // DIAGNOSTIC_H_

1
src/source_location.cc

@ -36,4 +36,3 @@ void clangmm::SourceLocation::get_data(std::string* path, unsigned *line, unsign
}
}
}

3
src/source_location.h

@ -1,8 +1,8 @@
#ifndef SOURCELOCATION_H_
#define SOURCELOCATION_H_
#include <clang-c/Index.h>
#include <string>
#include <ostream>
#include <string>
namespace clangmm {
class Offset {
@ -22,6 +22,7 @@ namespace clangmm {
friend class Diagnostic;
SourceLocation(CXTranslationUnit &tu, const std::string &filepath, unsigned offset);
SourceLocation(CXTranslationUnit &tu, const std::string &filepath, unsigned line, unsigned column);
public:
SourceLocation(const CXSourceLocation &cx_location) : cx_location(cx_location) {}

2
src/source_range.h

@ -1,7 +1,7 @@
#ifndef SOURCERANGE_H_
#define SOURCERANGE_H_
#include <clang-c/Index.h>
#include "source_location.h"
#include <clang-c/Index.h>
#include <string>
#include <utility>

11
src/token.h

@ -1,14 +1,15 @@
#ifndef TOKEN_H_
#define TOKEN_H_
#include <clang-c/Index.h>
#include "cursor.h"
#include "source_location.h"
#include "source_range.h"
#include "cursor.h"
#include <clang-c/Index.h>
#include <string>
namespace clangmm {
class Token {
friend class Tokens;
public:
enum Kind {
Punctuation,
@ -17,9 +18,11 @@ namespace clangmm {
Literal,
Comment
};
private:
Token(CXTranslationUnit &cx_tu, CXToken &cx_token, CXCursor &cx_cursor):
cx_tu(cx_tu), cx_token(cx_token), cx_cursor(cx_cursor) {}
Token(CXTranslationUnit &cx_tu, CXToken &cx_token, CXCursor &cx_cursor)
: cx_tu(cx_tu), cx_token(cx_token), cx_cursor(cx_cursor) {}
public:
Kind get_kind() const;
std::string get_spelling() const;

2
src/tokens.cc

@ -1,8 +1,8 @@
#include "tokens.h"
#include "utility.h"
#include <unordered_set>
#include <cstring>
#include <map>
#include <unordered_set>
clangmm::Tokens::Tokens(CXTranslationUnit &cx_tu, const SourceRange &range, bool annotate_tokens) : cx_tu(cx_tu) {
unsigned num_tokens;

6
src/tokens.h

@ -1,21 +1,23 @@
#ifndef TOKENS_H_
#define TOKENS_H_
#include <clang-c/Index.h>
#include "source_range.h"
#include "token.h"
#include <clang-c/Index.h>
#include <memory>
#include <unordered_set>
#include <vector>
#include <memory>
namespace clangmm {
class Tokens : public std::vector<clangmm::Token> {
friend class TranslationUnit;
friend class Diagnostic;
Tokens(CXTranslationUnit &cx_tu, const SourceRange &range, bool annotate_tokens = true);
public:
~Tokens();
std::vector<std::pair<clangmm::Offset, clangmm::Offset>> get_similar_token_offsets(Cursor::Kind kind, const std::string &spelling,
const std::unordered_set<std::string> &usrs);
private:
CXToken *cx_tokens;
std::unique_ptr<CXCursor[]> cx_cursors;

15
src/translation_unit.h

@ -1,15 +1,15 @@
#ifndef TRANSLATIONUNIT_H_
#define TRANSLATIONUNIT_H_
#include "code_complete_results.h"
#include "cursor.h"
#include "diagnostic.h"
#include "index.h"
#include "tokens.h"
#include <clang-c/Index.h>
#include <string>
#include <vector>
#include <map>
#include <memory>
#include "index.h"
#include "diagnostic.h"
#include "tokens.h"
#include "code_complete_results.h"
#include "cursor.h"
#include <string>
#include <vector>
namespace clangmm {
class TranslationUnit {
@ -52,4 +52,3 @@ namespace clangmm {
};
} // namespace clangmm
#endif // TRANSLATIONUNIT_H_

3
src/utility.cc

@ -55,7 +55,8 @@ void clangmm::remove_include_guard(std::string &buffer) {
}
std::smatch sm;
if(empty_line) {}
if(empty_line) {
}
else if(!found_ifndef && (std::regex_match(line, sm, ifndef_regex1) || std::regex_match(line, sm, ifndef_regex2))) {
found_ifndef = true;
ranges.emplace_back(start_of_line, c);

2
src/utility.h

@ -15,6 +15,6 @@ namespace clangmm {
};
void remove_include_guard(std::string &buffer);
}
} // namespace clangmm
#endif // UTILITY_H_

2
tests/code_complete_results_test.cc

@ -1,7 +1,7 @@
#include "clangmm.h"
#include <string>
#include <cassert>
#include <regex>
#include <string>
int main() {
std::string tests_path = LIBCLANGMM_TESTS_PATH;

2
tests/completion_string_test.cc

@ -1,7 +1,7 @@
#include "clangmm.h"
#include <string>
#include <cassert>
#include <regex>
#include <string>
int main() {
{

2
tests/cursor_test.cc

@ -1,7 +1,7 @@
#include "clangmm.h"
#include <string>
#include <cassert>
#include <regex>
#include <string>
int main() {
std::string tests_path = LIBCLANGMM_TESTS_PATH;

4
tests/diagnostics_test.cc

@ -1,7 +1,7 @@
#include "clangmm.h"
#include <iostream>
#include <fstream>
#include <cassert>
#include <fstream>
#include <iostream>
#include <regex>
using namespace std;

2
tests/source_location_test.cc

@ -1,6 +1,6 @@
#include "clangmm.h"
#include <string>
#include <cassert>
#include <string>
int main() {
std::string tests_path = LIBCLANGMM_TESTS_PATH;

2
tests/token_test.cc

@ -1,6 +1,6 @@
#include "clangmm.h"
#include <string>
#include <cassert>
#include <string>
int main() {
std::string tests_path = LIBCLANGMM_TESTS_PATH;

4
tests/translation_unit_test.cc

@ -1,7 +1,7 @@
#include "clangmm.h"
#include <string>
#include <map>
#include <cassert>
#include <map>
#include <string>
int main() {
std::string tests_path = LIBCLANGMM_TESTS_PATH;

Loading…
Cancel
Save