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

#132 Add a CMake build for C++ port #133

Merged
merged 22 commits into from
Jul 27, 2024

Conversation

vityaman
Copy link
Contributor

@vityaman vityaman commented Jul 24, 2024

The part of issue #132.

  • Build a static library with name libantlr4-c3.a that is statically linked with libantlr4-runtime.a.
  • Test a library using GTest with GMock, Java port test for Expr.g4 was ported.
  • Get ANTLRv4 Runtime via downloading v4.13.1 distribution.
  • Get ANTLRv4 Tool via downloading from www.antlr.org.
  • Support building with sanitazers.
  • Test debugging with lldb by pressing a F5 key at VSCode, clangd for VSCode support.

Adding this library as a dependency via FetchContent or something like this is not supported, because requiring to write some config and adding some demo project to test it.

There are not all changes here. Planning to add in the nearest future at next PRs:

  • Add clang-format, clang-tidy - separate PR because will contain formatting changes
  • Support adding the library as an external dependency
  • Porting more tests from TypeScript
  • Refactoring, small fixes with regression tests

@@ -188,7 +188,7 @@ bool CodeCompletionCore::translateStackToRuleIndex(RuleWithStartTokenList const&
if (translateRulesTopDown) {
// Loop over the rule stack from lowest to highest rule level. This will prioritize a lower preferred rule
// if it is a child of a higher one that is also a preferred rule.
for (size_t i = ruleWithStartTokenList.size() - 1; i >= 0; i--) {
for (int64_t i = ruleWithStartTokenList.size() - 1; i >= 0; i--) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here was a possible bug with overflow, which can cause an infinite loop. Caught by compiler with warnings enabled :)

Comment on lines 336 to 340
return {
.sets = sets,
.combined = combined,
.isExhaustive = isExhaustive,
.combined = combined
};
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed to fix compiler warning about parameters ordering.

Copy link
Owner

@mike-lischke mike-lischke left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow, what an effort to make this work, but nice to see you have thought about every aspect!

Comment on lines 336 to 340
return {
.sets = sets,
.combined = combined,
.isExhaustive = isExhaustive,
.combined = combined
};
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not familiar with that syntax. Is that C++20? Only know that from Swift (with a different meaning).

Copy link
Contributor Author

@vityaman vityaman Jul 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I understand, it is called Aggregate Initialization and exists to simplify object creation. Something like named args for trivial autogenerated by compiler constructors.

So it lets you initialize plain structs this way:

struct Point {
  std::size_t x;
  std::size_t y;
}

Point point = {.x = 10, .y = 10};

It is since C++20.

Comment on lines 141 to 145
// FIXME: it returns empty lists as tokens are ignored, but in TS not
// EXPECT_THAT(candidates.tokens[ExprLexer::VAR],
// UnorderedElementsAre(ExprLexer::ID, ExprLexer::EQUAL));
// EXPECT_THAT(candidates.tokens[ExprLexer::LET],
// UnorderedElementsAre(ExprLexer::ID, ExprLexer::EQUAL));
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here is an interesting thing, because this port gives us an empty following token list, as that tokens were ignored.

Java port has the same behavior, that can be observed here.

But TypeScript tells us a different story.

What is a desired behavior? I propose just to document this "feature" is in the tests to begin with.

@@ -0,0 +1,24 @@
cmake_minimum_required(VERSION 3.7)
project(antlr4-c3 VERSION 0.1.0)
Copy link
Contributor Author

@vityaman vityaman Jul 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is an actual version of C++ port? I would like to keep it with zero major version for now because it is still in progress, because of some major CMake structure changes may be required.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not very fond of a zero major version for published libraries, but ok, let's start with 0.1.0.

@vityaman
Copy link
Contributor Author

This CMake project structure was inspired by the project twist and many others, that I greped in the Internet.

@vityaman
Copy link
Contributor Author

Oh, I eventually defeated that problem with an absence of GTest and CTest, checks passed at my fork.

@mike-lischke, the PR is ready for review.

@vityaman vityaman marked this pull request as ready for review July 24, 2024 14:21
@vityaman vityaman changed the title [WIP] #132 Add a CMake build for C++ port #132 Add a CMake build for C++ port Jul 24, 2024
@@ -0,0 +1 @@
# ANTLRv4 C3 C++ Port
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please add a bit more information, like required C++ and CMake versions and some instructions to build and run the tests?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@@ -0,0 +1,24 @@
cmake_minimum_required(VERSION 3.7)
project(antlr4-c3 VERSION 1.1.0)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Considering the previous version as "1.0.0", "1.1.0" means the addition of CMake build.

@mike-lischke mike-lischke merged commit b4e1941 into mike-lischke:main Jul 27, 2024
5 checks passed
@mike-lischke
Copy link
Owner

Thanks!

@vityaman vityaman deleted the 132-port-cpp-cmake branch July 31, 2024 12:56
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

Successfully merging this pull request may close these issues.

2 participants