Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

C language improve and refactor #24

Closed
phodal opened this issue Jan 5, 2024 · 1 comment
Closed

C language improve and refactor #24

phodal opened this issue Jan 5, 2024 · 1 comment
Assignees

Comments

@phodal
Copy link
Owner

phodal commented Jan 5, 2024

link to: archguard/archguard#96

@phodal
Copy link
Owner Author

phodal commented Jan 5, 2024

https://github.com/doxygen/doxygen/blob/master/src/classdef.cpp

For our strategy, simliar to Rust

  • file as container
  • structure as structure
  • all other functions in default
  • careful about pointer maybe take a look on clangparser.cpp
static QCString getCompoundTypeString(SrcLangExt lang,ClassDef::CompoundType compType,bool isJavaEnum)
{
  if (lang==SrcLangExt_Fortran)
  {
    switch (compType)
    {
      case ClassDef::Class:     return "module";
      case ClassDef::Struct:    return "type";
      case ClassDef::Union:     return "union";
      case ClassDef::Interface: return "interface";
      case ClassDef::Protocol:  return "protocol";
      case ClassDef::Category:  return "category";
      case ClassDef::Exception: return "exception";
      default:                  return "unknown";
    }
  }
  else
  {
    switch (compType)
    {
      case ClassDef::Class:     return isJavaEnum ? "enum" : "class";
      case ClassDef::Struct:    return "struct";
      case ClassDef::Union:     return "union";
      case ClassDef::Interface: return lang==SrcLangExt_ObjC ? "class" : "interface";
      case ClassDef::Protocol:  return "protocol";
      case ClassDef::Category:  return "category";
      case ClassDef::Exception: return "exception";
      case ClassDef::Service:   return "service";
      case ClassDef::Singleton: return "singleton";
      default:                  return "unknown";
    }
  }
}

phodal added a commit that referenced this issue Jan 6, 2024
phodal added a commit that referenced this issue Jan 6, 2024
phodal added a commit that referenced this issue Jan 6, 2024
phodal added a commit that referenced this issue Jan 6, 2024
@phodal phodal changed the title C language for fun C language improve and refactor Jan 6, 2024
phodal added a commit that referenced this issue Jan 6, 2024
phodal added a commit that referenced this issue Jan 6, 2024
phodal added a commit that referenced this issue Jan 6, 2024
@phodal phodal self-assigned this Jan 6, 2024
phodal added a commit that referenced this issue Jan 6, 2024
phodal added a commit that referenced this issue Jan 6, 2024
phodal added a commit that referenced this issue Jan 6, 2024
phodal added a commit that referenced this issue Jan 30, 2024
- Renamed `CPPFullIdentListenerTest.kt` to `CPPBasicIdentListenerTest.kt`.
- Renamed `CPPFullIdentListener.kt` to `CPPBasicIdentListener.kt`.
- Updated references in the code to reflect the new file names.
phodal added a commit that referenced this issue Jan 30, 2024
Add a new test case to identify inheritance in CPPBasicIdentListenerTest. The test case checks if the code correctly identifies the base class and implements it in the derived class.
phodal added a commit that referenced this issue Jan 30, 2024
Add a test case to identify functions in CPPAnalyser. The test case verifies that the function name is correctly identified and added to the container's data structures.
@phodal phodal closed this as completed Jan 30, 2024
phodal added a commit that referenced this issue Jan 30, 2024
This commit adds support for identifying C++ structures in the `CPPBasicIdentListener` class. It includes a new test case that analyzes a C++ code snippet and verifies the identification of a structure. The identified structure is then added to the `CodeContainer` object. Additionally, the `CodeDataStruct` class is updated to include a new `DataStructType` enum value for C++ unions.
phodal added a commit that referenced this issue Jan 30, 2024
This commit adds the CMake parser and analyser to the chapi-parser-cmake module. The parser is implemented using ANTLR and can parse CMake code. The analyser walks the parse tree and extracts relevant information.
phodal added a commit that referenced this issue Jan 30, 2024
… to CMakeBasicListener #24

