Skip to content

Commit

Permalink
Merge pull request #1961 from masatake/cleanup-inclusions
Browse files Browse the repository at this point in the history
Defining interface for parsers (part 5 of N)
  • Loading branch information
masatake authored Dec 28, 2018
2 parents 5728abe + ec40f18 commit 18bf3a4
Show file tree
Hide file tree
Showing 44 changed files with 418 additions and 206 deletions.
1 change: 1 addition & 0 deletions main/debug.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "options.h"
#include "parse_p.h"
#include "read.h"
#include "read_p.h"

/*
* FUNCTION DEFINITIONS
Expand Down
5 changes: 3 additions & 2 deletions main/entry.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,12 @@
#include "field.h"
#include "fmt_p.h"
#include "kind.h"
#include "main.h"
#include "main_p.h"
#include "nestlevel.h"
#include "options_p.h"
#include "ptag_p.h"
#include "read.h"
#include "read_p.h"
#include "routines.h"
#include "routines_p.h"
#include "parse_p.h"
Expand All @@ -57,7 +58,7 @@
#include "subparser_p.h"
#include "trashbox.h"
#include "writer_p.h"
#include "xtag.h"
#include "xtag_p.h"

/*
* MACROS
Expand Down
10 changes: 2 additions & 8 deletions main/entry.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
#include "field.h"
#include "xtag.h"
#include "mio.h"
#include "ptrarray.h"
#include "nestlevel.h"

/*
* MACROS
Expand Down Expand Up @@ -142,12 +144,4 @@ extern bool isTagExtraBitMarked (const tagEntryInfo *const tag, xtagType extra);
extern void attachParserField (tagEntryInfo *const tag, fieldType ftype, const char* value);
extern void attachParserFieldToCorkEntry (int index, fieldType ftype, const char* value);

CTAGS_INLINE roleBitsType makeRoleBit(int roleIndex)
{
if (roleIndex == ROLE_INDEX_DEFINITION)
return 0;
else
return ((roleBitsType)1) << roleIndex;
}

#endif /* CTAGS_MAIN_ENTRY_H */
9 changes: 9 additions & 0 deletions main/entry_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,13 @@ extern void makeFileTag (const char *const fileName);

extern const tagField* getParserField (const tagEntryInfo * tag, int index);


CTAGS_INLINE roleBitsType makeRoleBit(int roleIndex)
{
if (roleIndex == ROLE_INDEX_DEFINITION)
return 0;
else
return ((roleBitsType)1) << roleIndex;
}

#endif /* CTAGS_PRIVATE_ENTRY_H */
1 change: 1 addition & 0 deletions main/field.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include "read.h"
#include "routines.h"
#include "trashbox.h"
#include "xtag_p.h"


