Skip to content

Commit cfe6bf1

Browse files
large refactoring:
The code is split into multiple modules 1. cppast: contains code to represent the AST of C++. 2. cppparser: the code that produces cppast objects after parsing C++ file. 3. cppcodegen: creates C++ code from given cppast objects. A new and improved design is used: - no more direct access to data members of ast classes. - use of class instead of struct. - better modeling of ast.
1 parent f9a4cfa commit cfe6bf1

File tree

7,515 files changed

+12821
-22370
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

7,515 files changed

+12821
-22370
lines changed

.clang-tidy

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Copyright (C) 2022 Satya Das and CppParser contributors
2+
# SPDX-License-Identifier: MIT
3+
4+
Checks: '-*,readability-identifier-naming'
5+
6+
CheckOptions:
7+
- { key: readability-identifier-naming.ClassCase, value: CamelCase }
8+
- { key: readability-identifier-naming.MethodCase, value: camelCase }
9+
- { key: readability-identifier-naming.FunctionCase, value: CamelCase }
10+
- { key: readability-identifier-naming.GlobalFunctionCase, value: CamelCase }
11+
- { key: readability-identifier-naming.VariableCase, value: camelBack }
12+
- { key: readability-identifier-naming.ParameterCase, value: camelBack }
13+
- { key: readability-identifier-naming.GlobalConstantCase, value: camelBack }
14+
- { key: readability-identifier-naming.StaticConstantCase, value: camelBack }
15+
- { key: readability-identifier-naming.ConstexprVariableCase, value: camelBack }
16+
17+
HeaderFilterRegex: '.*\.h'

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ publish/
107107
*.pubxml
108108

109109
# NuGet Packages Directory
110-
## TODO: If you have NuGet Package Restore enabled, uncomment the next line
110+
## If you have NuGet Package Restore enabled, uncomment the next line
111111
#packages/
112112

113113
# Windows Azure Build Output

.vscode/c_cpp_properties.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
"compilerPath": "/usr/bin/clang-5.0",
1010
"cStandard": "c11",
1111
"intelliSenseMode": "linux-clang-x64",
12-
"cppStandard": "c++17"
12+
"cppStandard": "c++17",
13+
"compileCommands": "${workspaceFolder}/build/compile_commands.json"
1314
}
1415
],
1516
"version": 4

