Skip to content

Commit

Permalink
ObjectiveC: ignore 'extern "C" {'
Browse files Browse the repository at this point in the history
All lines surrounded by 'extern "C" {' and '}' were not parsed.
Instead of skpping the lines, this change ignores 'extern "C" {' itself.
As the result, the lines are parsed expectedly. The last '}' may be
just ignored.

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
  • Loading branch information
masatake committed May 16, 2019
1 parent ad3548a commit 2b88b85
Show file tree
Hide file tree
Showing 6 changed files with 117 additions and 3 deletions.
1 change: 1 addition & 0 deletions Tmain/option-dump-keywords.d/stdout-expected.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@
@synchronized ObjectiveC
@synthesize ObjectiveC
enum ObjectiveC
extern ObjectiveC
struct ObjectiveC
typedef ObjectiveC
1 change: 1 addition & 0 deletions Units/parser-objectivec.r/objc-extern-c.d/args.ctags
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
--sort=no
9 changes: 9 additions & 0 deletions Units/parser-objectivec.r/objc-extern-c.d/expected.tags
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
__NSCompoundPredicate_h_GNUSTEP_BASE_INCLUDE input.h /^#define __NSCompoundPredicate_h_GNUSTEP_BASE_INCLUDE$/;" M
NSCompoundPredicateType input.h /^typedef NSUInteger NSCompoundPredicateType;$/;" t
NSCompoundPredicate input.h /^@interface NSCompoundPredicate : NSPredicate$/;" i
_subs input.h /^ NSArray *_subs;$/;" E interface:NSCompoundPredicate
andPredicateWithSubpredicates: input.h /^+ (NSPredicate *) andPredicateWithSubpredicates: (NSArray *)list;$/;" c interface:NSCompoundPredicate
notPredicateWithSubpredicate: input.h /^+ (NSPredicate *) notPredicateWithSubpredicate: (NSPredicate *)predicate;$/;" c interface:NSCompoundPredicate
orPredicateWithSubpredicates: input.h /^+ (NSPredicate *) orPredicateWithSubpredicates: (NSArray *)list;$/;" c interface:NSCompoundPredicate
subpredicates input.h /^- (NSArray *) subpredicates;$/;" m interface:NSCompoundPredicate
foo input-0.m /^extern int foo (void)$/;" f
13 changes: 13 additions & 0 deletions Units/parser-objectivec.r/objc-extern-c.d/input-0.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// -*- mode: objc -*-

/* Verify code handling
*
* extern "C" { ...
*
* doesn't break the other area of objectivec parser.
*/

extern int foo (void)
{
return 0;
}
59 changes: 59 additions & 0 deletions Units/parser-objectivec.r/objc-extern-c.d/input.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/* Interface for NSCompoundPredicate for GNUStep
Copyright (C) 2005 Free Software Foundation, Inc.
Written by: Dr. H. Nikolaus Schaller
Created: 2005
This file is part of the GNUstep Base Library.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free
Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02111 USA.
*/

#ifndef __NSCompoundPredicate_h_GNUSTEP_BASE_INCLUDE
#define __NSCompoundPredicate_h_GNUSTEP_BASE_INCLUDE
#import <GNUstepBase/GSVersionMacros.h>

#if OS_API_VERSION(MAC_OS_X_VERSION_10_4, GS_API_LATEST)

#import <Foundation/NSPredicate.h>

#if defined(__cplusplus)
extern "C" {
#endif

typedef NSUInteger NSCompoundPredicateType;

@interface NSCompoundPredicate : NSPredicate
{
#if GS_EXPOSE(NSCompoundPredicate)
NSArray *_subs;
#endif
}

+ (NSPredicate *) andPredicateWithSubpredicates: (NSArray *)list;
+ (NSPredicate *) notPredicateWithSubpredicate: (NSPredicate *)predicate;
+ (NSPredicate *) orPredicateWithSubpredicates: (NSArray *)list;

- (NSArray *) subpredicates;

@end

#if defined(__cplusplus)
}
#endif

#endif /* 100400 */
#endif
37 changes: 34 additions & 3 deletions parsers/objc.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ typedef enum {
ObjcINTERFACE,
ObjcPROTOCOL,
ObjcENCODE,
ObjcEXTERN,
ObjcSYNCHRONIZED,
ObjcSELECTOR,
ObjcPROPERTY,
Expand Down Expand Up @@ -101,6 +102,7 @@ typedef enum {
Tok_ANGLEL, /* '<' */
Tok_ANGLER, /* '>' */
Tok_EOL, /* '\r''\n' */
Tok_CSTRING, /* "..." */
Tok_any,

Tok_EOF /* END of file */
Expand All @@ -112,6 +114,7 @@ static const keywordTable objcKeywordTable[] = {
{"typedef", ObjcTYPEDEF},
{"struct", ObjcSTRUCT},
{"enum", ObjcENUM},
{"extern", ObjcEXTERN},
{"@implementation", ObjcIMPLEMENTATION},
{"@interface", ObjcINTERFACE},
{"@protocol", ObjcPROTOCOL},
Expand Down Expand Up @@ -201,12 +204,14 @@ static void eatWhiteSpace (lexingState * st)
st->cp = cp;
}

static void eatString (lexingState * st)
static void readCString (lexingState * st)
{
bool lastIsBackSlash = false;
bool unfinished = true;
const unsigned char *c = st->cp + 1;

vStringClear (st->name);

while (unfinished)
{
/* end of line should never happen.
Expand All @@ -216,7 +221,10 @@ static void eatString (lexingState * st)
else if (*c == '"' && !lastIsBackSlash)
unfinished = false;
else
{
lastIsBackSlash = *c == '\\';
vStringPut (st->name, (int) *c);
}

c++;
}
Expand Down Expand Up @@ -398,8 +406,8 @@ static objcKeyword lex (lexingState * st)
st->cp++;
return Tok_dpoint;
case '"':
eatString (st);
return Tok_any;
readCString (st);
return Tok_CSTRING;
case '+':
st->cp++;
return Tok_PLUS;
Expand Down Expand Up @@ -1177,6 +1185,24 @@ static void parsePreproc (vString * const ident, objcToken what)
}
}

static void skipCurlL (vString * const ident, objcToken what)
{
if (what == Tok_CurlL)
toDoNext = comeAfter;
}

static void parseCPlusPlusCLinkage (vString * const ident, objcToken what)
{
toDoNext = comeAfter;

/* Linkage specification like "C" */
if (what == Tok_CSTRING)
toDoNext = skipCurlL;
else
/* Force handle this ident in globalScope */
globalScope (ident, what);
}

/* Handle the "strong" top levels, all 'big' declarations
* happen here */
static void globalScope (vString * const ident, objcToken what)
Expand Down Expand Up @@ -1231,6 +1257,11 @@ static void globalScope (vString * const ident, objcToken what)
ignoreBalanced (ident, what);
break;

case ObjcEXTERN:
comeAfter = &globalScope;
toDoNext = &parseCPlusPlusCLinkage;
break;

case ObjcEND:
case ObjcPUBLIC:
case ObjcPROTECTED:
Expand Down

0 comments on commit 2b88b85

Please sign in to comment.