Skip to content

Commit

Permalink
Antlr upgrade to version 4.9.2, some inline comments
Browse files Browse the repository at this point in the history
  • Loading branch information
maxirmx authored and ronaldtse committed May 4, 2022
1 parent b37a1b3 commit 2c2c8ae
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 43 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/rake.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ on:
jobs:
rake:
name: test on ruby-${{ matrix.ruby }} ${{ matrix.os }}
runs-on: ${{ matrix.os }}

runs-on: ${{ matrix.os }}
continue-on-error: ${{ matrix.experimental }}
strategy:
fail-fast: false
Expand Down
2 changes: 1 addition & 1 deletion ext/express-parser/antlr4-upstream
Submodule antlr4-upstream updated 720 files
21 changes: 0 additions & 21 deletions ext/express-parser/antlr4.patch

This file was deleted.

20 changes: 5 additions & 15 deletions ext/express-parser/express_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -265,14 +265,6 @@ class ContextProxy {
public:
ContextProxy(tree::ParseTree* orig) {
this -> orig = orig;
// if (orig != nullptr) {
// for (auto it = orig -> children.begin(); it != orig -> children.end(); it ++) {
// Object parseTree = ContextProxy::wrapParseTree(*it);
// if (parseTree != Nil) {
// children.push(parseTree);
// }
// }
// }
}

tree::ParseTree* getOriginal() {
Expand All @@ -294,6 +286,11 @@ class ContextProxy {
}

Array getChildren() {
// Note re memory management
// It looks like it is critical to 'fill' children array each time when this method is called
// When Ruby GC collects the array it also unmarks all its elements so it is not possible to reuse them
// (without custom mark function ????)
// This comment also applies to all methods returning Ruby Arrays below
Array children;
if (orig != nullptr) {
for (auto it = orig -> children.begin(); it != orig -> children.end(); it ++) {
Expand All @@ -307,11 +304,6 @@ class ContextProxy {
}

Object getParent() {
// if (parent == Nil) {
// if (orig != nullptr) {
// parent = ContextProxy::wrapParseTree(orig -> parent);
// }
// }
return orig == nullptr ? Nil: wrapParseTree(orig -> parent) ;
}

Expand All @@ -334,8 +326,6 @@ class ContextProxy {

protected:
tree::ParseTree* orig = nullptr;
// Array children;
// Object parent = Nil;
};

class TerminalNodeProxy : public ContextProxy {
Expand Down
4 changes: 1 addition & 3 deletions ext/express-parser/extconf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,10 @@
end
else
require 'mkmf-rice'

dir_config(extension_name)
end

$CPPFLAGS << " -std=c++17 -DANTLR4CPP_STATIC -DHAVE_CXX11 -g -fno-common -fno-omit-frame-pointer"
#-fsanitize=address -fsanitize-address-use-after-scope $DLDFLAGS << " -fsanitize=address"
$CPPFLAGS << " -std=c++17 -DANTLR4CPP_STATIC -DHAVE_CXX11 -fno-omit-frame-pointer"
$INCFLAGS << " -I#{__dir__}/#{antlr4_src}"
$srcs = []

Expand Down
5 changes: 4 additions & 1 deletion lib/expressir/express/parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,11 @@ class Parser
def self.from_file(file, skip_references: nil, include_source: nil)
input = File.read(file)

# An important note re memory management
# parse, syntax, visitor methods return complex tree structures created in netive (C++) extension
# visit method references nodes and leaves of this structures but it is totally untransparent for Ruby GarbageCllector
# so in this class we keep those C++ structure marked for GC so theu are not freed
@parser = ::ExpressParser::Parser.parse(input)

@parse_tree = @parser.syntax()

@visitor = Visitor.new(@parser.tokens, include_source: include_source)
Expand Down

0 comments on commit 2c2c8ae

Please sign in to comment.