.vscode/launch.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,16 @@
55
"version": "0.2.0",
66
"configurations": [
77
{
8-
"name": "Run parser test for",
8+
"name": "Run parser test",
99
"type": "cppdbg",
1010
"request": "launch",
11-
"program": "${workspaceFolder}/build/cppparserunittest",
11+
"program": "${workspaceFolder}/build/cppparser/test/cppparsertest",
1212
// "args": [
1313
// "-p",
14-
// "/home/dassat/github/cppparser/test/e2e/test_input/wxWidgets/include/wx/generic/private/grid.h"
14+
// "/home/dassat/github/cppparser/cppparser/test/e2e/test_input/ObjectArxHeaders/AcFdUtil.h"
1515
// ],
1616
"stopAtEntry": false,
17-
"cwd": "${workspaceFolder}/build/",
17+
"cwd": "${workspaceFolder}/build/cppparser/test/",
1818
"environment": [
1919
{
2020
"name": "ZZDEBUG",
@@ -36,12 +36,12 @@
3636
"name": "Run unit test",
3737
"type": "cppdbg",
3838
"request": "launch",
39-
"program": "${workspaceFolder}/build/cppparserunittest",
39+
"program": "${workspaceFolder}/build/cppparser/test/cppparserunittest",
4040
"args": [
41-
"vardecl-or-expr-ambiguity"
41+
"Attribute specifier sequence"
4242
],
4343
"stopAtEntry": false,
44-
"cwd": "${workspaceFolder}/build/",
44+
"cwd": "${workspaceFolder}/build/cppparser/test/",
4545
"preLaunchTask": "BuildAll",
4646
"externalConsole": false,
4747
"MIMode": "gdb",

.vscode/settings.json

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
{
22
"files.associations": {
33
"*.mdpp": "markdown",
4+
"*.i": "Swig interface",
5+
"*.cmake": "cmake",
46
"array": "cpp",
57
"atomic": "cpp",
68
"hash_map": "cpp",
@@ -64,7 +66,24 @@
6466
"bitset": "cpp",
6567
"regex": "cpp",
6668
"iomanip": "cpp",
67-
"variant": "cpp"
69+
"variant": "cpp",
70+
"strstream": "cpp",
71+
"cfenv": "cpp",
72+
"complex": "cpp",
73+
"typeindex": "cpp",
74+
"csignal": "cpp",
75+
"*.ipp": "cpp",
76+
"bit": "cpp",
77+
"compare": "cpp",
78+
"concepts": "cpp",
79+
"__bit_reference": "cpp",
80+
"__bits": "cpp",
81+
"__config": "cpp",
82+
"__debug": "cpp",
83+
"__split_buffer": "cpp",
84+
"__tuple": "cpp",
85+
"__verbose_abort": "cpp"
6886
},
69-
"git.ignoreLimitWarning": true
87+
"git.ignoreLimitWarning": true,
88+
"sonarlint.pathToCompileCommands": "${workspaceFolder}/build/compile_commands.json"
7089
}

.vscode/tasks.json

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,31 @@
1313
"isDefault": true
1414
},
1515
"presentation": {
16-
"clear": true // <-- this line
16+
"clear": true
1717
},
1818
"problemMatcher": [
19-
"$gcc",
19+
"$gcc"
2020
]
21+
},
22+
{
23+
"type": "shell",
24+
"label": "BuildFile",
25+
"command": "ninja `grep '${relativeFile}' build.ninja | head -1 | cut -d':' -f1 | cut -d' ' -f2-`",
26+
"options": {
27+
"cwd": "${workspaceFolder}/build"
28+
},
29+
"problemMatcher": [
30+
"$gcc"
31+
],
32+
"group": "build",
33+
"presentation": {
34+
"echo": true,
35+
"revealProblems": "never",
36+
"focus": false,
37+
"panel": "shared",
38+
"showReuseMessage": true,
39+
"clear": true
40+
}
2141
}
2242
],
2343
"version": "2.0.0"

CMakeLists.txt

Lines changed: 7 additions & 183 deletions
Original file line numberDiff line numberDiff line change
@@ -1,195 +1,19 @@
11
cmake_minimum_required(VERSION 3.4)
2-
3-
project(cppparser)
4-
52
enable_testing()
63

7-
include("../common/cmake/conf.cmake")
4+
project(cppparser)
85

96
set(CMAKE_CXX_STANDARD 17)
7+
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
108

119
if(MSVC)
1210
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd\"4996\"")
1311
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /wd\"4996\"")
1412
endif()
1513

