Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/cmake.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ on:

env:
# Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.)
BUILD_TYPE: Release
BUILD_TYPE: Debug

jobs:
build:
Expand All @@ -22,12 +22,12 @@ jobs:
- uses: actions/checkout@v2

- name: Install dependencies
run: brew install rapidjson llvm
run: brew install rapidjson llvm@11

- name: Configure CMake
# Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make.
# See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type
run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DCMAKE_PREFIX_PATH=$(brew --prefix llvm)
run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DCMAKE_PREFIX_PATH=$(brew --prefix llvm@11)

- name: Build
# Build your program with the given configuration
Expand Down
93 changes: 4 additions & 89 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,103 +9,18 @@ Initial idea picked up from this conference by Sergiy Migdalskiy: https://archiv

## Requirements

- Llvm 11
- MacOS
- Llvm 11 - Llvm 12 is not supported
- RapidJson 1.x

You might need to give the path to the llvm folder to CMake:
```bash
brew install llvm@11 rapidjson ninja
mkdir builds && cd builds
cmake .. -G Ninja -DCMAKE_PREFIX_PATH=<your_path_to_llvm_install>
cmake .. -G Ninja -DCMAKE_PREFIX_PATH=$(brew --prefix llvm@11)
ninja
```
With brew you can print the path using:
```bash
brew --prefix llvm
```
```bash
cmake .. -G Ninja -DCMAKE_PREFIX_PATH="$(brew --prefix llvm)"
```

## Example
File test_example.hpp:
```c++
#ifndef CPP2JSON_TEST_EXAMPLE_HPP
#define CPP2JSON_TEST_EXAMPLE_HPP
#include <string>

struct Example01
{
float m_float;
std::string m_string;
int m_int;
};

#endif //CPP2JSON_TEST_EXAMPLE_HPP
```

Run cpp2json on it:
```bash
$> cpp2json test_example.hpp --pretty --
```

Will give you the following JSON output:
```json
{
"classes": {
"Example01": {
"fields": [
{
"name": "m_float",
"type": {
"key": "float",
"expression": "float",
"pointer": false,
"array": false,
"reference": false,
"const": false,
"volatile": false,
"literal": true,
"enum": false
}
},
{
"name": "m_string",
"type": {
"key": "std::string",
"expression": "std::string",
"pointer": false,
"array": false,
"reference": false,
"const": false,
"volatile": false,
"literal": false,
"enum": false
}
},
{
"name": "m_int",
"type": {
"key": "int",
"expression": "int",
"pointer": false,
"array": false,
"reference": false,
"const": false,
"volatile": false,
"literal": true,
"enum": false
}
}
],
"methods": [],
"annotations": [],
"bases": [],
"file": "/Users/iota/projects/tools/cpp2json/sources/tests/resources/test_example.hpp"
}
},
"enums": {}
}
```
## Usage
```bash
USAGE: cpp2json [options] <source0> [... <sourceN>]
Expand Down
3 changes: 3 additions & 0 deletions sources/core/src/CommandLineHelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@ static std::string const LlvmBasePath{LLVM_DIR};

clang::tooling::CommandLineArguments makeLlvmIncludeArguments()
{
assert( !LlvmBasePath.empty() );

std::string const llvmVersion = LlvmBasePath.substr(LlvmBasePath.find_last_of('/'));
clang::tooling::CommandLineArguments extraArguments{
"-std=c++14",
"-I" + LlvmBasePath + "/include/c++/v1",
"-I" + LlvmBasePath + "/lib/clang/" + llvmVersion + "/include",
};
Expand Down
3 changes: 2 additions & 1 deletion sources/tests/Cpp2JsonVisitorFixture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ rapidjson::Value::ConstObject Cpp2JsonVisitorFixture::getField(std::string const
return field;
}
}
assert(false);

throw std::runtime_error("field not found");
}

rapidjson::Value::ConstArray Cpp2JsonVisitorFixture::getFieldsOf(const std::string &className) const
Expand Down