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

CPreProcessor,C: skip #ifdef __cplusplus ~ #endif branch #2648

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

masatake
Copy link
Member

Close #2647.

C parser doesn't work when C++ code "extern "C" {" and "}" is given.

    $ cat /tmp/extern-c.c
    extern "C" {
    #ifdef X
      void f() {}
    #else
      void g() {}
    #endif
    }
    $ u-ctags --output-format=xref --kinds-c=+plz --fields=+nie -o - /tmp/extern-c.c
    f                function      3 /tmp/extern-c.c  void f() {}

    $ cat /tmp/none-extern-c.c
    #ifdef X
      void f() {}
    #else
      void g() {}
    #endif
    $ u-ctags --output-format=xref --kinds-c=+plz --fields=+nie -o - /tmp/none-extern-c.c
    f                function      2 /tmp/none-extern-c.c void f() {}
    g                function      4 /tmp/none-extern-c.c void g() {}

The function g() is missed if the code is surrounded by extern "C" { and }.

This change uses a heuristic rule to skip the code in the C parser.

In most of cases, the code is in #ifdef __cplusplus ~ #endif branch.
So when the CPreProcessor parser detects #ifdef __cplusplus ~ #endif,
with this change, the CPreProcessor parser doesn't pass the code inside __cplusplus branch
to its client parser that requests to the CPreProcessor parser to do so.

C parser requests it. C++ parser doesn't.

Signed-off-by: Masatake YAMATO <[email protected]>

…ssed to cppInit()

cppInit takes too many arguments. To make the cppInit invocation
understandable, this change introduces cppInitData struct type. With
the type, a client parser can specify an argument with specifying the
name of field.

This change fixex a bug as a side effect.
The orders of parameters didn't matched between the declaration and
the implementation of cppInit().

Signed-off-by: Masatake YAMATO <[email protected]>
Close universal-ctags#2647.

C parser doesn't work when C++ code "extern "C" {" and "}" is given.

    $ cat /tmp/extern-c.c
    extern "C" {
    #ifdef X
      void f() {}
    #else
      void g() {}
    #endif
    }
    $ u-ctags --output-format=xref --kinds-c=+plz --fields=+nie -o - /tmp/extern-c.c
    f                function      3 /tmp/extern-c.c  void f() {}

    $ cat /tmp/none-extern-c.c
    #ifdef X
      void f() {}
    #else
      void g() {}
    #endif
    $ u-ctags --output-format=xref --kinds-c=+plz --fields=+nie -o - /tmp/none-extern-c.c
    f                function      2 /tmp/none-extern-c.c void f() {}
    g                function      4 /tmp/none-extern-c.c void g() {}

The function g() is missed if the code is surrounded by extern "C" { and }.

This change uses a heuristic rule to skip the code in the C parser.

In most of cases, the code is in #ifdef __cplusplus ~ #endif branch.
So when the CPreProcessor parser detects #ifdef __cplusplus ~ #endif,
with this change, the CPreProcessor parser doesn't pass the code inside __cplusplus branch
to its client parser that requests to the CPreProcessor parser to do so.

C parser requests it. C++ parser doesn't.

Signed-off-by: Masatake YAMATO <[email protected]>
@coveralls
Copy link

Coverage Status

Coverage increased (+0.002%) to 86.965% when pulling a26c377 on masatake:cpreprocessor-skip-cplusplus-branch into 23d50b5 on universal-ctags:master.

@codecov
Copy link

codecov bot commented Sep 17, 2020

Codecov Report

Merging #2648 into master will increase coverage by 0.00%.
The diff coverage is 96.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #2648   +/-   ##
=======================================
  Coverage   86.86%   86.87%           
=======================================
  Files         183      183           
  Lines       38973    38995   +22     
=======================================
+ Hits        33855    33875   +20     
- Misses       5118     5120    +2     
Impacted Files Coverage Δ
parsers/cpreprocessor.c 92.97% <93.33%> (-0.14%) ⬇️
parsers/asm.c 98.52% <100.00%> (+0.01%) ⬆️
parsers/c.c 76.42% <100.00%> (+0.08%) ⬆️
parsers/cxx/cxx_parser.c 85.47% <100.00%> (+0.04%) ⬆️
parsers/dts.c 100.00% <100.00%> (ø)
parsers/ldscript.c 88.31% <100.00%> (+0.04%) ⬆️
parsers/protobuf.c 97.48% <100.00%> (+0.01%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 23d50b5...a26c377. Read the comment docs.

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.

C/C++: extern "c" will cause parse error
2 participants