16-
add_subdirectory(third_party/btyacc_tp)
17-
18-
add_definitions(-DBOOST_AUTO_LINK_NOMANGLE)
19-
20-
add_subdirectory(../common/third_party/boost_tp/cmake ${CMAKE_BINARY_DIR}/boost)
21-
22-
include_directories(../common/third_party)
23-
24-
#############################################
25-
## CppParser
26-
27-
find_program(
28-
FLEX
29-
"flex"
30-
# Assuming for Linux and OSX flex is already available
31-
# Only for Windows the flex will be used from the repository
32-
PATHS ENV PATH "third_party/flex_tp"
33-
)
34-
if(${FLEX} MATCHES "FLEX-NOTFOUND")
35-
message(FATAL_ERROR "'flex' not found")
36-
else()
37-
message(STATUS "Found 'flex' as ${FLEX}")
38-
endif()
39-
40-
set_source_files_properties(src/parser.tab.cpp GENERATED)
41-
set_source_files_properties(src/parser.lex.cpp GENERATED)
42-
set_source_files_properties(src/parser.tab.h GENERATED)
43-
44-
add_custom_command(
45-
OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/src/parser.tab.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/parser.tab.h
46-
COMMAND $<TARGET_FILE:btyacc> -v -b parser -d ${CMAKE_CURRENT_SOURCE_DIR}/src/parser.y
47-
# COMMAND ${CMAKE_COMMAND} -E copy y_tab.c ${CMAKE_CURRENT_SOURCE_DIR}/parser.tab.cpp
48-
# COMMAND ${CMAKE_COMMAND} -E copy y_tab.h ${CMAKE_CURRENT_SOURCE_DIR}/parser.tab.h
49-
COMMAND ${CMAKE_COMMAND} -E copy parser.tab.c ${CMAKE_CURRENT_SOURCE_DIR}/src/parser.tab.cpp
50-
COMMAND ${CMAKE_COMMAND} -E copy parser.tab.h ${CMAKE_CURRENT_SOURCE_DIR}/src/parser.tab.h
51-
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/src/parser.y
52-
)
53-
54-
add_custom_command(
55-
OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/src/parser.lex.cpp
56-
COMMAND ${FLEX} -o${CMAKE_CURRENT_SOURCE_DIR}/src/parser.lex.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/parser.l
57-
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/src/parser.l ${CMAKE_CURRENT_SOURCE_DIR}/src/parser.tab.h
58-
)
59-
60-
set(CPPPARSER_SOURCES
61-
src/cppparser.cpp
62-
src/cppast.cpp
63-
src/cppprog.cpp
64-
src/cppwriter.cpp
65-
src/cppobjfactory.cpp
66-
src/lexer-helper.cpp
67-
src/parser.l
68-
src/parser.y
69-
src/parser.lex.cpp
70-
src/parser.tab.cpp
71-
src/utils.cpp
72-
)
73-
74-
add_library(cppparser STATIC ${CPPPARSER_SOURCES})
75-
add_dependencies(cppparser btyacc boost_filesystem boost_program_options)
76-
target_link_libraries(cppparser
77-
PUBLIC
78-
boost_filesystem
79-
boost_program_options
80-
boost_system
81-
)
82-
target_include_directories(
83-
cppparser
84-
PUBLIC
85-
pub
86-
../common/third_party/boost_tp
87-
PRIVATE
88-
hack
89-
)
90-
target_compile_definitions(
91-
cppparser
92-
PRIVATE
93-
YY_NO_UNPUT
94-
)
95-
96-
#############################################
97-
## CppParserTest
98-
99-
add_executable(cppparsertest
100-
test/app/cppparsertest.cpp
101-
)
102-
103-
target_link_libraries(cppparsertest
104-
PRIVATE
105-
cppparser
106-
boost_filesystem
107-
boost_program_options
108-
boost_system
109-
)
110-
111-
set(E2E_TEST_DIR ${CMAKE_CURRENT_LIST_DIR}/test/e2e)
112-
set(CTEST_OUTPUT_ON_FAILURE 1)
113-
add_test(
114-
NAME ParserTest
115-
COMMAND cppparsertest --input-folder=${E2E_TEST_DIR}/test_input
116-
--output-folder=${E2E_TEST_DIR}/test_output
117-
--master-files-folder=${E2E_TEST_DIR}/test_master
118-
)
119-
120-
#############################################
121-
## Unit Test
122-
123-
set(TEST_SNIPPET_EMBEDDED_TESTS
124-
${CMAKE_CURRENT_LIST_DIR}/test/unit/attribute-specifier-sequence.cpp
125-
${CMAKE_CURRENT_LIST_DIR}/test/unit/disabled-code-test.cpp
126-
${CMAKE_CURRENT_LIST_DIR}/test/unit/error-handler-test.cpp
127-
${CMAKE_CURRENT_LIST_DIR}/test/unit/expr-test.cpp
128-
${CMAKE_CURRENT_LIST_DIR}/test/unit/namespace-test.cpp
129-
${CMAKE_CURRENT_LIST_DIR}/test/unit/template-test.cpp
130-
${CMAKE_CURRENT_LIST_DIR}/test/unit/uniform-init-test.cpp
131-
${CMAKE_CURRENT_LIST_DIR}/test/unit/vardecl-test.cpp
132-
)
133-
134-
add_executable(cppparserunittest
135-
${CMAKE_CURRENT_LIST_DIR}/test/unit/main.cpp
136-
${CMAKE_CURRENT_LIST_DIR}/test/unit/test-hello-world.cpp
137-
138-
${TEST_SNIPPET_EMBEDDED_TESTS}
139-
)
140-
target_include_directories(cppparserunittest
141-
PRIVATE
142-
${CMAKE_CURRENT_LIST_DIR}/src
143-
)
144-
145-
target_link_libraries(cppparserunittest
146-
PRIVATE
147-
cppparser
148-
boost_filesystem
149-
boost_program_options
150-
boost_system
151-
)
152-
set(UNIT_TEST_DIR ${CMAKE_CURRENT_LIST_DIR}/test/unit)
153-
add_test(
154-
NAME ParserUnitTest
155-
COMMAND cppparserunittest
156-
)
157-
158-
# cppparserembeddedsnippetvalidity is just to ensure that the embedded
159-
# code snippets used in unit tests are valid C/C++ code.
160-
# So, the goal is to test if the embedded test snippets compile without error.
161-
add_executable(cppparserembeddedsnippetvalidity
162-
${CMAKE_CURRENT_LIST_DIR}/test/unit/main.cpp
163-
164-
${TEST_SNIPPET_EMBEDDED_TESTS}
165-
)
166-
target_include_directories(cppparserembeddedsnippetvalidity
167-
PRIVATE
168-
${CMAKE_CURRENT_LIST_DIR}/src
169-
)
170-
target_compile_definitions(cppparserembeddedsnippetvalidity
171-
PRIVATE
172-
"TEST_CASE_SNIPPET_STARTS_FROM_NEXT_LINE=1"
173-
"CPPPARSER_TEST_DEFINED_MACRO=1"
174-
)
175-
target_link_libraries(cppparserembeddedsnippetvalidity
176-
PRIVATE
177-
cppparser
178-
boost_filesystem
179-
boost_program_options
180-
boost_system
181-
)
182-
183-
if(NOT MSVC)
184-
target_compile_options(cppparserembeddedsnippetvalidity
185-
PRIVATE
186-
-Wno-unused-variable
187-
-Wno-attributes
188-
-Wno-unused-value
189-
-Wno-uninitialized
190-
-Wno-unused-but-set-variable
191-
)
192-
endif()
14+
add_subdirectory(cppast)
15+
add_subdirectory(cppparser)
16+
add_subdirectory(cppwriter)
19317