- Added a new test class `CMakeBasicListenerTest` to test the functionality of `CMakeBasicListener`.
- Renamed `CMakeChapiListener` to `CMakeBasicListener` for consistency and clarity.
- Updated the `CMakeBasicListener` class to use a `CodeContainer` object and extract relevant information from the code.
- Updated the `CMakeAnalyser` class to use the renamed `CMakeBasicListener` class.
phodal added a commit that referenced this issue Jan 30, 2024
This commit adds a CMakefile example and demonstrates the usage of the CMakeAnalyser class in the README.md file. The example shows how to analyze a CMakeLists.txt file and extract relevant information using the CMakeAnalyser class.
phodal added a commit that referenced this issue Jan 30, 2024
Add the private modifier to the container variable in the CMakeBasicListener class to enforce encapsulation and improve code readability.
phodal added a commit that referenced this issue Jan 30, 2024
This commit adds a default NodeName property to the `defaultDataStruct` object in the `CFullIdentListener` class. This allows for better identification and differentiation of data structures in the code analysis process.
phodal added a commit that referenced this issue Jan 30, 2024
- Refactored `CFullIdentListener.kt` to improve handling of include declarations.
- Updated `enterIncludeDeclaration` method to use a more descriptive variable name.
- Modified `includeIdentifier` rule in `C.g4` to allow for multiple identifiers separated by dots.
- Updated `CFullIdentListenerTest.kt` to analyze C files instead of Rust files.
phodal added a commit that referenced this issue Jan 30, 2024
phodal added a commit that referenced this issue Jan 30, 2024
This commit modifies the `includeIdentifier` rule in the `C.g4` file to allow including identifiers with slashes. Additionally, it adds the `sys/mman.h` header file to the `CFullIdentListenerTest.kt` file. This change enables support for including identifiers with slashes and ensures that the correct number of imports are accounted for in the test case.
phodal added a commit that referenced this issue Jan 30, 2024
- Modify the C grammar in `C.g4` to support one-line macro declarations.
- The `compilationUnit` rule now allows for multiple `oneLineMacroDeclaration` or `externalDeclaration` before the end of file.
- The `oneLineMacroDeclaration` rule has been added to handle `#include` and `#define` declarations.
- The `declaration` rule now allows for an optional `Static` keyword before the declaration specifiers.
phodal added a commit that referenced this issue Jan 31, 2024
- Modify `chapi-ast-c/src/main/antlr/C.g4` to remove unnecessary code in `singleLineMacroDeclaration`.
- Modify `chapi-ast-c/src/test/kotlin/chapi/ast/cast/CFullIdentListenerTest.kt` to remove printing of seconds in `println` statement.
- Add `recording.jsonl` to `.gitignore`.
- Update `README.md` to include information about the performance impact of using macros extensively.
- Update Kotlin implementation to include `warpTargetFullType` for accessing classes in the same package.
phodal added a commit that referenced this issue Jan 31, 2024
Fixes a bug where the nodeName for structOrUnionSpecifier was not being properly handled. The nodeName is now correctly assigned to the structOrUnionSpecifier.
phodal added a commit that referenced this issue Jan 31, 2024
Add support for macro expansion in the C grammar by introducing a new rule `macroExpandDeclaration` in the `C.g4` file. This allows for more flexible macro usage in the code.
phodal added a commit that referenced this issue Jan 31, 2024
Modify `chapi-ast-c/src/main/antlr/C.g4` to support macro in array access. Also, add a test case in `CFullIdentListenerTest.kt` to handle macro in array.
phodal added a commit that referenced this issue Jan 31, 2024
Add support for single line macro declaration in the C grammar. This allows parsing and analyzing single line macros in C code.
phodal added a commit that referenced this issue Jan 31, 2024
The macro expansion declaration in C.g4 was not correctly defined. This commit fixes the issue by updating the grammar rules.
phodal added a commit that referenced this issue Jan 31, 2024
Add support for a new macro expansion declaration in the C grammar. This allows for the definition and expansion of macros in the code.
phodal added a commit that referenced this issue Jan 31, 2024
- Modify singleLineMacroDeclaration to include Identifier as an option for include
- Modify macroKeywords to include 'ifndef' as an option

