Skip to content

Commit

Permalink
large refactoring:
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
SatyaRanjanDas-tomtom committed Oct 15, 2024
1 parent f9a4cfa commit cfe6bf1
Show file tree
Hide file tree
Showing 7,515 changed files with 12,821 additions and 22,370 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
17 changes: 17 additions & 0 deletions .clang-tidy
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Copyright (C) 2022 Satya Das and CppParser contributors
# SPDX-License-Identifier: MIT

Checks: '-*,readability-identifier-naming'

CheckOptions:
- { key: readability-identifier-naming.ClassCase, value: CamelCase }
- { key: readability-identifier-naming.MethodCase, value: camelCase }
- { key: readability-identifier-naming.FunctionCase, value: CamelCase }
- { key: readability-identifier-naming.GlobalFunctionCase, value: CamelCase }
- { key: readability-identifier-naming.VariableCase, value: camelBack }
- { key: readability-identifier-naming.ParameterCase, value: camelBack }
- { key: readability-identifier-naming.GlobalConstantCase, value: camelBack }
- { key: readability-identifier-naming.StaticConstantCase, value: camelBack }
- { key: readability-identifier-naming.ConstexprVariableCase, value: camelBack }

HeaderFilterRegex: '.*\.h'
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ publish/
*.pubxml

# NuGet Packages Directory
## TODO: If you have NuGet Package Restore enabled, uncomment the next line
## If you have NuGet Package Restore enabled, uncomment the next line
#packages/

# Windows Azure Build Output
Expand Down
3 changes: 2 additions & 1 deletion .vscode/c_cpp_properties.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"compilerPath": "/usr/bin/clang-5.0",
"cStandard": "c11",
"intelliSenseMode": "linux-clang-x64",
"cppStandard": "c++17"
"cppStandard": "c++17",
"compileCommands": "${workspaceFolder}/build/compile_commands.json"
}
],
"version": 4
Expand Down
14 changes: 7 additions & 7 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@
"version": "0.2.0",
"configurations": [
{
"name": "Run parser test for",
"name": "Run parser test",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/build/cppparserunittest",
"program": "${workspaceFolder}/build/cppparser/test/cppparsertest",
// "args": [
// "-p",
// "/home/dassat/github/cppparser/test/e2e/test_input/wxWidgets/include/wx/generic/private/grid.h"
// "/home/dassat/github/cppparser/cppparser/test/e2e/test_input/ObjectArxHeaders/AcFdUtil.h"
// ],
"stopAtEntry": false,
"cwd": "${workspaceFolder}/build/",
"cwd": "${workspaceFolder}/build/cppparser/test/",
"environment": [
{
"name": "ZZDEBUG",
Expand All @@ -36,12 +36,12 @@
"name": "Run unit test",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/build/cppparserunittest",
"program": "${workspaceFolder}/build/cppparser/test/cppparserunittest",
"args": [
"vardecl-or-expr-ambiguity"
"Attribute specifier sequence"
],
"stopAtEntry": false,
"cwd": "${workspaceFolder}/build/",
"cwd": "${workspaceFolder}/build/cppparser/test/",
"preLaunchTask": "BuildAll",
"externalConsole": false,
"MIMode": "gdb",
Expand Down
23 changes: 21 additions & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
{
"files.associations": {
"*.mdpp": "markdown",
"*.i": "Swig interface",
"*.cmake": "cmake",
"array": "cpp",
"atomic": "cpp",
"hash_map": "cpp",
Expand Down Expand Up @@ -64,7 +66,24 @@
"bitset": "cpp",
"regex": "cpp",
"iomanip": "cpp",
"variant": "cpp"
"variant": "cpp",
"strstream": "cpp",
"cfenv": "cpp",
"complex": "cpp",
"typeindex": "cpp",
"csignal": "cpp",
"*.ipp": "cpp",
"bit": "cpp",
"compare": "cpp",
"concepts": "cpp",
"__bit_reference": "cpp",
"__bits": "cpp",
"__config": "cpp",
"__debug": "cpp",
"__split_buffer": "cpp",
"__tuple": "cpp",
"__verbose_abort": "cpp"
},
"git.ignoreLimitWarning": true
"git.ignoreLimitWarning": true,
"sonarlint.pathToCompileCommands": "${workspaceFolder}/build/compile_commands.json"
}
24 changes: 22 additions & 2 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,31 @@
"isDefault": true
},
"presentation": {
"clear": true // <-- this line
"clear": true
},
"problemMatcher": [
"$gcc",
"$gcc"
]
},
{
"type": "shell",
"label": "BuildFile",
"command": "ninja `grep '${relativeFile}' build.ninja | head -1 | cut -d':' -f1 | cut -d' ' -f2-`",
"options": {
"cwd": "${workspaceFolder}/build"
},
"problemMatcher": [
"$gcc"
],
"group": "build",
"presentation": {
"echo": true,
"revealProblems": "never",
"focus": false,
"panel": "shared",
"showReuseMessage": true,
"clear": true
}
}
],
"version": "2.0.0"
Expand Down
190 changes: 7 additions & 183 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,195 +1,19 @@
cmake_minimum_required(VERSION 3.4)

project(cppparser)

enable_testing()

include("../common/cmake/conf.cmake")
project(cppparser)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

if(MSVC)
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd\"4996\"")
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /wd\"4996\"")
endif()