typedef struct sFieldObject {
Expand Down
57 changes: 11 additions & 46 deletions main/kind.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,17 @@
#ifndef CTAGS_MAIN_KIND_H
#define CTAGS_MAIN_KIND_H

/*
* INCLUDE FILES
*/

#include "general.h"
#include "types.h"
#include "routines.h"
#include "vstring.h"

/*
* DATA DECLARATIONS
*/

struct sRoleDefinition {
bool enabled;
Expand All @@ -21,9 +28,6 @@ struct sRoleDefinition {
int id;
};

typedef void (* freeRoleDefFunc) (roleDefinition *);
extern const char *renderRole (const roleDefinition* const def, vString* b);

/*
* Predefined kinds
*/
Expand Down Expand Up @@ -81,49 +85,10 @@ struct sKindDefinition {
#define ATTACH_ROLES(RS) .nRoles = ARRAY_SIZE(RS), .roles = RS
#define ATTACH_SEPARATORS(S) .separators = S, .separatorCount = ARRAY_SIZE(S)

/* for the obsolete --list-kinds option */
extern void printKind (const kindDefinition* const kind, bool indent);
/*
* FUNCTION PROTOTYPES
*/

extern const char *scopeSeparatorFor (langType lang, int kindIndex, int parentKindIndex);

extern void enableKind (kindDefinition *kind, bool enable);

struct kindControlBlock;
typedef void (* freeKindDefFunc) (kindDefinition *);
extern struct kindControlBlock* allocKindControlBlock (parserDefinition *parser);
extern void freeKindControlBlock (struct kindControlBlock* kcb);
extern int defineKind (struct kindControlBlock* kcb, kindDefinition *def,
freeKindDefFunc freeKindDef);
extern int defineRole (struct kindControlBlock* kcb, int kindIndex,
roleDefinition *def, freeRoleDefFunc freeRoleDef);
extern bool isRoleEnabled (struct kindControlBlock* kcb, int kindIndex, int roleIndex);

extern unsigned int countKinds (struct kindControlBlock* kcb);
extern unsigned int countRoles (struct kindControlBlock* kcb, int kindIndex);
extern kindDefinition *getKind (struct kindControlBlock* kcb, int kindIndex);
extern kindDefinition *getKindForLetter (struct kindControlBlock* kcb, int letter);
extern kindDefinition *getKindForName (struct kindControlBlock* kcb, const char* name);
extern roleDefinition* getRole(struct kindControlBlock* kcb, int kindIndex, int roleIndex);
extern roleDefinition* getRoleForName(struct kindControlBlock* kcb, int kindIndex, const char* name);
extern void linkKindDependency (struct kindControlBlock *masterKCB,
struct kindControlBlock *slaveKCB);

/* for --list-kinds-full option. LANGUAGE must be initialized. */
extern struct colprintTable * kindColprintTableNew (void);
extern void kindColprintAddLanguageLines (struct colprintTable *table,
struct kindControlBlock* kcb);
extern void kindColprintTablePrint (struct colprintTable *table, bool noparser,
bool withListHeader, bool machinable, FILE *fp);

extern struct colprintTable * roleColprintTableNew (void);
extern void roleColprintAddRoles (struct colprintTable *table,
struct kindControlBlock* kcb,
const char *kindspecs);
extern void roleColprintTablePrint (struct colprintTable *table, bool noparser,
bool withListHeader, bool machinable, FILE *fp);

#ifdef DEBUG
extern bool doesParserUseKind (struct kindControlBlock* kcb, char letter);
#endif

#endif /* CTAGS_MAIN_KIND_H */
74 changes: 74 additions & 0 deletions main/kind_p.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/*
* Copyright (c) 1998-2003, Darren Hiebert
*
* This source code is released for free distribution under the terms of the
* GNU General Public License version 2 or (at your option) any later version.
*
*/
#ifndef CTAGS_MAIN_KIND_PRIVATE_H
#define CTAGS_MAIN_KIND_PRIVATE_H

/*
* INCLUDE FILES
*/

#include "general.h"
#include "vstring.h"


/*
* DATA DECLARATIONS
*/

struct kindControlBlock;
typedef void (* freeKindDefFunc) (kindDefinition *);
typedef void (* freeRoleDefFunc) (roleDefinition *);


/*
* FUNCTION PROTOTYPES
*/
extern void enableKind (kindDefinition *kind, bool enable);
extern const char *renderRole (const roleDefinition* const def, vString* b);

extern struct kindControlBlock* allocKindControlBlock (parserDefinition *parser);
extern void freeKindControlBlock (struct kindControlBlock* kcb);

extern int defineKind (struct kindControlBlock* kcb, kindDefinition *def,
freeKindDefFunc freeKindDef);
extern int defineRole (struct kindControlBlock* kcb, int kindIndex,
roleDefinition *def, freeRoleDefFunc freeRoleDef);
extern bool isRoleEnabled (struct kindControlBlock* kcb, int kindIndex, int roleIndex);

extern unsigned int countKinds (struct kindControlBlock* kcb);
extern unsigned int countRoles (struct kindControlBlock* kcb, int kindIndex);
extern kindDefinition *getKind (struct kindControlBlock* kcb, int kindIndex);
extern kindDefinition *getKindForLetter (struct kindControlBlock* kcb, int letter);
extern kindDefinition *getKindForName (struct kindControlBlock* kcb, const char* name);
extern roleDefinition* getRole(struct kindControlBlock* kcb, int kindIndex, int roleIndex);
extern roleDefinition* getRoleForName(struct kindControlBlock* kcb, int kindIndex, const char* name);
extern void linkKindDependency (struct kindControlBlock *masterKCB,
struct kindControlBlock *slaveKCB);

/* for the obsolete --list-kinds option */
extern void printKind (const kindDefinition* const kind, bool indent);

/* for --list-kinds-full option. LANGUAGE must be initialized. */
extern struct colprintTable * kindColprintTableNew (void);
extern void kindColprintAddLanguageLines (struct colprintTable *table,
struct kindControlBlock* kcb);
extern void kindColprintTablePrint (struct colprintTable *table, bool noparser,
bool withListHeader, bool machinable, FILE *fp);

extern struct colprintTable * roleColprintTableNew (void);
extern void roleColprintAddRoles (struct colprintTable *table,
struct kindControlBlock* kcb,
const char *kindspecs);
extern void roleColprintTablePrint (struct colprintTable *table, bool noparser,
bool withListHeader, bool machinable, FILE *fp);

#ifdef DEBUG
extern bool doesParserUseKind (struct kindControlBlock* kcb, char letter);
#endif

#endif /* CTAGS_MAIN_KIND_PRIVATE_H */
4 changes: 3 additions & 1 deletion main/lregex.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,18 @@

#include "debug.h"
#include "colprint_p.h"
#include "entry.h"
#include "entry_p.h"
#include "flags_p.h"
#include "htable.h"
#include "kind.h"
#include "options.h"
#include "parse_p.h"
#include "read.h"
#include "read_p.h"
#include "routines.h"
#include "routines_p.h"
#include "trashbox.h"
#include "xtag_p.h"

static bool regexAvailable = false;

Expand Down
1 change: 1 addition & 0 deletions main/lregex_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
* INCLUDE FILES
*/
#include "general.h"
#include "kind_p.h"
#include "lregex.h"

/*
Expand Down
1 change: 1 addition & 0 deletions main/lxpath.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "options.h"
#include "parse_p.h"
#include "read.h"
#include "read_p.h"
#include "routines.h"
#include "xtag.h"

Expand Down
15 changes: 14 additions & 1 deletion main/lxpath.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
#ifndef CTAGS_LXPATH_PARSE_H
#define CTAGS_LXPATH_PARSE_H

/*
* INCLUDE FILES
*/

#include "general.h" /* must always come first */
#include "types.h"

Expand All @@ -22,6 +26,11 @@
#define xmlXPathContext void
#endif


/*
* DATA DECLARATIONS
*/

typedef struct sTagXpathMakeTagSpec {
int kind;
int role;
Expand Down Expand Up @@ -72,10 +81,14 @@ typedef struct sXpathFileSpec {
const char *rootNSHref;
} xpathFileSpec;


/*
* FUNCTION PROTOTYPES
*/

/* Xpath interface */
extern void findXMLTags (xmlXPathContext *ctx, xmlNode *root,
const tagXpathTableTable *xpathTableTable,
const kindDefinition* const kinds, void *userData);
extern void addTagXpath (const langType language, tagXpathTable *xpathTable);

#endif /* CTAGS_LXPATH_PARSE_H */
27 changes: 27 additions & 0 deletions main/lxpath_p.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Copyright (c) 2016, Masatake YAMATO
* Copyright (c) 2016, Red Hat, Inc.
*
* This source code is released for free distribution under the terms of the
* GNU General Public License version 2 or (at your option) any later version.
*
* Xpath based parer API for the main part
*/
#ifndef CTAGS_LXPATH_PARSE_PRIVATE_H
#define CTAGS_LXPATH_PARSE_PRIVATE_H

/*
* INCLUDE FILES
*/

#include "general.h" /* must always come first */
#include "types.h"


/*
* FUNCTION PROTOTYPES
*/

extern void addTagXpath (const langType language, tagXpathTable *xpathTable);

#endif /* CTAGS_LXPATH_PARSE_PRIVATE_H */
7 changes: 4 additions & 3 deletions main/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,15 @@
#include "error_p.h"
#include "field.h"
#include "keyword_p.h"
#include "main.h"
#include "main_p.h"
#include "options_p.h"
#include "parse_p.h"
#include "read.h"
#include "read_p.h"
#include "routines_p.h"
#include "trace.h"
#include "trashbox.h"
#include "trashbox_p.h"
#include "writer_p.h"
#include "xtag_p.h"

#ifdef HAVE_JANSSON
#include "interactive_p.h"
Expand Down
10 changes: 4 additions & 6 deletions main/main.h → main/main_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,21 @@
* This source code is released for free distribution under the terms of the
* GNU General Public License version 2 or (at your option) any later version.
*
* External interface to main.c
* Main part private interface to main.c
*/
#ifndef CTAGS_MAIN_MAIN_H
#define CTAGS_MAIN_MAIN_H
#ifndef CTAGS_MAIN_MAIN_PRIVATE_H
#define CTAGS_MAIN_MAIN_PRIVATE_H

/*
* INCLUDE FILES
*/
#include "general.h" /* must always come first */

#include <stdio.h>

/*
* FUNCTION PROTOTYPES
*/
extern void addTotals (const unsigned int files, const long unsigned int lines, const long unsigned int bytes);
extern bool isDestinationStdout (void);
extern int main (int argc, char **argv);

#endif /* CTAGS_MAIN_MAIN_H */
#endif /* CTAGS_MAIN_MAIN_PRIVATE_H */
1 change: 0 additions & 1 deletion main/nestlevel.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
*/
#include "general.h" /* must always come first */

#include "main.h"
#include "debug.h"
#include "entry.h"
#include "routines.h"
Expand Down
1 change: 1 addition & 0 deletions main/nestlevel.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
/*
* DATA DECLARATIONS
*/
typedef struct NestingLevel NestingLevel;
typedef struct NestingLevels NestingLevels;

struct NestingLevel
Expand Down
Loading

0 comments on commit 18bf3a4

Please sign in to comment.