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

Commits on Sep 17, 2020

  1. CPreProcessor: update the usage of cppInit()

    Signed-off-by: Masatake YAMATO <yamato@redhat.com>
    masatake committed Sep 17, 2020
    Configuration menu
    Copy the full SHA
    36426ae View commit details
    Browse the repository at this point in the history
  2. CPreProcessor,refactor: introduce a struct representing parameters pa…

    …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 <yamato@redhat.com>
    masatake committed Sep 17, 2020
    Configuration menu
    Copy the full SHA
    d1102ea View commit details
    Browse the repository at this point in the history
  3. CPreProcessor,C: skip #ifdef __cplusplus ~ #endif branch

    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 <yamato@redhat.com>
    masatake committed Sep 17, 2020
    Configuration menu
    Copy the full SHA
    a26c377 View commit details
    Browse the repository at this point in the history