add_subdirectory(third_party/btyacc_tp)

add_definitions(-DBOOST_AUTO_LINK_NOMANGLE)

add_subdirectory(../common/third_party/boost_tp/cmake ${CMAKE_BINARY_DIR}/boost)

include_directories(../common/third_party)

#############################################
## CppParser

find_program(
FLEX
"flex"
# Assuming for Linux and OSX flex is already available
# Only for Windows the flex will be used from the repository
PATHS ENV PATH "third_party/flex_tp"
)
if(${FLEX} MATCHES "FLEX-NOTFOUND")
message(FATAL_ERROR "'flex' not found")
else()
message(STATUS "Found 'flex' as ${FLEX}")
endif()

set_source_files_properties(src/parser.tab.cpp GENERATED)
set_source_files_properties(src/parser.lex.cpp GENERATED)
set_source_files_properties(src/parser.tab.h GENERATED)

add_custom_command(
OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/src/parser.tab.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/parser.tab.h
COMMAND $<TARGET_FILE:btyacc> -v -b parser -d ${CMAKE_CURRENT_SOURCE_DIR}/src/parser.y
# COMMAND ${CMAKE_COMMAND} -E copy y_tab.c ${CMAKE_CURRENT_SOURCE_DIR}/parser.tab.cpp
# COMMAND ${CMAKE_COMMAND} -E copy y_tab.h ${CMAKE_CURRENT_SOURCE_DIR}/parser.tab.h
COMMAND ${CMAKE_COMMAND} -E copy parser.tab.c ${CMAKE_CURRENT_SOURCE_DIR}/src/parser.tab.cpp
COMMAND ${CMAKE_COMMAND} -E copy parser.tab.h ${CMAKE_CURRENT_SOURCE_DIR}/src/parser.tab.h
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/src/parser.y
)

add_custom_command(
OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/src/parser.lex.cpp
COMMAND ${FLEX} -o${CMAKE_CURRENT_SOURCE_DIR}/src/parser.lex.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/parser.l
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/src/parser.l ${CMAKE_CURRENT_SOURCE_DIR}/src/parser.tab.h
)

set(CPPPARSER_SOURCES
src/cppparser.cpp
src/cppast.cpp
src/cppprog.cpp
src/cppwriter.cpp
src/cppobjfactory.cpp
src/lexer-helper.cpp
src/parser.l
src/parser.y
src/parser.lex.cpp
src/parser.tab.cpp
src/utils.cpp
)

add_library(cppparser STATIC ${CPPPARSER_SOURCES})
add_dependencies(cppparser btyacc boost_filesystem boost_program_options)
target_link_libraries(cppparser
PUBLIC
boost_filesystem
boost_program_options
boost_system
)
target_include_directories(
cppparser
PUBLIC
pub
../common/third_party/boost_tp
PRIVATE
hack
)
target_compile_definitions(
cppparser
PRIVATE
YY_NO_UNPUT
)

#############################################
## CppParserTest

add_executable(cppparsertest
test/app/cppparsertest.cpp
)

target_link_libraries(cppparsertest
PRIVATE
cppparser
boost_filesystem
boost_program_options
boost_system
)

set(E2E_TEST_DIR ${CMAKE_CURRENT_LIST_DIR}/test/e2e)
set(CTEST_OUTPUT_ON_FAILURE 1)
add_test(
NAME ParserTest
COMMAND cppparsertest --input-folder=${E2E_TEST_DIR}/test_input
--output-folder=${E2E_TEST_DIR}/test_output
--master-files-folder=${E2E_TEST_DIR}/test_master
)

