ctags icon indicating copy to clipboard operation
ctags copied to clipboard

C/C++: Handling .h file in relaxed syntax

Open masatake opened this issue 9 years ago • 5 comments

I found this case in linux kernel.

Consider a C language header having .h suffix. In C language private is not a keyword. New Cxx parser doesn't record a variable named private because the parser recognized it as C++ keyword.`` Old Cxx parser

[yamato@x201]/tmp% cat foo.h
extern int private;
static inline int f(void)
{
  return private;
}
typedef int int32;


[yamato@x201]/tmp% u-ctags -o - /tmp/foo.h 
# nothing is captured.

[yamato@x201]/tmp% u-ctags --languages=+OldC++ --language-force=OldC++ -o - /tmp/foo.h
f   /tmp/foo.h  /^static inline int f(void)$/;" f
int32   /tmp/foo.h  /^typedef int int32;$/;"    t

We can avoid this ignorance with modifying language map, however I hope u-ctags handling this situation well because this situation may be so popular.

masatake avatar May 12 '16 09:05 masatake

@pragmaware, can I ask you to look at this one?

masatake avatar May 30 '16 14:05 masatake

Done :) Waiting for checks to complete for merging.

pragmaware avatar May 31 '16 01:05 pragmaware

I found another case in real code:

[yamato@x201]~/usr/pacemaker% cat /tmp/foo.h 
typedef struct S {
  int klass;
  int class;
};
[yamato@x201]~/usr/pacemaker% u-ctags -o - /tmp/foo.h
S   /tmp/foo.h  /^typedef struct S {$/;"    s
klass   /tmp/foo.h  /^  int klass;$/;"  m   struct:S    typeref:typename:int

class is not recorded as a member.

masatake avatar Jun 17 '16 13:06 masatake

I made a crazy input. gcc accepts this.

struct C {
  int alignas;
  int alignof;
  int bool;
  int catch;
  int char16_t;
  int char32_t;
  int class;
  int concept;
  int constexpr;
  int const_cast;
  int decltype;
  int delete;
  int dynamic_cast;
  int explicit;
  int export;
  int final;
  int friend;
  int mutable;
  int namespace;
  int new;
  int noexcept;
  int nullptr;
  int operator;
  int private;
  int protected;
  int public;
  int reinterpret_cast;
  int requires;
  int static_assert;
  int static_cast;
  int template;
  int this;
  int thread_local;
  int throw;
  int try;
  int typeid;
  int typename;
  int using;
  int virutal;
};

How about adding `usedAsNameinC field in CXXKeywordDescriptor like:

typedef struct _CXXKeywordDescriptor
{
    unsigned char bValidC;
    const char * szName;
    unsigned int uFlags;
    boolean usedAsNameInC;
} CXXKeywordDescriptor;

masatake avatar Jun 17 '16 13:06 masatake

@pragmaware, I woud like to try this.

masatake avatar Jul 15 '16 01:07 masatake