19418
find_program(
19519
MARKDOWN_PP
@@ -200,8 +24,8 @@ find_program(
20024
if(NOT ${MARKDOWN_PP} MATCHES "MARKDOWN_PP-NOTFOUND")
20125
add_custom_command(
20226
OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/README.md
203-
COMMAND ${MARKDOWN_PP} ${CMAKE_CURRENT_SOURCE_DIR}/src/README.mdpp -o ${CMAKE_CURRENT_SOURCE_DIR}/README.md
204-
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/src/README.mdpp ${RESPATHS} ${EXAMPLE_HEADERS}
27+
COMMAND ${MARKDOWN_PP} ${CMAKE_CURRENT_SOURCE_DIR}/cppparser/src/README.mdpp -o ${CMAKE_CURRENT_SOURCE_DIR}/README.md
28+
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/cppparser/src/README.mdpp ${RESPATHS} ${EXAMPLE_HEADERS}
20529
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
20630
)
20731
add_custom_target(

CodingStyleAndGuidelines.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Coding Style and Guidelines
2+
3+
- All data members must be private.
4+
- Prefer class over struct unless it is truly a data collection without methods.
5+
- No Get or Set prefix in method names. E.g. prefer 2 overoads of owner() instead of getOwner() and setOwner().
6+
- Mostly one class per file.
7+
- No Raw pointer. In general try to use modern C++ types, styles and idioms.
8+
- No full copyright message in each file, rather a 2 line stuf.
9+
- Do not return const reference of unique_ptr, prefer OptionalReference instead.

0 commit comments

Comments
 (0)