#############################################
## Unit Test

set(TEST_SNIPPET_EMBEDDED_TESTS
${CMAKE_CURRENT_LIST_DIR}/test/unit/attribute-specifier-sequence.cpp
${CMAKE_CURRENT_LIST_DIR}/test/unit/disabled-code-test.cpp
${CMAKE_CURRENT_LIST_DIR}/test/unit/error-handler-test.cpp
${CMAKE_CURRENT_LIST_DIR}/test/unit/expr-test.cpp
${CMAKE_CURRENT_LIST_DIR}/test/unit/namespace-test.cpp
${CMAKE_CURRENT_LIST_DIR}/test/unit/template-test.cpp
${CMAKE_CURRENT_LIST_DIR}/test/unit/uniform-init-test.cpp
${CMAKE_CURRENT_LIST_DIR}/test/unit/vardecl-test.cpp
)

add_executable(cppparserunittest
${CMAKE_CURRENT_LIST_DIR}/test/unit/main.cpp
${CMAKE_CURRENT_LIST_DIR}/test/unit/test-hello-world.cpp

${TEST_SNIPPET_EMBEDDED_TESTS}
)
target_include_directories(cppparserunittest
PRIVATE
${CMAKE_CURRENT_LIST_DIR}/src
)

target_link_libraries(cppparserunittest
PRIVATE
cppparser
boost_filesystem
boost_program_options
boost_system
)
set(UNIT_TEST_DIR ${CMAKE_CURRENT_LIST_DIR}/test/unit)
add_test(
NAME ParserUnitTest
COMMAND cppparserunittest
)

# cppparserembeddedsnippetvalidity is just to ensure that the embedded
# code snippets used in unit tests are valid C/C++ code.
# So, the goal is to test if the embedded test snippets compile without error.
add_executable(cppparserembeddedsnippetvalidity
${CMAKE_CURRENT_LIST_DIR}/test/unit/main.cpp

${TEST_SNIPPET_EMBEDDED_TESTS}
)
target_include_directories(cppparserembeddedsnippetvalidity
PRIVATE
${CMAKE_CURRENT_LIST_DIR}/src
)
target_compile_definitions(cppparserembeddedsnippetvalidity
PRIVATE
"TEST_CASE_SNIPPET_STARTS_FROM_NEXT_LINE=1"
"CPPPARSER_TEST_DEFINED_MACRO=1"
)
target_link_libraries(cppparserembeddedsnippetvalidity
PRIVATE
cppparser
boost_filesystem
boost_program_options
boost_system
)

if(NOT MSVC)
target_compile_options(cppparserembeddedsnippetvalidity
PRIVATE
-Wno-unused-variable
-Wno-attributes
-Wno-unused-value
-Wno-uninitialized
-Wno-unused-but-set-variable
)
endif()
add_subdirectory(cppast)
add_subdirectory(cppparser)
add_subdirectory(cppwriter)

find_program(
MARKDOWN_PP
Expand All @@ -200,8 +24,8 @@ find_program(
if(NOT ${MARKDOWN_PP} MATCHES "MARKDOWN_PP-NOTFOUND")
add_custom_command(
OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/README.md
COMMAND ${MARKDOWN_PP} ${CMAKE_CURRENT_SOURCE_DIR}/src/README.mdpp -o ${CMAKE_CURRENT_SOURCE_DIR}/README.md
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/src/README.mdpp ${RESPATHS} ${EXAMPLE_HEADERS}
COMMAND ${MARKDOWN_PP} ${CMAKE_CURRENT_SOURCE_DIR}/cppparser/src/README.mdpp -o ${CMAKE_CURRENT_SOURCE_DIR}/README.md
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/cppparser/src/README.mdpp ${RESPATHS} ${EXAMPLE_HEADERS}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
)
add_custom_target(
Expand Down
9 changes: 9 additions & 0 deletions CodingStyleAndGuidelines.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Coding Style and Guidelines

- All data members must be private.
- Prefer class over struct unless it is truly a data collection without methods.
- No Get or Set prefix in method names. E.g. prefer 2 overoads of owner() instead of getOwner() and setOwner().
- Mostly one class per file.
- No Raw pointer. In general try to use modern C++ types, styles and idioms.
- No full copyright message in each file, rather a 2 line stuf.
- Do not return const reference of unique_ptr, prefer OptionalReference instead.
Loading

0 comments on commit cfe6bf1

Please sign in to comment.