These changes ensure that singleLineMacroDeclaration and macroKeywords are more flexible and can handle different scenarios.
phodal added a commit that referenced this issue Jan 31, 2024
- Modify the syntax of singleLineMacroDeclaration in chapi-ast-c to improve readability and maintainability.
- Update the macroStatement rule to include the '#' symbol before singleLineMacroDeclaration.
- Remove unnecessary rules and comments related to macro expansion and undefining macros.
- Update the singleLineMacroDeclaration rule to remove the '#' symbol before includeDeclaration and macroCastDeclaration.
- Update the singleLineMacroDeclaration rule to remove the '#' symbol before ifdefDeclaration and defineDeclaration.
- Update the singleLineMacroDeclaration rule to remove the '#' symbol before macroExpansionDeclaration2.
- Update the singleLineMacroDeclaration rule to remove the '#' symbol before includeDeclaration and ifdefDeclaration.
phodal added a commit that referenced this issue Jan 31, 2024
This commit adds support for the `asmBody` production rule in the C grammar. The `asmBody` rule allows for the inclusion of assembly code within C code, providing more flexibility and control to developers.
phodal added a commit that referenced this issue Jan 31, 2024
Add support for macro function declaration in the C grammar. This allows defining macros with function-like syntax.
phodal added a commit that referenced this issue Jan 31, 2024
The grammar for macro declarations in the chapi-ast-c file has been simplified. The typeQualifier and pointer options have been removed from the typeKeywords and Identifier options. Additionally, a new rule for macroFunctionExpression has been added to handle macro function declarations.
phodal added a commit that referenced this issue Jan 31, 2024
This commit adds support for macro statements in the C grammar. It modifies the `C.g4` file to include the `macroStatement` rule and adds the `normalStatement` and `macroStatement` options to the `statement` rule. Additionally, it modifies the `CFullIdentListenerTest.kt` file to update the test case for the `allGrammarUnderResources` function.
phodal added a commit that referenced this issue Feb 1, 2024
This commit adds support for macro alias declaration in the chapi-ast-c file. The macroFunctionExpression rule has been modified to allow for parameterTypeList and expressionStatement.
phodal added a commit that referenced this issue Feb 1, 2024
Add support for macro statements in the chapi-ast-c module. This includes adding the `macroStatement` rule to the `C.g4` grammar file and modifying the `SlowMacro2.h` file to define some preprocessor constants.
phodal added a commit that referenced this issue Feb 1, 2024
Add support for macro postfix call in the C grammar by modifying the `compilationUnit` rule. This allows for macro calls to be recognized and parsed correctly. Also, include tests for macro calls in `CFullIdentListenerTest`.
phodal added a commit that referenced this issue Feb 1, 2024
Refactor the macro declaration in C.g4 to improve readability and maintainability. The `defineMacro` rule is now split into three separate rules: `macroAssignDeclaration`, `macroAliasDeclaration`, and `macroStructureDeclaration`. The `macroStatementDeclaration` rule now accepts `macroFunctionExpression` as an optional argument.
phodal added a commit that referenced this issue Feb 1, 2024
…ions #24

This commit modifies the grammar rules for single line macro declarations in the chapi-ast-c project. The changes include adding support for various types of macro declarations and expressions. The modifications aim to improve the parsing of macros in the code.
phodal added a commit that referenced this issue Feb 1, 2024
This commit adds support for parsing #include statements in C code. It extracts the included file name and adds it to the list of imports in the code container.
phodal added a commit that referenced this issue Feb 1, 2024
phodal added a commit that referenced this issue Feb 1, 2024
phodal added a commit that referenced this issue Feb 1, 2024
- Modified the grammar file to fix the comparison and assignment operators.
- Replaced "Equal" with "OP_EQ" for assignmentOperator and initDeclarator.
- Replaced "Equal" with "OP_EQ" for enumerator and designation.
- Replaced "Equal" with "Assign" for designation.
phodal added a commit that referenced this issue Feb 1, 2024
phodal added a commit that referenced this issue Feb 1, 2024
Refactor the `OnPreprocessorDirectiveIfdef` and `OnPreprocessorDirectiveIfndef` methods in `CPreprocessorParserBase.java` to remove unnecessary code. Also, update the `CLexer.g4` and `CPreprocessorParser.g4` files to use more descriptive names for the preprocessor directives.
phodal added a commit that referenced this issue Feb 1, 2024
Add a recommendation for a C Macro library in the README.md file. The library is called jcpp and can be found at [https://github.com/shevek/jcpp](https://github.com/shevek/jcpp). This library is useful for parsing C code that requires pre-processing.
phodal added a commit that referenced this issue Feb 1, 2024
This commit adds support for preprocessing C code using the `org.anarres.cpp` library. It introduces a new `CAnalyser` class that initializes a `Preprocessor` object and adds features and warnings. The `addSource` method is added to add source code to the program. The `analysis` method now preprocesses the code using the `Preprocessor` object and then parses the resulting output. The `CParser.g4` file is modified to include support for type keywords and pointers. The `CFullIdentListenerTest.kt` file is modified to update the test cases. The `build.gradle.kts` file is modified to include the `org.anarres:jcpp` dependency.
phodal added a commit that referenced this issue Feb 1, 2024
This commit adds the ability to add source code to the program in the chapi-ast-c module. The `addSource` method now takes a string representation of the source code and adds it to the program. This allows for the inclusion of C header files and other source code files.
phodal added a commit that referenced this issue Feb 1, 2024
This commit adds the `override` keyword to the `addSource` method in the `CAnalyser` class. This ensures that the method is properly overridden from the parent class.
phodal added a commit that referenced this issue Feb 1, 2024
This commit adds support for parsing C header files in the `Analyser` interface. The `addSource` function now accepts C header files and adds them to the program. This allows for more comprehensive analysis of C code.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant