2005-11-22 12:26:26 +00:00
|
|
|
/*
|
|
|
|
*
|
|
|
|
* Copyright (c) 1996-2001, Darren Hiebert
|
|
|
|
*
|
|
|
|
* This source code is released for free distribution under the terms of the
|
|
|
|
* GNU General Public License.
|
|
|
|
*
|
2006-08-18 19:57:02 +00:00
|
|
|
* This module contains functions for parsing and scanning C, C++, D and Java
|
2005-11-22 12:26:26 +00:00
|
|
|
* source files.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* INCLUDE FILES
|
|
|
|
*/
|
|
|
|
#include "general.h" /* must always come first */
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
#include <setjmp.h>
|
|
|
|
|
|
|
|
#include "entry.h"
|
|
|
|
#include "get.h"
|
|
|
|
#include "keyword.h"
|
|
|
|
#include "main.h"
|
2007-01-16 13:18:37 +00:00
|
|
|
#include "options.h"
|
2005-11-22 12:26:26 +00:00
|
|
|
#include "parse.h"
|
|
|
|
#include "read.h"
|
|
|
|
|
|
|
|
/*
|
|
|
|
* MACROS
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define activeToken(st) ((st)->token [(int) (st)->tokenIndex])
|
|
|
|
#define parentDecl(st) ((st)->parent == NULL ? \
|
2008-11-12 19:37:02 +00:00
|
|
|
DECL_NONE : (st)->parent->declaration)
|
2005-11-22 12:26:26 +00:00
|
|
|
#define isType(token,t) (boolean) ((token)->type == (t))
|
|
|
|
#define insideEnumBody(st) (boolean) ((st)->parent == NULL ? FALSE : \
|
2008-11-12 19:37:02 +00:00
|
|
|
((st)->parent->declaration == DECL_ENUM))
|
2005-11-22 12:26:26 +00:00
|
|
|
#define isExternCDecl(st,c) (boolean) ((c) == STRING_SYMBOL && \
|
2008-11-12 19:37:02 +00:00
|
|
|
! (st)->haveQualifyingName && \
|
|
|
|
(st)->scope == SCOPE_EXTERN)
|
2005-11-22 12:26:26 +00:00
|
|
|
|
|
|
|
#define isOneOf(c,s) (boolean) (strchr ((s), (c)) != NULL)
|
|
|
|
|
|
|
|
/*
|
|
|
|
* DATA DECLARATIONS
|
|
|
|
*/
|
|
|
|
|
2007-10-17 11:55:59 +00:00
|
|
|
enum { NumTokens = 12 };
|
2005-11-22 12:26:26 +00:00
|
|
|
|
2008-11-12 19:37:02 +00:00
|
|
|
typedef enum eException
|
|
|
|
{
|
|
|
|
ExceptionNone, ExceptionEOF, ExceptionFormattingError,
|
|
|
|
ExceptionBraceFormattingError
|
2005-11-22 12:26:26 +00:00
|
|
|
} exception_t;
|
|
|
|
|
|
|
|
/* Used to specify type of keyword.
|
|
|
|
*/
|
2008-11-12 19:37:02 +00:00
|
|
|
typedef enum eKeywordId
|
|
|
|
{
|
2008-03-05 18:18:19 +00:00
|
|
|
KEYWORD_NONE = -1,
|
2009-11-06 13:03:28 +00:00
|
|
|
KEYWORD_ATTRIBUTE, KEYWORD_ABSTRACT, KEYWORD_ALIAS,
|
2007-06-22 17:22:07 +00:00
|
|
|
KEYWORD_BOOLEAN, KEYWORD_BYTE, KEYWORD_BAD_STATE, KEYWORD_BAD_TRANS,
|
2009-11-06 13:03:28 +00:00
|
|
|
KEYWORD_BIND, KEYWORD_BIND_VAR, KEYWORD_BIT, KEYWORD_BODY,
|
2007-06-22 17:22:07 +00:00
|
|
|
KEYWORD_CASE, KEYWORD_CATCH, KEYWORD_CHAR, KEYWORD_CLASS, KEYWORD_CONST,
|
|
|
|
KEYWORD_CONSTRAINT, KEYWORD_COVERAGE_BLOCK, KEYWORD_COVERAGE_DEF,
|
|
|
|
KEYWORD_DEFAULT, KEYWORD_DELEGATE, KEYWORD_DELETE, KEYWORD_DO,
|
|
|
|
KEYWORD_DOUBLE,
|
|
|
|
KEYWORD_ELSE, KEYWORD_ENUM, KEYWORD_EXPLICIT, KEYWORD_EXTERN,
|
|
|
|
KEYWORD_EXTENDS, KEYWORD_EVENT,
|
2008-11-11 16:33:20 +00:00
|
|
|
KEYWORD_FINAL, KEYWORD_FINALLY, KEYWORD_FLOAT, KEYWORD_FOR, KEYWORD_FRIEND, KEYWORD_FUNCTION,
|
|
|
|
KEYWORD_GET, KEYWORD_GOTO,
|
2009-11-06 13:03:28 +00:00
|
|
|
KEYWORD_IF, KEYWORD_IMPLEMENTS, KEYWORD_IMPORT, KEYWORD_IN, KEYWORD_INLINE, KEYWORD_INT,
|
2007-06-22 17:22:07 +00:00
|
|
|
KEYWORD_INOUT, KEYWORD_INPUT, KEYWORD_INTEGER, KEYWORD_INTERFACE,
|
|
|
|
KEYWORD_INTERNAL,
|
|
|
|
KEYWORD_LOCAL, KEYWORD_LONG,
|
|
|
|
KEYWORD_M_BAD_STATE, KEYWORD_M_BAD_TRANS, KEYWORD_M_STATE, KEYWORD_M_TRANS,
|
|
|
|
KEYWORD_MODULE, KEYWORD_MUTABLE,
|
|
|
|
KEYWORD_NAMESPACE, KEYWORD_NEW, KEYWORD_NEWCOV, KEYWORD_NATIVE,
|
2008-12-09 19:00:45 +00:00
|
|
|
KEYWORD_OPERATOR, KEYWORD_OUT, KEYWORD_OUTPUT, KEYWORD_OVERLOAD, KEYWORD_OVERRIDE,
|
2007-06-22 17:22:07 +00:00
|
|
|
KEYWORD_PACKED, KEYWORD_PORT, KEYWORD_PACKAGE, KEYWORD_PRIVATE,
|
|
|
|
KEYWORD_PROGRAM, KEYWORD_PROTECTED, KEYWORD_PUBLIC,
|
2008-12-09 19:00:45 +00:00
|
|
|
KEYWORD_REF, KEYWORD_REGISTER, KEYWORD_RETURN,
|
2007-06-22 17:22:07 +00:00
|
|
|
KEYWORD_SHADOW, KEYWORD_STATE,
|
2008-11-11 16:33:20 +00:00
|
|
|
KEYWORD_SET, KEYWORD_SHORT, KEYWORD_SIGNAL, KEYWORD_SIGNED, KEYWORD_SIZE_T, KEYWORD_STATIC, KEYWORD_STRING,
|
2007-06-22 17:22:07 +00:00
|
|
|
KEYWORD_STRUCT, KEYWORD_SWITCH, KEYWORD_SYNCHRONIZED,
|
|
|
|
KEYWORD_TASK, KEYWORD_TEMPLATE, KEYWORD_THIS, KEYWORD_THROW,
|
|
|
|
KEYWORD_THROWS, KEYWORD_TRANSIENT, KEYWORD_TRANS, KEYWORD_TRANSITION,
|
|
|
|
KEYWORD_TRY, KEYWORD_TYPEDEF, KEYWORD_TYPENAME,
|
|
|
|
KEYWORD_UINT, KEYWORD_ULONG, KEYWORD_UNION, KEYWORD_UNSIGNED, KEYWORD_USHORT,
|
|
|
|
KEYWORD_USING,
|
|
|
|
KEYWORD_VIRTUAL, KEYWORD_VOID, KEYWORD_VOLATILE,
|
2008-12-09 19:00:45 +00:00
|
|
|
KEYWORD_WCHAR_T, KEYWORD_WEAK, KEYWORD_WHILE
|
2005-11-22 12:26:26 +00:00
|
|
|
} keywordId;
|
|
|
|
|
|
|
|
/* Used to determine whether keyword is valid for the current language and
|
|
|
|
* what its ID is.
|
|
|
|
*/
|
2008-11-12 19:37:02 +00:00
|
|
|
typedef struct sKeywordDesc
|
|
|
|
{
|
2007-06-22 17:22:07 +00:00
|
|
|
const char *name;
|
|
|
|
keywordId id;
|
2008-11-11 17:42:54 +00:00
|
|
|
short isValid [7]; /* indicates languages for which kw is valid */
|
2005-11-22 12:26:26 +00:00
|
|
|
} keywordDesc;
|
|
|
|
|
|
|
|
/* Used for reporting the type of object parsed by nextToken ().
|
|
|
|
*/
|
2008-11-12 19:37:02 +00:00
|
|
|
typedef enum eTokenType
|
|
|
|
{
|
|
|
|
TOKEN_NONE, /* none */
|
|
|
|
TOKEN_ARGS, /* a parenthetical pair and its contents */
|
|
|
|
TOKEN_BRACE_CLOSE,
|
|
|
|
TOKEN_BRACE_OPEN,
|
|
|
|
TOKEN_COMMA, /* the comma character */
|
|
|
|
TOKEN_DOUBLE_COLON, /* double colon indicates nested-name-specifier */
|
|
|
|
TOKEN_KEYWORD,
|
|
|
|
TOKEN_NAME, /* an unknown name */
|
|
|
|
TOKEN_PACKAGE, /* a Java package name */
|
|
|
|
TOKEN_PAREN_NAME, /* a single name in parentheses */
|
|
|
|
TOKEN_SEMICOLON, /* the semicolon character */
|
|
|
|
TOKEN_SPEC, /* a storage class specifier, qualifier, type, etc. */
|
|
|
|
TOKEN_STAR, /* pointer detection */
|
|
|
|
TOKEN_ARRAY, /* array detection */
|
|
|
|
TOKEN_COUNT
|
2005-11-22 12:26:26 +00:00
|
|
|
} tokenType;
|
|
|
|
|
|
|
|
/* This describes the scoping of the current statement.
|
|
|
|
*/
|
2008-11-12 19:37:02 +00:00
|
|
|
typedef enum eTagScope
|
|
|
|
{
|
|
|
|
SCOPE_GLOBAL, /* no storage class specified */
|
|
|
|
SCOPE_STATIC, /* static storage class */
|
|
|
|
SCOPE_EXTERN, /* external storage class */
|
|
|
|
SCOPE_FRIEND, /* declares access only */
|
|
|
|
SCOPE_TYPEDEF, /* scoping depends upon context */
|
|
|
|
SCOPE_COUNT
|
2005-11-22 12:26:26 +00:00
|
|
|
} tagScope;
|
|
|
|
|
2008-11-12 19:37:02 +00:00
|
|
|
typedef enum eDeclaration
|
|
|
|
{
|
|
|
|
DECL_NONE,
|
|
|
|
DECL_BASE, /* base type (default) */
|
|
|
|
DECL_CLASS,
|
|
|
|
DECL_ENUM,
|
2007-06-22 17:22:07 +00:00
|
|
|
DECL_EVENT,
|
2008-11-11 16:33:20 +00:00
|
|
|
DECL_SIGNAL,
|
2008-11-12 19:37:02 +00:00
|
|
|
DECL_FUNCTION,
|
|
|
|
DECL_IGNORE, /* non-taggable "declaration" */
|
|
|
|
DECL_INTERFACE,
|
|
|
|
DECL_MODULE,
|
|
|
|
DECL_NAMESPACE,
|
|
|
|
DECL_NOMANGLE, /* C++ name demangling block */
|
|
|
|
DECL_PACKAGE,
|
|
|
|
DECL_STRUCT,
|
|
|
|
DECL_UNION,
|
|
|
|
DECL_COUNT
|
2005-11-22 12:26:26 +00:00
|
|
|
} declType;
|
|
|
|
|
2008-11-12 19:37:02 +00:00
|
|
|
typedef enum eVisibilityType
|
|
|
|
{
|
|
|
|
ACCESS_UNDEFINED,
|
|
|
|
ACCESS_PRIVATE,
|
|
|
|
ACCESS_PROTECTED,
|
|
|
|
ACCESS_PUBLIC,
|
|
|
|
ACCESS_DEFAULT, /* Java-specific */
|
|
|
|
ACCESS_COUNT
|
2005-11-22 12:26:26 +00:00
|
|
|
} accessType;
|
|
|
|
|
|
|
|
/* Information about the parent class of a member (if any).
|
|
|
|
*/
|
2008-11-12 19:37:02 +00:00
|
|
|
typedef struct sMemberInfo
|
|
|
|
{
|
|
|
|
accessType access; /* access of current statement */
|
|
|
|
accessType accessDefault; /* access default for current statement */
|
2005-11-22 12:26:26 +00:00
|
|
|
} memberInfo;
|
|
|
|
|
2008-11-12 19:37:02 +00:00
|
|
|
typedef struct sTokenInfo
|
|
|
|
{
|
|
|
|
tokenType type;
|
|
|
|
keywordId keyword;
|
|
|
|
vString* name; /* the name of the token */
|
|
|
|
unsigned long lineNumber; /* line number of tag */
|
|
|
|
fpos_t filePosition; /* file position of line containing name */
|
|
|
|
int bufferPosition; /* buffer position of line containing name */
|
2005-11-22 12:26:26 +00:00
|
|
|
} tokenInfo;
|
|
|
|
|
2008-11-12 19:37:02 +00:00
|
|
|
typedef enum eImplementation
|
|
|
|
{
|
|
|
|
IMP_DEFAULT,
|
|
|
|
IMP_ABSTRACT,
|
|
|
|
IMP_VIRTUAL,
|
|
|
|
IMP_PURE_VIRTUAL,
|
|
|
|
IMP_COUNT
|
2005-11-22 12:26:26 +00:00
|
|
|
} impType;
|
|
|
|
|
|
|
|
/* Describes the statement currently undergoing analysis.
|
|
|
|
*/
|
2008-11-12 19:37:02 +00:00
|
|
|
typedef struct sStatementInfo
|
|
|
|
{
|
|
|
|
tagScope scope;
|
|
|
|
declType declaration; /* specifier associated with TOKEN_SPEC */
|
|
|
|
boolean gotName; /* was a name parsed yet? */
|
|
|
|
boolean haveQualifyingName; /* do we have a name we are considering? */
|
|
|
|
boolean gotParenName; /* was a name inside parentheses parsed yet? */
|
|
|
|
boolean gotArgs; /* was a list of parameters parsed yet? */
|
|
|
|
impType implementation; /* abstract or concrete implementation? */
|
|
|
|
unsigned int tokenIndex; /* currently active token */
|
|
|
|
tokenInfo* token [((int) NumTokens)];
|
|
|
|
tokenInfo* context; /* accumulated scope of current statement */
|
|
|
|
tokenInfo* blockName; /* name of current block */
|
|
|
|
memberInfo member; /* information regarding parent class/struct */
|
|
|
|
vString* parentClasses; /* parent classes */
|
|
|
|
struct sStatementInfo *parent; /* statement we are nested within */
|
|
|
|
long argEndPosition; /* Position where argument list ended */
|
|
|
|
tokenInfo* firstToken; /* First token in the statement */
|
2005-11-22 12:26:26 +00:00
|
|
|
} statementInfo;
|
|
|
|
|
|
|
|
/* Describes the type of tag being generated.
|
|
|
|
*/
|
2008-11-12 19:37:02 +00:00
|
|
|
typedef enum eTagType
|
|
|
|
{
|
|
|
|
TAG_UNDEFINED,
|
|
|
|
TAG_CLASS, /* class name */
|
|
|
|
TAG_ENUM, /* enumeration name */
|
|
|
|
TAG_ENUMERATOR, /* enumerator (enumeration value) */
|
|
|
|
TAG_FIELD, /* field (Java) */
|
|
|
|
TAG_FUNCTION, /* function definition */
|
|
|
|
TAG_INTERFACE, /* interface declaration */
|
|
|
|
TAG_MEMBER, /* structure, class or interface member */
|
|
|
|
TAG_METHOD, /* method declaration */
|
|
|
|
TAG_NAMESPACE, /* namespace name */
|
|
|
|
TAG_PACKAGE, /* package name */
|
|
|
|
TAG_PROTOTYPE, /* function prototype or declaration */
|
|
|
|
TAG_STRUCT, /* structure name */
|
|
|
|
TAG_TYPEDEF, /* typedef name */
|
|
|
|
TAG_UNION, /* union name */
|
|
|
|
TAG_VARIABLE, /* variable definition */
|
|
|
|
TAG_EXTERN_VAR, /* external variable declaration */
|
2005-11-22 12:26:26 +00:00
|
|
|
TAG_MACRO, /* #define s */
|
2008-11-12 19:37:02 +00:00
|
|
|
TAG_EVENT, /* event */
|
|
|
|
TAG_SIGNAL, /* signal */
|
|
|
|
TAG_LOCAL, /* local variable definition */
|
|
|
|
TAG_PROPERTY, /* property name */
|
|
|
|
TAG_COUNT /* must be last */
|
2005-11-22 12:26:26 +00:00
|
|
|
} tagType;
|
|
|
|
|
2008-11-12 19:37:02 +00:00
|
|
|
typedef struct sParenInfo
|
|
|
|
{
|
|
|
|
boolean isParamList;
|
|
|
|
boolean isKnrParamList;
|
|
|
|
boolean isNameCandidate;
|
|
|
|
boolean invalidContents;
|
|
|
|
boolean nestedArgs;
|
|
|
|
unsigned int parameterCount;
|
2005-11-22 12:26:26 +00:00
|
|
|
} parenInfo;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* DATA DEFINITIONS
|
|
|
|
*/
|
|
|
|
|
|
|
|
static jmp_buf Exception;
|
|
|
|
|
|
|
|
static langType Lang_c;
|
|
|
|
static langType Lang_cpp;
|
2007-06-22 17:22:07 +00:00
|
|
|
static langType Lang_csharp;
|
2005-11-22 12:26:26 +00:00
|
|
|
static langType Lang_java;
|
2006-08-18 19:57:02 +00:00
|
|
|
static langType Lang_d;
|
2008-08-27 12:44:54 +00:00
|
|
|
static langType Lang_glsl;
|
2006-08-27 17:39:34 +00:00
|
|
|
static langType Lang_ferite;
|
2008-11-11 16:33:20 +00:00
|
|
|
static langType Lang_vala;
|
2005-11-22 12:26:26 +00:00
|
|
|
|
|
|
|
/* Used to index into the CKinds table. */
|
2008-11-12 19:37:02 +00:00
|
|
|
typedef enum
|
|
|
|
{
|
|
|
|
CK_UNDEFINED = -1,
|
|
|
|
CK_CLASS, CK_DEFINE, CK_ENUMERATOR, CK_FUNCTION,
|
2009-11-06 17:14:00 +00:00
|
|
|
CK_ENUMERATION, CK_INTERFACE, CK_MEMBER, CK_NAMESPACE, CK_PROTOTYPE,
|
2008-11-12 19:37:02 +00:00
|
|
|
CK_STRUCT, CK_TYPEDEF, CK_UNION, CK_VARIABLE,
|
|
|
|
CK_EXTERN_VARIABLE
|
2005-11-22 12:26:26 +00:00
|
|
|
} cKind;
|
|
|
|
|
|
|
|
static kindOption CKinds [] = {
|
2008-11-12 19:37:02 +00:00
|
|
|
{ TRUE, 'c', "class", "classes"},
|
|
|
|
{ TRUE, 'd', "macro", "macro definitions"},
|
|
|
|
{ TRUE, 'e', "enumerator", "enumerators (values inside an enumeration)"},
|
|
|
|
{ TRUE, 'f', "function", "function definitions"},
|
|
|
|
{ TRUE, 'g', "enum", "enumeration names"},
|
2009-11-06 17:14:00 +00:00
|
|
|
{ TRUE, 'i', "interface", "interfaces"}, /* for D */
|
2008-11-12 19:37:02 +00:00
|
|
|
{ TRUE, 'm', "member", "class, struct, and union members"},
|
|
|
|
{ TRUE, 'n', "namespace", "namespaces"},
|
|
|
|
{ FALSE, 'p', "prototype", "function prototypes"},
|
|
|
|
{ TRUE, 's', "struct", "structure names"},
|
|
|
|
{ TRUE, 't', "typedef", "typedefs"},
|
|
|
|
{ TRUE, 'u', "union", "union names"},
|
|
|
|
{ TRUE, 'v', "variable", "variable definitions"},
|
|
|
|
{ FALSE, 'x', "externvar", "external variable declarations"},
|
2005-11-22 12:26:26 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Used to index into the JavaKinds table. */
|
2008-11-12 19:37:02 +00:00
|
|
|
typedef enum
|
|
|
|
{
|
|
|
|
JK_UNDEFINED = -1,
|
|
|
|
JK_CLASS, JK_FIELD, JK_INTERFACE, JK_METHOD,
|
|
|
|
JK_PACKAGE, JK_ACCESS, JK_CLASS_PREFIX
|
2005-11-22 12:26:26 +00:00
|
|
|
} javaKind;
|
|
|
|
|
|
|
|
static kindOption JavaKinds [] = {
|
2008-11-12 19:37:02 +00:00
|
|
|
{ TRUE, 'c', "class", "classes"},
|
|
|
|
{ TRUE, 'f', "field", "fields"},
|
|
|
|
{ TRUE, 'i', "interface", "interfaces"},
|
|
|
|
{ TRUE, 'm', "method", "methods"},
|
|
|
|
{ TRUE, 'p', "package", "packages"},
|
2005-11-22 12:26:26 +00:00
|
|
|
};
|
|
|
|
|
2008-11-12 19:37:02 +00:00
|
|
|
typedef enum
|
|
|
|
{
|
2007-06-22 17:22:07 +00:00
|
|
|
CSK_UNDEFINED = -1,
|
|
|
|
CSK_CLASS, CSK_DEFINE, CSK_ENUMERATOR, CSK_EVENT, CSK_FIELD,
|
|
|
|
CSK_ENUMERATION, CSK_INTERFACE, CSK_LOCAL, CSK_METHOD,
|
|
|
|
CSK_NAMESPACE, CSK_PROPERTY, CSK_STRUCT, CSK_TYPEDEF
|
|
|
|
} csharpKind;
|
|
|
|
|
|
|
|
static kindOption CsharpKinds [] = {
|
|
|
|
{ TRUE, 'c', "class", "classes"},
|
|
|
|
{ TRUE, 'd', "macro", "macro definitions"},
|
|
|
|
{ TRUE, 'e', "enumerator", "enumerators (values inside an enumeration)"},
|
|
|
|
{ TRUE, 'E', "event", "events"},
|
|
|
|
{ TRUE, 'f', "field", "fields"},
|
|
|
|
{ TRUE, 'g', "enum", "enumeration names"},
|
|
|
|
{ TRUE, 'i', "interface", "interfaces"},
|
|
|
|
{ FALSE, 'l', "local", "local variables"},
|
|
|
|
{ TRUE, 'm', "method", "methods"},
|
|
|
|
{ TRUE, 'n', "namespace", "namespaces"},
|
|
|
|
{ TRUE, 'p', "property", "properties"},
|
|
|
|
{ TRUE, 's', "struct", "structure names"},
|
|
|
|
{ TRUE, 't', "typedef", "typedefs"},
|
|
|
|
};
|
|
|
|
|
2008-11-11 16:33:20 +00:00
|
|
|
typedef enum {
|
|
|
|
VK_UNDEFINED = -1,
|
|
|
|
VK_CLASS, VK_DEFINE, VK_ENUMERATOR, VK_FIELD,
|
|
|
|
VK_ENUMERATION, VK_INTERFACE, VK_LOCAL, VK_METHOD,
|
|
|
|
VK_NAMESPACE, VK_PROPERTY, VK_SIGNAL, VK_STRUCT
|
|
|
|
} valaKind;
|
|
|
|
|
|
|
|
static kindOption ValaKinds [] = {
|
|
|
|
{ TRUE, 'c', "class", "classes"},
|
|
|
|
{ TRUE, 'd', "macro", "macro definitions"},
|
|
|
|
{ TRUE, 'e', "enumerator", "enumerators (values inside an enumeration)"},
|
|
|
|
{ TRUE, 'f', "field", "fields"},
|
|
|
|
{ TRUE, 'g', "enum", "enumeration names"},
|
|
|
|
{ TRUE, 'i', "interface", "interfaces"},
|
|
|
|
{ FALSE, 'l', "local", "local variables"},
|
|
|
|
{ TRUE, 'm', "method", "methods"},
|
|
|
|
{ TRUE, 'n', "namespace", "namespaces"},
|
|
|
|
{ TRUE, 'p', "property", "properties"},
|
|
|
|
{ TRUE, 'S', "signal", "signals"},
|
|
|
|
{ TRUE, 's', "struct", "structure names"},
|
|
|
|
};
|
|
|
|
|
2005-11-22 12:26:26 +00:00
|
|
|
static const keywordDesc KeywordTable [] = {
|
2008-11-11 17:42:54 +00:00
|
|
|
/* C++ */
|
|
|
|
/* ANSI C | C# Java */
|
|
|
|
/* | | | | Vera */
|
|
|
|
/* | | | | | Vala */
|
|
|
|
/* | | | | | | D */
|
|
|
|
/* keyword keyword ID | | | | | | | */
|
|
|
|
{ "__attribute__", KEYWORD_ATTRIBUTE, { 1, 1, 1, 0, 0, 0, 1 } },
|
|
|
|
{ "abstract", KEYWORD_ABSTRACT, { 0, 0, 1, 1, 0, 1, 1 } },
|
2009-11-06 13:03:28 +00:00
|
|
|
{ "alias", KEYWORD_TYPEDEF, { 0, 0, 0, 0, 0, 0, 1 } }, /* handle like typedef */
|
2008-11-11 17:42:54 +00:00
|
|
|
{ "bad_state", KEYWORD_BAD_STATE, { 0, 0, 0, 0, 1, 0, 0 } },
|
|
|
|
{ "bad_trans", KEYWORD_BAD_TRANS, { 0, 0, 0, 0, 1, 0, 0 } },
|
|
|
|
{ "bind", KEYWORD_BIND, { 0, 0, 0, 0, 1, 0, 0 } },
|
|
|
|
{ "bind_var", KEYWORD_BIND_VAR, { 0, 0, 0, 0, 1, 0, 0 } },
|
|
|
|
{ "bit", KEYWORD_BIT, { 0, 0, 0, 0, 1, 0, 0 } },
|
2009-11-06 13:03:28 +00:00
|
|
|
{ "body", KEYWORD_BODY, { 0, 0, 0, 0, 0, 0, 1 } },
|
2008-11-11 17:42:54 +00:00
|
|
|
{ "boolean", KEYWORD_BOOLEAN, { 0, 0, 0, 1, 0, 0, 0 } },
|
2009-11-06 13:03:28 +00:00
|
|
|
{ "byte", KEYWORD_BYTE, { 0, 0, 0, 1, 0, 0, 1 } },
|
2008-11-11 17:42:54 +00:00
|
|
|
{ "case", KEYWORD_CASE, { 1, 1, 1, 1, 0, 1, 1 } },
|
|
|
|
{ "catch", KEYWORD_CATCH, { 0, 1, 1, 0, 0, 1, 1 } },
|
|
|
|
{ "char", KEYWORD_CHAR, { 1, 1, 1, 1, 0, 1, 1 } },
|
|
|
|
{ "class", KEYWORD_CLASS, { 0, 1, 1, 1, 1, 1, 1 } },
|
|
|
|
{ "const", KEYWORD_CONST, { 1, 1, 1, 1, 0, 1, 1 } },
|
|
|
|
{ "constraint", KEYWORD_CONSTRAINT, { 0, 0, 0, 0, 1, 0, 0 } },
|
|
|
|
{ "coverage_block", KEYWORD_COVERAGE_BLOCK, { 0, 0, 0, 0, 1, 0, 0 } },
|
|
|
|
{ "coverage_def", KEYWORD_COVERAGE_DEF, { 0, 0, 0, 0, 1, 0, 0 } },
|
|
|
|
{ "do", KEYWORD_DO, { 1, 1, 1, 1, 0, 1, 1 } },
|
|
|
|
{ "default", KEYWORD_DEFAULT, { 1, 1, 1, 1, 0, 1, 1 } },
|
|
|
|
{ "delegate", KEYWORD_DELEGATE, { 0, 0, 1, 0, 0, 1, 1 } },
|
|
|
|
{ "delete", KEYWORD_DELETE, { 0, 1, 0, 0, 0, 1, 1 } },
|
|
|
|
{ "double", KEYWORD_DOUBLE, { 1, 1, 1, 1, 0, 1, 1 } },
|
|
|
|
{ "else", KEYWORD_ELSE, { 1, 1, 0, 1, 0, 1, 1 } },
|
|
|
|
{ "enum", KEYWORD_ENUM, { 1, 1, 1, 1, 1, 1, 1 } },
|
|
|
|
{ "errordomain", KEYWORD_ENUM, { 0, 0, 0, 0, 0, 1, 0 } }, /* errordomain behaves like enum */
|
|
|
|
{ "event", KEYWORD_EVENT, { 0, 0, 1, 0, 1, 0, 0 } },
|
|
|
|
{ "explicit", KEYWORD_EXPLICIT, { 0, 1, 1, 0, 0, 0, 1 } },
|
|
|
|
{ "extends", KEYWORD_EXTENDS, { 0, 0, 0, 1, 1, 0, 0 } },
|
2009-11-06 17:24:31 +00:00
|
|
|
{ "extern", KEYWORD_EXTERN, { 1, 1, 1, 0, 1, 1, 0 } },
|
|
|
|
{ "extern", KEYWORD_NAMESPACE, { 0, 0, 0, 0, 0, 0, 1 } }, /* hack to ignore extern */
|
2009-11-06 13:03:28 +00:00
|
|
|
{ "final", KEYWORD_FINAL, { 0, 0, 0, 1, 0, 0, 1 } },
|
|
|
|
{ "finally", KEYWORD_FINALLY, { 0, 0, 0, 0, 0, 1, 1 } },
|
2008-11-11 17:42:54 +00:00
|
|
|
{ "float", KEYWORD_FLOAT, { 1, 1, 1, 1, 0, 1, 1 } },
|
|
|
|
{ "for", KEYWORD_FOR, { 1, 1, 1, 1, 0, 1, 1 } },
|
|
|
|
{ "friend", KEYWORD_FRIEND, { 0, 1, 0, 0, 0, 0, 0 } },
|
2009-11-06 13:03:28 +00:00
|
|
|
{ "function", KEYWORD_FUNCTION, { 0, 0, 0, 0, 1, 0, 1 } },
|
2008-11-11 17:42:54 +00:00
|
|
|
{ "get", KEYWORD_GET, { 0, 0, 0, 0, 0, 1, 0 } },
|
|
|
|
{ "goto", KEYWORD_GOTO, { 1, 1, 1, 1, 0, 1, 1 } },
|
|
|
|
{ "if", KEYWORD_IF, { 1, 1, 1, 1, 0, 1, 1 } },
|
|
|
|
{ "implements", KEYWORD_IMPLEMENTS, { 0, 0, 0, 1, 0, 0, 0 } },
|
|
|
|
{ "import", KEYWORD_IMPORT, { 0, 0, 0, 1, 0, 0, 1 } },
|
|
|
|
{ "inline", KEYWORD_INLINE, { 0, 1, 0, 0, 0, 1, 0 } },
|
2009-11-06 13:03:28 +00:00
|
|
|
{ "in", KEYWORD_IN, { 0, 0, 0, 0, 0, 0, 1 } },
|
2008-11-11 17:42:54 +00:00
|
|
|
{ "inout", KEYWORD_INOUT, { 0, 0, 0, 0, 1, 0, 1 } },
|
|
|
|
{ "input", KEYWORD_INPUT, { 0, 0, 0, 0, 1, 0, 0 } },
|
|
|
|
{ "int", KEYWORD_INT, { 1, 1, 1, 1, 0, 1, 1 } },
|
|
|
|
{ "integer", KEYWORD_INTEGER, { 0, 0, 0, 0, 1, 0, 0 } },
|
|
|
|
{ "interface", KEYWORD_INTERFACE, { 0, 0, 1, 1, 1, 1, 1 } },
|
|
|
|
{ "internal", KEYWORD_INTERNAL, { 0, 0, 1, 0, 0, 0, 0 } },
|
|
|
|
{ "local", KEYWORD_LOCAL, { 0, 0, 0, 0, 1, 0, 0 } },
|
|
|
|
{ "long", KEYWORD_LONG, { 1, 1, 1, 1, 0, 1, 1 } },
|
|
|
|
{ "m_bad_state", KEYWORD_M_BAD_STATE, { 0, 0, 0, 0, 1, 0, 0 } },
|
|
|
|
{ "m_bad_trans", KEYWORD_M_BAD_TRANS, { 0, 0, 0, 0, 1, 0, 0 } },
|
|
|
|
{ "m_state", KEYWORD_M_STATE, { 0, 0, 0, 0, 1, 0, 0 } },
|
|
|
|
{ "m_trans", KEYWORD_M_TRANS, { 0, 0, 0, 0, 1, 0, 0 } },
|
|
|
|
{ "mutable", KEYWORD_MUTABLE, { 0, 1, 0, 0, 0, 0, 0 } },
|
|
|
|
{ "module", KEYWORD_MODULE, { 0, 0, 0, 0, 0, 0, 1 } },
|
|
|
|
{ "namespace", KEYWORD_NAMESPACE, { 0, 1, 1, 0, 0, 1, 1 } },
|
|
|
|
{ "native", KEYWORD_NATIVE, { 0, 0, 0, 1, 0, 0, 0 } },
|
|
|
|
{ "new", KEYWORD_NEW, { 0, 1, 1, 1, 0, 1, 1 } },
|
|
|
|
{ "newcov", KEYWORD_NEWCOV, { 0, 0, 0, 0, 1, 0, 0 } },
|
|
|
|
{ "operator", KEYWORD_OPERATOR, { 0, 1, 1, 0, 0, 0, 0 } },
|
2009-11-06 13:03:28 +00:00
|
|
|
{ "out", KEYWORD_OUT, { 0, 0, 0, 0, 0, 1, 1 } },
|
2008-11-11 17:42:54 +00:00
|
|
|
{ "output", KEYWORD_OUTPUT, { 0, 0, 0, 0, 1, 0, 0 } },
|
|
|
|
{ "overload", KEYWORD_OVERLOAD, { 0, 1, 0, 0, 0, 0, 0 } },
|
|
|
|
{ "override", KEYWORD_OVERRIDE, { 0, 0, 1, 0, 0, 1, 1 } },
|
|
|
|
{ "package", KEYWORD_PACKAGE, { 0, 0, 0, 1, 0, 0, 1 } },
|
|
|
|
{ "packed", KEYWORD_PACKED, { 0, 0, 0, 0, 1, 0, 0 } },
|
|
|
|
{ "port", KEYWORD_PORT, { 0, 0, 0, 0, 1, 0, 0 } },
|
|
|
|
{ "private", KEYWORD_PRIVATE, { 0, 1, 1, 1, 0, 1, 1 } },
|
|
|
|
{ "program", KEYWORD_PROGRAM, { 0, 0, 0, 0, 1, 0, 0 } },
|
|
|
|
{ "protected", KEYWORD_PROTECTED, { 0, 1, 1, 1, 1, 1, 1 } },
|
|
|
|
{ "public", KEYWORD_PUBLIC, { 0, 1, 1, 1, 1, 1, 1 } },
|
2009-11-06 13:03:28 +00:00
|
|
|
{ "ref", KEYWORD_REF, { 0, 0, 0, 0, 0, 1, 1 } },
|
2008-11-11 17:42:54 +00:00
|
|
|
{ "register", KEYWORD_REGISTER, { 1, 1, 0, 0, 0, 0, 0 } },
|
|
|
|
{ "return", KEYWORD_RETURN, { 1, 1, 1, 1, 0, 1, 1 } },
|
|
|
|
{ "set", KEYWORD_SET, { 0, 0, 0, 0, 0, 1, 0 } },
|
|
|
|
{ "shadow", KEYWORD_SHADOW, { 0, 0, 0, 0, 1, 0, 0 } },
|
|
|
|
{ "short", KEYWORD_SHORT, { 1, 1, 1, 1, 0, 1, 1 } },
|
|
|
|
{ "signal", KEYWORD_SIGNAL, { 0, 0, 0, 0, 0, 1, 0 } },
|
|
|
|
{ "signed", KEYWORD_SIGNED, { 1, 1, 0, 0, 0, 0, 0 } },
|
|
|
|
{ "size_t", KEYWORD_SIZE_T, { 1, 1, 0, 0, 0, 1, 1 } },
|
|
|
|
{ "state", KEYWORD_STATE, { 0, 0, 0, 0, 1, 0, 0 } },
|
|
|
|
{ "static", KEYWORD_STATIC, { 1, 1, 1, 1, 1, 1, 1 } },
|
|
|
|
{ "string", KEYWORD_STRING, { 0, 0, 1, 0, 1, 1, 0 } },
|
|
|
|
{ "struct", KEYWORD_STRUCT, { 1, 1, 1, 0, 0, 1, 1 } },
|
|
|
|
{ "switch", KEYWORD_SWITCH, { 1, 1, 1, 1, 0, 1, 1 } },
|
|
|
|
{ "synchronized", KEYWORD_SYNCHRONIZED, { 0, 0, 0, 1, 0, 0, 1 } },
|
|
|
|
{ "task", KEYWORD_TASK, { 0, 0, 0, 0, 1, 0, 0 } },
|
|
|
|
{ "template", KEYWORD_TEMPLATE, { 0, 1, 0, 0, 0, 0, 1 } },
|
|
|
|
{ "this", KEYWORD_THIS, { 0, 0, 1, 1, 0, 1, 0 } }, /* 0 to allow D ctor tags */
|
|
|
|
{ "throw", KEYWORD_THROW, { 0, 1, 1, 1, 0, 1, 1 } },
|
|
|
|
{ "throws", KEYWORD_THROWS, { 0, 0, 0, 1, 0, 1, 0 } },
|
|
|
|
{ "trans", KEYWORD_TRANS, { 0, 0, 0, 0, 1, 0, 0 } },
|
|
|
|
{ "transition", KEYWORD_TRANSITION, { 0, 0, 0, 0, 1, 0, 0 } },
|
|
|
|
{ "transient", KEYWORD_TRANSIENT, { 0, 0, 0, 1, 0, 0, 0 } },
|
|
|
|
{ "try", KEYWORD_TRY, { 0, 1, 1, 0, 0, 1, 1 } },
|
|
|
|
{ "typedef", KEYWORD_TYPEDEF, { 1, 1, 1, 0, 1, 0, 1 } },
|
|
|
|
{ "typename", KEYWORD_TYPENAME, { 0, 1, 0, 0, 0, 0, 0 } },
|
|
|
|
{ "uint", KEYWORD_UINT, { 0, 0, 1, 0, 0, 1, 1 } },
|
|
|
|
{ "ulong", KEYWORD_ULONG, { 0, 0, 1, 0, 0, 1, 1 } },
|
|
|
|
{ "union", KEYWORD_UNION, { 1, 1, 0, 0, 0, 0, 1 } },
|
|
|
|
{ "unsigned", KEYWORD_UNSIGNED, { 1, 1, 1, 0, 0, 0, 1 } },
|
|
|
|
{ "ushort", KEYWORD_USHORT, { 0, 0, 1, 0, 0, 1, 1 } },
|
|
|
|
{ "using", KEYWORD_USING, { 0, 1, 1, 0, 0, 1, 0 } },
|
2009-11-06 17:24:31 +00:00
|
|
|
{ "version", KEYWORD_NAMESPACE, { 0, 0, 0, 0, 0, 0, 1 } }, /* hack to ignore version */
|
2008-11-11 17:42:54 +00:00
|
|
|
{ "virtual", KEYWORD_VIRTUAL, { 0, 1, 1, 0, 1, 1, 0 } },
|
|
|
|
{ "void", KEYWORD_VOID, { 1, 1, 1, 1, 1, 1, 1 } },
|
|
|
|
{ "volatile", KEYWORD_VOLATILE, { 1, 1, 1, 1, 0, 0, 1 } },
|
|
|
|
{ "wchar_t", KEYWORD_WCHAR_T, { 1, 1, 1, 0, 0, 0, 1 } },
|
2008-12-09 19:00:45 +00:00
|
|
|
{ "weak", KEYWORD_WEAK, { 0, 0, 0, 0, 0, 1, 0 } },
|
2008-11-11 17:42:54 +00:00
|
|
|
{ "while", KEYWORD_WHILE, { 1, 1, 1, 1, 0, 1, 1 } }
|
2005-11-22 12:26:26 +00:00
|
|
|
};
|
|
|
|
|
2007-06-22 17:22:07 +00:00
|
|
|
|
2005-11-22 12:26:26 +00:00
|
|
|
/*
|
|
|
|
* FUNCTION PROTOTYPES
|
|
|
|
*/
|
|
|
|
static void createTags (const unsigned int nestLevel, statementInfo *const parent);
|
2007-01-16 13:18:37 +00:00
|
|
|
static void copyToken (tokenInfo *const dest, const tokenInfo *const src);
|
2007-10-17 11:55:59 +00:00
|
|
|
static const char *getVarType (const statementInfo *const st);
|
2005-11-22 12:26:26 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* FUNCTION DEFINITIONS
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Debugging functions added by Biswa */
|
2008-02-20 11:24:23 +00:00
|
|
|
#if defined(DEBUG_C) && DEBUG_C
|
2005-11-22 12:26:26 +00:00
|
|
|
static char *tokenTypeName[] = {
|
2008-11-12 19:37:02 +00:00
|
|
|
"none", "args", "'}'", "'{'", "','", "'::'", "keyword", "name",
|
|
|
|
"package", "paren-name", "';'", "spec", "*", "[]", "count"
|
2005-11-22 12:26:26 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static char *tagScopeNames[] = {
|
|
|
|
"global", "static", "extern", "friend", "typedef", "count"};
|
|
|
|
|
|
|
|
static char *declTypeNames[] = {
|
|
|
|
"none", "base", "class", "enum", "function", "ignore", "interface",
|
|
|
|
"namespace", "nomangle", "package", "struct", "union", "count"};
|
|
|
|
|
|
|
|
static char *impTypeNames[] = {
|
|
|
|
"default", "abstract", "virtual", "pure-virtual", "count"};
|
|
|
|
|
|
|
|
void printToken(const tokenInfo *const token)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "Type: %s, Keyword: %d, name: %s\n", tokenTypeName[token->type],
|
2008-11-12 19:37:02 +00:00
|
|
|
token->keyword, vStringValue(token->name));
|
2005-11-22 12:26:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void printTagEntry(const tagEntryInfo *tag)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "Tag: %s (%s) [ impl: %s, scope: %s, type: %s\n", tag->name,
|
|
|
|
tag->kindName, tag->extensionFields.implementation, tag->extensionFields.scope[1],
|
|
|
|
tag->extensionFields.varType);
|
|
|
|
}
|
|
|
|
|
|
|
|
void printStatement(const statementInfo *const statement)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
statementInfo *st = (statementInfo *) statement;
|
|
|
|
while (NULL != st)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "Statement Info:\n------------------------\n");
|
2008-11-12 19:37:02 +00:00
|
|
|
fprintf(stderr, "scope: %s, decl: %s, impl: %s\n", tagScopeNames[st->scope],
|
|
|
|
declTypeNames[st->declaration], impTypeNames[st->implementation]);
|
2005-11-22 12:26:26 +00:00
|
|
|
for (i=0; i < NumTokens; ++i)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "Token %d %s: ", i, (i == st->tokenIndex)?"(current)":"");
|
|
|
|
printToken(st->token[i]);
|
|
|
|
}
|
|
|
|
fprintf(stderr, "Context: ");
|
|
|
|
printToken(st->context);
|
|
|
|
fprintf(stderr, "Block: ");
|
|
|
|
printToken(st->blockName);
|
|
|
|
fprintf(stderr, "Parent classes: %s\n", vStringValue(st->parentClasses));
|
|
|
|
fprintf(stderr, "First token: ");
|
|
|
|
printToken(st->firstToken);
|
|
|
|
if (NULL != st->parent)
|
|
|
|
fprintf(stderr, "Printing Parent:\n");
|
|
|
|
st = st->parent;
|
|
|
|
}
|
|
|
|
fprintf(stderr, "-----------------------------------------------\n");
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
extern boolean includingDefineTags (void)
|
|
|
|
{
|
2008-11-12 19:37:02 +00:00
|
|
|
return CKinds [CK_DEFINE].enabled;
|
2005-11-22 12:26:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Token management
|
|
|
|
*/
|
|
|
|
|
|
|
|
static void initToken (tokenInfo* const token)
|
|
|
|
{
|
2008-11-12 19:37:02 +00:00
|
|
|
token->type = TOKEN_NONE;
|
|
|
|
token->keyword = KEYWORD_NONE;
|
|
|
|
token->lineNumber = getSourceLineNumber();
|
|
|
|
if (useFile())
|
|
|
|
token->filePosition = getInputFilePosition();
|
|
|
|
else
|
|
|
|
token->bufferPosition = getInputBufferPosition();
|
|
|
|
vStringClear(token->name);
|
2005-11-22 12:26:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void advanceToken (statementInfo* const st)
|
|
|
|
{
|
2008-11-12 19:37:02 +00:00
|
|
|
if (st->tokenIndex >= (unsigned int) NumTokens - 1)
|
|
|
|
st->tokenIndex = 0;
|
|
|
|
else
|
|
|
|
++st->tokenIndex;
|
|
|
|
initToken(st->token[st->tokenIndex]);
|
2005-11-22 12:26:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static tokenInfo *prevToken (const statementInfo *const st, unsigned int n)
|
|
|
|
{
|
2008-11-12 19:37:02 +00:00
|
|
|
unsigned int tokenIndex;
|
|
|
|
unsigned int num = (unsigned int) NumTokens;
|
|
|
|
Assert(n < num);
|
|
|
|
tokenIndex = (st->tokenIndex + num - n) % num;
|
2007-01-16 13:18:37 +00:00
|
|
|
|
2008-11-12 19:37:02 +00:00
|
|
|
return st->token[tokenIndex];
|
2005-11-22 12:26:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void setToken (statementInfo *const st, const tokenType type)
|
|
|
|
{
|
2008-11-12 19:37:02 +00:00
|
|
|
tokenInfo *token;
|
|
|
|
token = activeToken (st);
|
|
|
|
initToken(token);
|
|
|
|
token->type = type;
|
2005-11-22 12:26:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void retardToken (statementInfo *const st)
|
|
|
|
{
|
2008-11-12 19:37:02 +00:00
|
|
|
if (st->tokenIndex == 0)
|
|
|
|
st->tokenIndex = (unsigned int) NumTokens - 1;
|
|
|
|
else
|
|
|
|
--st->tokenIndex;
|
|
|
|
setToken(st, TOKEN_NONE);
|
2005-11-22 12:26:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static tokenInfo *newToken (void)
|
|
|
|
{
|
2008-11-12 19:37:02 +00:00
|
|
|
tokenInfo *const token = xMalloc (1, tokenInfo);
|
|
|
|
token->name = vStringNew();
|
|
|
|
initToken(token);
|
|
|
|
return token;
|
2005-11-22 12:26:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void deleteToken (tokenInfo *const token)
|
|
|
|
{
|
2008-11-12 19:37:02 +00:00
|
|
|
if (token != NULL)
|
|
|
|
{
|
|
|
|
vStringDelete(token->name);
|
|
|
|
eFree(token);
|
|
|
|
}
|
2005-11-22 12:26:26 +00:00
|
|
|
}
|
|
|
|
|
2007-06-29 15:42:37 +00:00
|
|
|
static const char *accessString (const accessType laccess)
|
2005-11-22 12:26:26 +00:00
|
|
|
{
|
2008-11-12 19:37:02 +00:00
|
|
|
static const char *const names [] ={
|
|
|
|
"?", "private", "protected", "public", "default"
|
|
|
|
};
|
|
|
|
Assert (sizeof (names) / sizeof (names [0]) == ACCESS_COUNT);
|
|
|
|
Assert ((int) laccess < ACCESS_COUNT);
|
|
|
|
return names[(int) laccess];
|
2005-11-22 12:26:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static const char *implementationString (const impType imp)
|
|
|
|
{
|
2008-11-12 19:37:02 +00:00
|
|
|
static const char *const names [] ={
|
|
|
|
"?", "abstract", "virtual", "pure virtual"
|
|
|
|
};
|
|
|
|
Assert (sizeof (names) / sizeof (names [0]) == IMP_COUNT);
|
|
|
|
Assert ((int) imp < IMP_COUNT);
|
|
|
|
return names [(int) imp];
|
2005-11-22 12:26:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Debugging functions
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef TM_DEBUG
|
|
|
|
|
|
|
|
#define boolString(c) ((c) ? "TRUE" : "FALSE")
|
|
|
|
|
|
|
|
static const char *tokenString (const tokenType type)
|
|
|
|
{
|
2008-11-12 19:37:02 +00:00
|
|
|
static const char *const names [] = {
|
|
|
|
"none", "args", "}", "{", "comma", "double colon", "keyword", "name",
|
|
|
|
"package", "paren-name", "semicolon", "specifier", "*", "[]", "count"
|
|
|
|
};
|
|
|
|
Assert (sizeof (names) / sizeof (names [0]) == TOKEN_COUNT);
|
|
|
|
Assert ((int) type < TOKEN_COUNT);
|
|
|
|
return names[(int) type];
|
2005-11-22 12:26:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static const char *scopeString (const tagScope scope)
|
|
|
|
{
|
2008-11-12 19:37:02 +00:00
|
|
|
static const char *const names [] = {
|
|
|
|
"global", "static", "extern", "friend", "typedef"
|
|
|
|
};
|
|
|
|
Assert (sizeof (names) / sizeof (names [0]) == SCOPE_COUNT);
|
|
|
|
Assert ((int) scope < SCOPE_COUNT);
|
|
|
|
return names[(int) scope];
|
2005-11-22 12:26:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static const char *declString (const declType declaration)
|
|
|
|
{
|
2008-11-12 19:37:02 +00:00
|
|
|
static const char *const names [] = {
|
|
|
|
"?", "base", "class", "enum", "function", "ignore", "interface",
|
|
|
|
"namespace", "no mangle", "package", "struct", "union",
|
|
|
|
};
|
|
|
|
Assert (sizeof (names) / sizeof (names [0]) == DECL_COUNT);
|
|
|
|
Assert ((int) declaration < DECL_COUNT);
|
|
|
|
return names[(int) declaration];
|
2005-11-22 12:26:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static const char *keywordString (const keywordId keyword)
|
|
|
|
{
|
2008-11-12 19:37:02 +00:00
|
|
|
const size_t count = sizeof (KeywordTable) / sizeof (KeywordTable [0]);
|
|
|
|
const char *name = "none";
|
|
|
|
size_t i;
|
|
|
|
for (i = 0 ; i < count ; ++i)
|
2005-11-22 12:26:26 +00:00
|
|
|
{
|
2008-11-12 19:37:02 +00:00
|
|
|
const keywordDesc *p = &KeywordTable[i];
|
|
|
|
|
|
|
|
if (p->id == keyword)
|
|
|
|
{
|
|
|
|
name = p->name;
|
|
|
|
break;
|
|
|
|
}
|
2005-11-22 12:26:26 +00:00
|
|
|
}
|
2008-11-12 19:37:02 +00:00
|
|
|
return name;
|
2005-11-22 12:26:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void __unused__ pt (tokenInfo *const token)
|
|
|
|
{
|
2008-11-12 19:37:02 +00:00
|
|
|
if (isType (token, TOKEN_NAME))
|
|
|
|
printf("type: %-12s: %-13s line: %lu\n",
|
|
|
|
tokenString (token->type), vStringValue (token->name),
|
|
|
|
token->lineNumber);
|
|
|
|
else if (isType (token, TOKEN_KEYWORD))
|
|
|
|
printf("type: %-12s: %-13s line: %lu\n",
|
|
|
|
tokenString (token->type), keywordString (token->keyword),
|
|
|
|
token->lineNumber);
|
|
|
|
else
|
|
|
|
printf("type: %-12s line: %lu\n",
|
|
|
|
tokenString (token->type), token->lineNumber);
|
2005-11-22 12:26:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void __unused__ ps (statementInfo *const st)
|
|
|
|
{
|
2008-11-12 19:37:02 +00:00
|
|
|
unsigned int i;
|
|
|
|
printf("scope: %s decl: %s gotName: %s gotParenName: %s\n",
|
|
|
|
scopeString (st->scope), declString (st->declaration),
|
|
|
|
boolString (st->gotName), boolString (st->gotParenName));
|
|
|
|
printf("haveQualifyingName: %s\n", boolString (st->haveQualifyingName));
|
|
|
|
printf("access: %s default: %s\n", accessString (st->member.access),
|
|
|
|
accessString (st->member.accessDefault));
|
|
|
|
printf("token : ");
|
|
|
|
pt(activeToken (st));
|
|
|
|
for (i = 1 ; i < (unsigned int) NumTokens ; ++i)
|
|
|
|
{
|
|
|
|
printf("prev %u : ", i);
|
|
|
|
pt(prevToken (st, i));
|
|
|
|
}
|
|
|
|
printf("context: ");
|
|
|
|
pt(st->context);
|
2005-11-22 12:26:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Statement management
|
|
|
|
*/
|
|
|
|
|
2007-01-16 13:18:37 +00:00
|
|
|
static boolean isDataTypeKeyword (const tokenInfo *const token)
|
|
|
|
{
|
2008-11-12 19:37:02 +00:00
|
|
|
switch (token->keyword)
|
|
|
|
{
|
|
|
|
case KEYWORD_BOOLEAN:
|
|
|
|
case KEYWORD_BYTE:
|
|
|
|
case KEYWORD_CHAR:
|
|
|
|
case KEYWORD_DOUBLE:
|
|
|
|
case KEYWORD_FLOAT:
|
|
|
|
case KEYWORD_INT:
|
|
|
|
case KEYWORD_LONG:
|
|
|
|
case KEYWORD_SHORT:
|
|
|
|
case KEYWORD_VOID:
|
|
|
|
case KEYWORD_WCHAR_T:
|
|
|
|
case KEYWORD_SIZE_T:
|
|
|
|
return TRUE;
|
|
|
|
default:
|
|
|
|
return FALSE;
|
|
|
|
}
|
2007-01-16 13:18:37 +00:00
|
|
|
}
|
|
|
|
|
2008-02-25 16:37:46 +00:00
|
|
|
#if 0
|
2007-01-03 12:41:10 +00:00
|
|
|
static boolean isVariableKeyword (const tokenInfo *const token)
|
|
|
|
{
|
2008-11-12 19:37:02 +00:00
|
|
|
switch (token->keyword)
|
|
|
|
{
|
|
|
|
case KEYWORD_CONST:
|
|
|
|
case KEYWORD_EXTERN:
|
|
|
|
case KEYWORD_REGISTER:
|
|
|
|
case KEYWORD_STATIC:
|
|
|
|
case KEYWORD_VIRTUAL:
|
|
|
|
case KEYWORD_SIGNED:
|
|
|
|
case KEYWORD_UNSIGNED:
|
|
|
|
return TRUE;
|
|
|
|
default:
|
|
|
|
return FALSE;
|
|
|
|
}
|
2007-01-03 12:41:10 +00:00
|
|
|
}
|
2008-02-25 16:37:46 +00:00
|
|
|
#endif
|
2007-01-03 12:41:10 +00:00
|
|
|
|
2005-11-22 12:26:26 +00:00
|
|
|
static boolean isContextualKeyword (const tokenInfo *const token)
|
|
|
|
{
|
2008-11-12 19:37:02 +00:00
|
|
|
boolean result;
|
|
|
|
switch (token->keyword)
|
|
|
|
{
|
|
|
|
case KEYWORD_CLASS:
|
|
|
|
case KEYWORD_ENUM:
|
|
|
|
case KEYWORD_INTERFACE:
|
|
|
|
case KEYWORD_NAMESPACE:
|
|
|
|
case KEYWORD_STRUCT:
|
|
|
|
case KEYWORD_UNION:
|
|
|
|
{
|
|
|
|
result = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
{
|
|
|
|
result = FALSE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
2005-11-22 12:26:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static boolean isContextualStatement (const statementInfo *const st)
|
|
|
|
{
|
2008-11-12 19:37:02 +00:00
|
|
|
boolean result = FALSE;
|
2005-11-22 12:26:26 +00:00
|
|
|
|
2008-11-11 16:33:20 +00:00
|
|
|
if (st != NULL)
|
|
|
|
{
|
|
|
|
if (isLanguage (Lang_vala))
|
|
|
|
{
|
|
|
|
/* All can be a contextual statment as properties can be of any type */
|
|
|
|
result = TRUE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
switch (st->declaration)
|
|
|
|
{
|
2008-11-12 19:37:02 +00:00
|
|
|
case DECL_CLASS:
|
|
|
|
case DECL_ENUM:
|
|
|
|
case DECL_INTERFACE:
|
|
|
|
case DECL_NAMESPACE:
|
|
|
|
case DECL_STRUCT:
|
|
|
|
case DECL_UNION:
|
|
|
|
{
|
|
|
|
result = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
2008-11-11 16:33:20 +00:00
|
|
|
|
2008-11-12 19:37:02 +00:00
|
|
|
default:
|
|
|
|
{
|
|
|
|
result = FALSE;
|
|
|
|
break;
|
|
|
|
}
|
2008-11-11 16:33:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2008-12-09 19:00:45 +00:00
|
|
|
return result;
|
2005-11-22 12:26:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static boolean isMember (const statementInfo *const st)
|
|
|
|
{
|
2008-11-12 19:37:02 +00:00
|
|
|
boolean result;
|
|
|
|
if (isType (st->context, TOKEN_NAME))
|
|
|
|
result = TRUE;
|
|
|
|
else
|
|
|
|
result = isContextualStatement (st->parent);
|
|
|
|
return result;
|
2005-11-22 12:26:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void initMemberInfo (statementInfo *const st)
|
|
|
|
{
|
2008-11-12 19:37:02 +00:00
|
|
|
accessType accessDefault = ACCESS_UNDEFINED;
|
2005-11-22 12:26:26 +00:00
|
|
|
|
2008-11-12 19:37:02 +00:00
|
|
|
if (st->parent != NULL) switch (st->parent->declaration)
|
|
|
|
{
|
|
|
|
case DECL_ENUM:
|
|
|
|
case DECL_NAMESPACE:
|
|
|
|
{
|
|
|
|
accessDefault = ACCESS_UNDEFINED;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case DECL_CLASS:
|
|
|
|
{
|
|
|
|
if (isLanguage (Lang_java))
|
|
|
|
accessDefault = ACCESS_DEFAULT;
|
|
|
|
else
|
|
|
|
accessDefault = ACCESS_PRIVATE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case DECL_INTERFACE:
|
|
|
|
case DECL_STRUCT:
|
|
|
|
case DECL_UNION:
|
|
|
|
{
|
|
|
|
accessDefault = ACCESS_PUBLIC;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
st->member.accessDefault = accessDefault;
|
|
|
|
st->member.access = accessDefault;
|
2005-11-22 12:26:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void reinitStatement (statementInfo *const st, const boolean partial)
|
|
|
|
{
|
2008-11-12 19:37:02 +00:00
|
|
|
unsigned int i;
|
2005-11-22 12:26:26 +00:00
|
|
|
|
2008-11-12 19:37:02 +00:00
|
|
|
if (! partial)
|
|
|
|
{
|
|
|
|
st->scope = SCOPE_GLOBAL;
|
|
|
|
if (isContextualStatement (st->parent))
|
|
|
|
st->declaration = DECL_BASE;
|
|
|
|
else
|
|
|
|
st->declaration = DECL_NONE;
|
|
|
|
}
|
|
|
|
st->gotParenName = FALSE;
|
|
|
|
st->implementation = IMP_DEFAULT;
|
|
|
|
st->gotArgs = FALSE;
|
|
|
|
st->gotName = FALSE;
|
|
|
|
st->haveQualifyingName = FALSE;
|
|
|
|
st->argEndPosition = 0;
|
|
|
|
|
|
|
|
st->tokenIndex = 0;
|
|
|
|
for (i = 0 ; i < (unsigned int) NumTokens ; ++i)
|
|
|
|
{
|
|
|
|
initToken (st->token [i]);
|
|
|
|
}
|
2005-11-22 12:26:26 +00:00
|
|
|
|
2008-11-12 19:37:02 +00:00
|
|
|
initToken (st->context);
|
|
|
|
initToken (st->blockName);
|
|
|
|
vStringClear (st->parentClasses);
|
2005-11-22 12:26:26 +00:00
|
|
|
|
2008-11-12 19:37:02 +00:00
|
|
|
/* Init member info.
|
|
|
|
*/
|
|
|
|
if (! partial)
|
|
|
|
st->member.access = st->member.accessDefault;
|
2006-08-27 17:39:34 +00:00
|
|
|
|
2005-11-22 12:26:26 +00:00
|
|
|
/* Init first token */
|
|
|
|
if (!partial)
|
2008-12-09 19:00:45 +00:00
|
|
|
initToken(st->firstToken);
|
2005-11-22 12:26:26 +00:00
|
|
|
}
|
|
|
|
|
2007-01-16 13:18:37 +00:00
|
|
|
static void reinitStatementWithToken (statementInfo *const st,
|
2008-12-09 19:00:45 +00:00
|
|
|
tokenInfo *token, const boolean partial)
|
2007-01-16 13:18:37 +00:00
|
|
|
{
|
2008-11-12 19:37:02 +00:00
|
|
|
tokenInfo *const save = newToken ();
|
|
|
|
/* given token can be part of reinit statementInfo */
|
|
|
|
copyToken (save, token);
|
|
|
|
reinitStatement (st, partial);
|
|
|
|
token = activeToken (st);
|
|
|
|
copyToken (token, save);
|
|
|
|
deleteToken (save);
|
|
|
|
++st->tokenIndex; /* this is quite save becouse current tokenIndex = 0 */
|
2007-01-16 13:18:37 +00:00
|
|
|
}
|
|
|
|
|
2005-11-22 12:26:26 +00:00
|
|
|
static void initStatement (statementInfo *const st, statementInfo *const parent)
|
|
|
|
{
|
2008-11-12 19:37:02 +00:00
|
|
|
st->parent = parent;
|
|
|
|
initMemberInfo (st);
|
|
|
|
reinitStatement (st, FALSE);
|
|
|
|
if(parent)
|
|
|
|
{
|
|
|
|
const tokenInfo *const src = activeToken (parent);
|
|
|
|
tokenInfo *const dst = activeToken (st);
|
|
|
|
copyToken (dst, src);
|
|
|
|
st->tokenIndex++;
|
|
|
|
}
|
2005-11-22 12:26:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Tag generation functions
|
|
|
|
*/
|
|
|
|
static cKind cTagKind (const tagType type)
|
|
|
|
{
|
2008-11-12 19:37:02 +00:00
|
|
|
cKind result = CK_UNDEFINED;
|
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
case TAG_CLASS: result = CK_CLASS; break;
|
|
|
|
case TAG_ENUM: result = CK_ENUMERATION; break;
|
|
|
|
case TAG_ENUMERATOR: result = CK_ENUMERATOR; break;
|
|
|
|
case TAG_FUNCTION: result = CK_FUNCTION; break;
|
2009-11-06 17:14:00 +00:00
|
|
|
case TAG_INTERFACE: result = CK_INTERFACE; break;
|
2008-11-12 19:37:02 +00:00
|
|
|
case TAG_MEMBER: result = CK_MEMBER; break;
|
|
|
|
case TAG_NAMESPACE: result = CK_NAMESPACE; break;
|
|
|
|
case TAG_PROTOTYPE: result = CK_PROTOTYPE; break;
|
|
|
|
case TAG_STRUCT: result = CK_STRUCT; break;
|
|
|
|
case TAG_TYPEDEF: result = CK_TYPEDEF; break;
|
|
|
|
case TAG_UNION: result = CK_UNION; break;
|
|
|
|
case TAG_VARIABLE: result = CK_VARIABLE; break;
|
|
|
|
case TAG_EXTERN_VAR: result = CK_EXTERN_VARIABLE; break;
|
|
|
|
|
|
|
|
default: Assert ("Bad C tag type" == NULL); break;
|
|
|
|
}
|
|
|
|
return result;
|
2005-11-22 12:26:26 +00:00
|
|
|
}
|
|
|
|
|
2007-06-22 17:22:07 +00:00
|
|
|
static csharpKind csharpTagKind (const tagType type)
|
|
|
|
{
|
|
|
|
csharpKind result = CSK_UNDEFINED;
|
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
case TAG_CLASS: result = CSK_CLASS; break;
|
|
|
|
case TAG_ENUM: result = CSK_ENUMERATION; break;
|
|
|
|
case TAG_ENUMERATOR: result = CSK_ENUMERATOR; break;
|
|
|
|
case TAG_EVENT: result = CSK_EVENT; break;
|
|
|
|
case TAG_FIELD: result = CSK_FIELD ; break;
|
|
|
|
case TAG_INTERFACE: result = CSK_INTERFACE; break;
|
|
|
|
case TAG_LOCAL: result = CSK_LOCAL; break;
|
|
|
|
case TAG_METHOD: result = CSK_METHOD; break;
|
|
|
|
case TAG_NAMESPACE: result = CSK_NAMESPACE; break;
|
|
|
|
case TAG_PROPERTY: result = CSK_PROPERTY; break;
|
|
|
|
case TAG_STRUCT: result = CSK_STRUCT; break;
|
|
|
|
case TAG_TYPEDEF: result = CSK_TYPEDEF; break;
|
|
|
|
|
|
|
|
default: Assert ("Bad C# tag type" == NULL); break;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2008-11-11 16:33:20 +00:00
|
|
|
static valaKind valaTagKind (const tagType type)
|
|
|
|
{
|
|
|
|
valaKind result = VK_UNDEFINED;
|
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
case TAG_CLASS: result = VK_CLASS; break;
|
|
|
|
case TAG_ENUM: result = VK_ENUMERATION; break;
|
|
|
|
case TAG_ENUMERATOR: result = VK_ENUMERATOR; break;
|
|
|
|
case TAG_SIGNAL: result = VK_SIGNAL; break;
|
|
|
|
case TAG_FIELD: result = VK_FIELD ; break;
|
|
|
|
case TAG_INTERFACE: result = VK_INTERFACE; break;
|
|
|
|
case TAG_LOCAL: result = VK_LOCAL; break;
|
|
|
|
case TAG_METHOD: result = VK_METHOD; break;
|
|
|
|
case TAG_NAMESPACE: result = VK_NAMESPACE; break;
|
|
|
|
case TAG_PROPERTY: result = VK_PROPERTY; break;
|
|
|
|
case TAG_STRUCT: result = VK_STRUCT; break;
|
|
|
|
|
|
|
|
default: Assert ("Bad Vala tag type" == NULL); break;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2005-11-22 12:26:26 +00:00
|
|
|
static javaKind javaTagKind (const tagType type)
|
|
|
|
{
|
2008-11-12 19:37:02 +00:00
|
|
|
javaKind result = JK_UNDEFINED;
|
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
case TAG_CLASS: result = JK_CLASS; break;
|
|
|
|
case TAG_FIELD: result = JK_FIELD; break;
|
|
|
|
case TAG_INTERFACE: result = JK_INTERFACE; break;
|
|
|
|
case TAG_METHOD: result = JK_METHOD; break;
|
|
|
|
case TAG_PACKAGE: result = JK_PACKAGE; break;
|
2005-11-22 12:26:26 +00:00
|
|
|
|
2008-11-12 19:37:02 +00:00
|
|
|
default: Assert ("Bad Java tag type" == NULL); break;
|
|
|
|
}
|
|
|
|
return result;
|
2005-11-22 12:26:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static const char *tagName (const tagType type)
|
|
|
|
{
|
2008-11-12 19:37:02 +00:00
|
|
|
const char* result;
|
|
|
|
if (isLanguage (Lang_java))
|
2007-06-22 17:22:07 +00:00
|
|
|
result = JavaKinds [javaTagKind (type)].name;
|
|
|
|
else if (isLanguage (Lang_csharp))
|
|
|
|
result = CsharpKinds [csharpTagKind (type)].name;
|
2008-11-11 16:33:20 +00:00
|
|
|
else if (isLanguage (Lang_vala))
|
|
|
|
result = ValaKinds [valaTagKind (type)].name;
|
2008-11-12 19:37:02 +00:00
|
|
|
else
|
2007-06-22 17:22:07 +00:00
|
|
|
result = CKinds [cTagKind (type)].name;
|
2008-11-12 19:37:02 +00:00
|
|
|
return result;
|
2005-11-22 12:26:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int tagLetter (const tagType type)
|
|
|
|
{
|
2008-11-12 19:37:02 +00:00
|
|
|
int result;
|
2008-11-11 16:33:20 +00:00
|
|
|
if (isLanguage (Lang_csharp))
|
2007-06-22 17:22:07 +00:00
|
|
|
result = CsharpKinds [csharpTagKind (type)].letter;
|
2008-11-11 16:33:20 +00:00
|
|
|
else if (isLanguage (Lang_java))
|
|
|
|
result = JavaKinds [javaTagKind (type)].letter;
|
2008-11-12 19:37:02 +00:00
|
|
|
else if (isLanguage (Lang_vala))
|
2008-11-11 16:33:20 +00:00
|
|
|
result = ValaKinds [valaTagKind (type)].letter;
|
2008-11-12 19:37:02 +00:00
|
|
|
else
|
2007-06-22 17:22:07 +00:00
|
|
|
result = CKinds [cTagKind (type)].letter;
|
2008-11-12 19:37:02 +00:00
|
|
|
return result;
|
2005-11-22 12:26:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
static boolean includeTag (const tagType type, const boolean isFileScope)
|
|
|
|
{
|
2008-11-12 19:37:02 +00:00
|
|
|
boolean result;
|
|
|
|
if (isFileScope && ! Option.include.fileScope)
|
|
|
|
result = FALSE;
|
|
|
|
else if (isLanguage (Lang_java))
|
|
|
|
result = JavaKinds [javaTagKind (type)].enabled;
|
|
|
|
else
|
|
|
|
result = CKinds [cTagKind (type)].enabled;
|
|
|
|
return result;
|
2005-11-22 12:26:26 +00:00
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
|
|
|
static tagType declToTagType (const declType declaration)
|
|
|
|
{
|
2008-11-12 19:37:02 +00:00
|
|
|
tagType type = TAG_UNDEFINED;
|
2005-11-22 12:26:26 +00:00
|
|
|
|
2008-11-12 19:37:02 +00:00
|
|
|
switch (declaration)
|
|
|
|
{
|
2008-12-09 19:00:45 +00:00
|
|
|
case DECL_CLASS: type = TAG_CLASS; break;
|
|
|
|
case DECL_ENUM: type = TAG_ENUM; break;
|
2008-11-12 19:37:02 +00:00
|
|
|
case DECL_FUNCTION: type = TAG_FUNCTION; break;
|
|
|
|
case DECL_INTERFACE:type = TAG_INTERFACE; break;
|
|
|
|
case DECL_NAMESPACE:type = TAG_NAMESPACE; break;
|
2008-12-09 19:00:45 +00:00
|
|
|
case DECL_STRUCT: type = TAG_STRUCT; break;
|
|
|
|
case DECL_UNION: type = TAG_UNION; break;
|
2008-11-12 19:37:02 +00:00
|
|
|
|
|
|
|
default: Assert ("Unexpected declaration" == NULL); break;
|
|
|
|
}
|
|
|
|
return type;
|
2005-11-22 12:26:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static const char* accessField (const statementInfo *const st)
|
|
|
|
{
|
2008-11-12 19:37:02 +00:00
|
|
|
const char* result = NULL;
|
2006-08-27 17:39:34 +00:00
|
|
|
|
2008-11-12 19:37:02 +00:00
|
|
|
if ((isLanguage (Lang_cpp) || isLanguage (Lang_d) || isLanguage (Lang_ferite)) &&
|
|
|
|
st->scope == SCOPE_FRIEND)
|
|
|
|
result = "friend";
|
|
|
|
else if (st->member.access != ACCESS_UNDEFINED)
|
|
|
|
result = accessString (st->member.access);
|
|
|
|
return result;
|
2005-11-22 12:26:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void addOtherFields (tagEntryInfo* const tag, const tagType type,
|
2008-11-12 19:37:02 +00:00
|
|
|
const statementInfo *const st, vString *const scope)
|
2005-11-22 12:26:26 +00:00
|
|
|
{
|
|
|
|
/* For selected tag types, append an extension flag designating the
|
|
|
|
* parent object in which the tag is defined.
|
|
|
|
*/
|
|
|
|
switch (type)
|
|
|
|
{
|
2008-11-12 19:37:02 +00:00
|
|
|
default: break;
|
|
|
|
|
|
|
|
case TAG_CLASS:
|
|
|
|
case TAG_ENUM:
|
|
|
|
case TAG_ENUMERATOR:
|
|
|
|
case TAG_FIELD:
|
|
|
|
case TAG_FUNCTION:
|
|
|
|
case TAG_INTERFACE:
|
|
|
|
case TAG_MEMBER:
|
|
|
|
case TAG_METHOD:
|
|
|
|
case TAG_PROTOTYPE:
|
|
|
|
case TAG_STRUCT:
|
|
|
|
case TAG_TYPEDEF:
|
|
|
|
case TAG_UNION:
|
|
|
|
{
|
2007-06-22 17:22:07 +00:00
|
|
|
if (vStringLength (scope) > 0 &&
|
|
|
|
(isMember (st) || st->parent->declaration == DECL_NAMESPACE))
|
|
|
|
{
|
|
|
|
if (isType (st->context, TOKEN_NAME))
|
|
|
|
tag->extensionFields.scope [0] = tagName (TAG_CLASS);
|
|
|
|
else
|
|
|
|
tag->extensionFields.scope [0] =
|
|
|
|
tagName (declToTagType (parentDecl (st)));
|
|
|
|
tag->extensionFields.scope [1] = vStringValue (scope);
|
|
|
|
}
|
|
|
|
if ((type == TAG_CLASS || type == TAG_INTERFACE ||
|
|
|
|
type == TAG_STRUCT) && vStringLength (st->parentClasses) > 0)
|
|
|
|
{
|
2006-08-27 17:39:34 +00:00
|
|
|
|
2007-06-22 17:22:07 +00:00
|
|
|
tag->extensionFields.inheritance =
|
|
|
|
vStringValue (st->parentClasses);
|
|
|
|
}
|
|
|
|
if (st->implementation != IMP_DEFAULT &&
|
2008-11-11 16:33:20 +00:00
|
|
|
(isLanguage (Lang_cpp) || isLanguage (Lang_csharp) || isLanguage (Lang_vala) ||
|
2007-06-29 15:42:37 +00:00
|
|
|
isLanguage (Lang_java) || isLanguage (Lang_d) || isLanguage (Lang_ferite)))
|
2007-06-22 17:22:07 +00:00
|
|
|
{
|
|
|
|
tag->extensionFields.implementation =
|
|
|
|
implementationString (st->implementation);
|
|
|
|
}
|
|
|
|
if (isMember (st))
|
|
|
|
{
|
|
|
|
tag->extensionFields.access = accessField (st);
|
2006-08-15 12:26:15 +00:00
|
|
|
}
|
2007-06-29 15:42:37 +00:00
|
|
|
if ((TRUE == st->gotArgs) && (TRUE == Option.extensionFields.argList) &&
|
2008-11-12 19:37:02 +00:00
|
|
|
((TAG_FUNCTION == type) || (TAG_METHOD == type) || (TAG_PROTOTYPE == type)))
|
2008-11-07 14:37:17 +00:00
|
|
|
{
|
2008-11-12 19:37:02 +00:00
|
|
|
if (useFile())
|
|
|
|
{
|
2008-11-07 14:37:17 +00:00
|
|
|
tag->extensionFields.arglist = getArglistFromFilePos(
|
2008-11-12 19:37:02 +00:00
|
|
|
tag->filePosition, tag->name);
|
2008-11-07 14:37:17 +00:00
|
|
|
}
|
2008-11-12 19:37:02 +00:00
|
|
|
else
|
|
|
|
{
|
2008-11-07 14:37:17 +00:00
|
|
|
tag->extensionFields.arglist = getArglistFromBufferPos(
|
2008-11-12 19:37:02 +00:00
|
|
|
tag->bufferPosition, tag->name);
|
2008-11-07 14:37:17 +00:00
|
|
|
}
|
2007-06-29 15:42:37 +00:00
|
|
|
}
|
2008-11-12 19:37:02 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2006-08-27 17:39:34 +00:00
|
|
|
|
2005-11-22 12:26:26 +00:00
|
|
|
if ((TAG_FIELD == tag->type) || (TAG_MEMBER == tag->type) ||
|
|
|
|
(TAG_EXTERN_VAR == tag->type) || (TAG_TYPEDEF == tag->type) ||
|
|
|
|
(TAG_VARIABLE == tag->type) || (TAG_METHOD == tag->type) ||
|
|
|
|
(TAG_PROTOTYPE == tag->type) || (TAG_FUNCTION == tag->type))
|
|
|
|
{
|
2007-01-16 13:18:37 +00:00
|
|
|
if (((TOKEN_NAME == st->firstToken->type) || isDataTypeKeyword(st->firstToken))
|
2008-11-12 19:37:02 +00:00
|
|
|
&& (0 != strcmp(vStringValue(st->firstToken->name), tag->name)))
|
|
|
|
{
|
|
|
|
tag->extensionFields.varType = getVarType(st);
|
|
|
|
}
|
2005-11-22 12:26:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-10-17 11:55:59 +00:00
|
|
|
static const char *getVarType (const statementInfo *const st)
|
|
|
|
{
|
|
|
|
static vString *vt = NULL;
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
if (! st->gotArgs)
|
|
|
|
return vStringValue(st->firstToken->name); /* ignore non-functions */
|
|
|
|
|
|
|
|
if (vt == NULL)
|
|
|
|
vt = vStringNew();
|
|
|
|
else
|
|
|
|
vStringClear(vt);
|
|
|
|
|
|
|
|
for (i = 0; i < st->tokenIndex; i++)
|
|
|
|
{
|
|
|
|
tokenInfo *t = st->token[i];
|
|
|
|
|
|
|
|
switch (t->type)
|
|
|
|
{
|
|
|
|
case TOKEN_NAME: /* user typename */
|
|
|
|
if (strcmp(vStringValue(t->name), vStringValue(st->firstToken->name)) != 0)
|
|
|
|
continue;
|
|
|
|
break;
|
|
|
|
case TOKEN_KEYWORD:
|
|
|
|
if (t->keyword != KEYWORD_EXTERN && t->keyword != KEYWORD_STATIC) /* uninteresting keywords */
|
|
|
|
break;
|
|
|
|
continue;
|
|
|
|
case TOKEN_STAR: vStringCatS(vt, " *"); continue;
|
|
|
|
case TOKEN_ARRAY: vStringCatS(vt, "[]"); continue;
|
|
|
|
default: continue;
|
|
|
|
}
|
|
|
|
if (vStringLength(vt) > 0)
|
|
|
|
if (isalpha(vStringValue(vt)[vStringLength(vt) - 1]))
|
|
|
|
vStringPut(vt, ' ');
|
|
|
|
vStringCat(vt, t->name);
|
|
|
|
}
|
|
|
|
vStringTerminate(vt);
|
|
|
|
return vStringValue(vt);
|
|
|
|
}
|
|
|
|
|
2005-11-22 12:26:26 +00:00
|
|
|
static void addContextSeparator (vString *const scope)
|
|
|
|
{
|
2008-11-12 19:37:02 +00:00
|
|
|
if (isLanguage (Lang_c) || isLanguage (Lang_cpp))
|
|
|
|
vStringCatS (scope, "::");
|
|
|
|
else if (isLanguage (Lang_java) || isLanguage (Lang_d) || isLanguage (Lang_ferite) ||
|
|
|
|
isLanguage (Lang_csharp) || isLanguage (Lang_vala))
|
|
|
|
vStringCatS (scope, ".");
|
2005-11-22 12:26:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void findScopeHierarchy (vString *const string,
|
2008-11-12 19:37:02 +00:00
|
|
|
const statementInfo *const st)
|
2005-11-22 12:26:26 +00:00
|
|
|
{
|
2008-11-12 19:37:02 +00:00
|
|
|
const char* const anon = "<anonymous>";
|
|
|
|
boolean nonAnonPresent = FALSE;
|
2005-11-22 12:26:26 +00:00
|
|
|
|
2008-11-12 19:37:02 +00:00
|
|
|
vStringClear (string);
|
|
|
|
if (isType (st->context, TOKEN_NAME))
|
|
|
|
{
|
|
|
|
vStringCopy (string, st->context->name);
|
|
|
|
nonAnonPresent = TRUE;
|
|
|
|
}
|
|
|
|
if (st->parent != NULL)
|
2005-11-22 12:26:26 +00:00
|
|
|
{
|
2008-11-12 19:37:02 +00:00
|
|
|
vString *temp = vStringNew ();
|
|
|
|
const statementInfo *s;
|
|
|
|
|
|
|
|
for (s = st->parent ; s != NULL ; s = s->parent)
|
2005-11-22 12:26:26 +00:00
|
|
|
{
|
2008-11-24 13:35:10 +00:00
|
|
|
if (isContextualStatement (s) ||
|
|
|
|
s->declaration == DECL_NAMESPACE)
|
2008-11-12 19:37:02 +00:00
|
|
|
{
|
|
|
|
vStringCopy (temp, string);
|
|
|
|
vStringClear (string);
|
|
|
|
if (isType (s->blockName, TOKEN_NAME))
|
|
|
|
{
|
|
|
|
if (isType (s->context, TOKEN_NAME) &&
|
|
|
|
vStringLength (s->context->name) > 0)
|
|
|
|
{
|
|
|
|
vStringCat (string, s->context->name);
|
|
|
|
addContextSeparator (string);
|
|
|
|
}
|
|
|
|
vStringCat (string, s->blockName->name);
|
|
|
|
nonAnonPresent = TRUE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
vStringCopyS (string, anon);
|
|
|
|
if (vStringLength (temp) > 0)
|
|
|
|
addContextSeparator (string);
|
|
|
|
vStringCat (string, temp);
|
|
|
|
}
|
2005-11-22 12:26:26 +00:00
|
|
|
}
|
2008-11-12 19:37:02 +00:00
|
|
|
vStringDelete (temp);
|
2005-11-22 12:26:26 +00:00
|
|
|
|
2008-11-12 19:37:02 +00:00
|
|
|
if (! nonAnonPresent)
|
|
|
|
vStringClear (string);
|
|
|
|
}
|
2005-11-22 12:26:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void makeExtraTagEntry (const tagType type, tagEntryInfo *const e,
|
2008-11-12 19:37:02 +00:00
|
|
|
vString *const scope)
|
2005-11-22 12:26:26 +00:00
|
|
|
{
|
2008-11-12 19:37:02 +00:00
|
|
|
if (Option.include.qualifiedTags &&
|
|
|
|
scope != NULL && vStringLength (scope) > 0)
|
2005-11-22 12:26:26 +00:00
|
|
|
{
|
2008-11-12 19:37:02 +00:00
|
|
|
vString *const scopedName = vStringNew ();
|
|
|
|
|
|
|
|
if (type != TAG_ENUMERATOR)
|
|
|
|
vStringCopy (scopedName, scope);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* remove last component (i.e. enumeration name) from scope */
|
|
|
|
const char* const sc = vStringValue (scope);
|
|
|
|
const char* colon = strrchr (sc, ':');
|
|
|
|
if (colon != NULL)
|
|
|
|
{
|
|
|
|
while (*colon == ':' && colon > sc)
|
|
|
|
--colon;
|
|
|
|
vStringNCopy (scopedName, scope, colon + 1 - sc);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (vStringLength (scopedName) > 0)
|
|
|
|
{
|
|
|
|
addContextSeparator (scopedName);
|
|
|
|
vStringCatS (scopedName, e->name);
|
|
|
|
e->name = vStringValue (scopedName);
|
|
|
|
makeTagEntry (e);
|
|
|
|
}
|
|
|
|
vStringDelete (scopedName);
|
2005-11-22 12:26:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void makeTag (const tokenInfo *const token,
|
2008-11-12 19:37:02 +00:00
|
|
|
const statementInfo *const st,
|
|
|
|
boolean isFileScope, const tagType type)
|
2005-11-22 12:26:26 +00:00
|
|
|
{
|
|
|
|
#ifdef DEBUG_C
|
|
|
|
printToken(token);
|
|
|
|
fprintf(stderr, "<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>\n");
|
|
|
|
printStatement(st);
|
|
|
|
#endif
|
2008-11-12 19:37:02 +00:00
|
|
|
/* Nothing is really of file scope when it appears in a header file.
|
|
|
|
*/
|
|
|
|
isFileScope = (boolean) (isFileScope && ! isHeaderFile ());
|
2005-11-22 12:26:26 +00:00
|
|
|
|
2008-11-12 19:37:02 +00:00
|
|
|
if (isType (token, TOKEN_NAME) && vStringLength (token->name) > 0 /* &&
|
|
|
|
includeTag (type, isFileScope) */)
|
|
|
|
{
|
|
|
|
vString *scope = vStringNew ();
|
|
|
|
tagEntryInfo e;
|
2005-11-22 12:26:26 +00:00
|
|
|
|
2008-11-12 19:37:02 +00:00
|
|
|
/* take only functions which are introduced by "function ..." */
|
|
|
|
if (type == TAG_FUNCTION && isLanguage (Lang_ferite) &&
|
|
|
|
strncmp("function", st->firstToken->name->buffer, 8) != 0)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2006-08-27 17:39:34 +00:00
|
|
|
|
2008-11-12 19:37:02 +00:00
|
|
|
initTagEntry (&e, vStringValue (token->name));
|
2005-11-22 12:26:26 +00:00
|
|
|
|
2008-11-12 19:37:02 +00:00
|
|
|
e.lineNumber = token->lineNumber;
|
|
|
|
if (useFile())
|
|
|
|
e.filePosition = token->filePosition;
|
|
|
|
else
|
|
|
|
e.bufferPosition = token->bufferPosition;
|
|
|
|
e.isFileScope = isFileScope;
|
|
|
|
e.kindName = tagName (type);
|
|
|
|
e.kind = tagLetter (type);
|
|
|
|
e.type = type;
|
2005-11-22 12:26:26 +00:00
|
|
|
|
2008-11-12 19:37:02 +00:00
|
|
|
findScopeHierarchy (scope, st);
|
|
|
|
addOtherFields (&e, type, st, scope);
|
2005-11-22 12:26:26 +00:00
|
|
|
|
|
|
|
#ifdef DEBUG_C
|
2008-11-12 19:37:02 +00:00
|
|
|
printTagEntry(&e);
|
2005-11-22 12:26:26 +00:00
|
|
|
#endif
|
2008-11-12 19:37:02 +00:00
|
|
|
makeTagEntry (&e);
|
|
|
|
if (NULL != TagEntryFunction)
|
|
|
|
makeExtraTagEntry (type, &e, scope);
|
|
|
|
vStringDelete (scope);
|
|
|
|
if (NULL != e.extensionFields.arglist)
|
|
|
|
free((char *) e.extensionFields.arglist);
|
|
|
|
}
|
2005-11-22 12:26:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static boolean isValidTypeSpecifier (const declType declaration)
|
|
|
|
{
|
2008-11-12 19:37:02 +00:00
|
|
|
boolean result;
|
|
|
|
switch (declaration)
|
|
|
|
{
|
|
|
|
case DECL_BASE:
|
|
|
|
case DECL_CLASS:
|
|
|
|
case DECL_ENUM:
|
|
|
|
case DECL_STRUCT:
|
|
|
|
case DECL_UNION:
|
|
|
|
result = TRUE;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
result = FALSE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return result;
|
2005-11-22 12:26:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void qualifyEnumeratorTag (const statementInfo *const st,
|
2008-11-12 19:37:02 +00:00
|
|
|
const tokenInfo *const nameToken)
|
2005-11-22 12:26:26 +00:00
|
|
|
{
|
2008-11-12 19:37:02 +00:00
|
|
|
if (isType (nameToken, TOKEN_NAME))
|
|
|
|
makeTag (nameToken, st, TRUE, TAG_ENUMERATOR);
|
2005-11-22 12:26:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void qualifyFunctionTag (const statementInfo *const st,
|
2008-11-12 19:37:02 +00:00
|
|
|
const tokenInfo *const nameToken)
|
2005-11-22 12:26:26 +00:00
|
|
|
{
|
2008-11-12 19:37:02 +00:00
|
|
|
if (isType (nameToken, TOKEN_NAME))
|
|
|
|
{
|
2008-11-11 16:33:20 +00:00
|
|
|
const tagType type = (isLanguage (Lang_java) || isLanguage (Lang_csharp) || isLanguage (Lang_vala))
|
2008-11-12 19:37:02 +00:00
|
|
|
? TAG_METHOD : TAG_FUNCTION;
|
2007-10-17 11:55:59 +00:00
|
|
|
const boolean isFileScope =
|
|
|
|
(boolean) (st->member.access == ACCESS_PRIVATE ||
|
2008-11-12 19:37:02 +00:00
|
|
|
(!isMember (st) && st->scope == SCOPE_STATIC));
|
2005-11-22 12:26:26 +00:00
|
|
|
|
2007-10-17 11:55:59 +00:00
|
|
|
makeTag (nameToken, st, isFileScope, type);
|
2008-11-12 19:37:02 +00:00
|
|
|
}
|
2005-11-22 12:26:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void qualifyFunctionDeclTag (const statementInfo *const st,
|
2008-11-12 19:37:02 +00:00
|
|
|
const tokenInfo *const nameToken)
|
2005-11-22 12:26:26 +00:00
|
|
|
{
|
2008-11-12 19:37:02 +00:00
|
|
|
if (! isType (nameToken, TOKEN_NAME))
|
2007-10-17 11:55:59 +00:00
|
|
|
;
|
2008-11-12 19:37:02 +00:00
|
|
|
else if (isLanguage (Lang_java) || isLanguage (Lang_csharp) || isLanguage (Lang_vala))
|
2007-06-22 17:22:07 +00:00
|
|
|
qualifyFunctionTag (st, nameToken);
|
2008-11-12 19:37:02 +00:00
|
|
|
else if (st->scope == SCOPE_TYPEDEF)
|
2007-06-22 17:22:07 +00:00
|
|
|
makeTag (nameToken, st, TRUE, TAG_TYPEDEF);
|
2008-11-12 19:37:02 +00:00
|
|
|
else if (isValidTypeSpecifier (st->declaration) &&
|
|
|
|
! (isLanguage (Lang_csharp) || isLanguage (Lang_vala)))
|
2007-06-22 17:22:07 +00:00
|
|
|
makeTag (nameToken, st, TRUE, TAG_PROTOTYPE);
|
2005-11-22 12:26:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void qualifyCompoundTag (const statementInfo *const st,
|
2008-11-12 19:37:02 +00:00
|
|
|
const tokenInfo *const nameToken)
|
2005-11-22 12:26:26 +00:00
|
|
|
{
|
2008-11-12 19:37:02 +00:00
|
|
|
if (isType (nameToken, TOKEN_NAME))
|
|
|
|
{
|
|
|
|
const tagType type = declToTagType (st->declaration);
|
2005-11-22 12:26:26 +00:00
|
|
|
|
2008-11-12 19:37:02 +00:00
|
|
|
if (type != TAG_UNDEFINED)
|
|
|
|
makeTag (nameToken, st, (boolean) (! isLanguage (Lang_java) &&
|
|
|
|
! isLanguage (Lang_csharp) &&
|
|
|
|
! isLanguage (Lang_vala)), type);
|
2005-11-22 12:26:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void qualifyBlockTag (statementInfo *const st,
|
2008-11-12 19:37:02 +00:00
|
|
|
const tokenInfo *const nameToken)
|
2005-11-22 12:26:26 +00:00
|
|
|
{
|
2008-11-12 19:37:02 +00:00
|
|
|
switch (st->declaration)
|
|
|
|
{
|
|
|
|
case DECL_CLASS:
|
|
|
|
case DECL_ENUM:
|
|
|
|
case DECL_INTERFACE:
|
|
|
|
case DECL_NAMESPACE:
|
|
|
|
case DECL_STRUCT:
|
|
|
|
case DECL_UNION:
|
|
|
|
qualifyCompoundTag (st, nameToken);
|
|
|
|
break;
|
|
|
|
default: break;
|
|
|
|
}
|
2005-11-22 12:26:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void qualifyVariableTag (const statementInfo *const st,
|
2008-11-12 19:37:02 +00:00
|
|
|
const tokenInfo *const nameToken)
|
2005-11-22 12:26:26 +00:00
|
|
|
{
|
2008-11-12 19:37:02 +00:00
|
|
|
/* We have to watch that we do not interpret a declaration of the
|
|
|
|
* form "struct tag;" as a variable definition. In such a case, the
|
|
|
|
* token preceding the name will be a keyword.
|
|
|
|
*/
|
|
|
|
if (! isType (nameToken, TOKEN_NAME))
|
|
|
|
;
|
|
|
|
else if (st->declaration == DECL_IGNORE)
|
|
|
|
;
|
|
|
|
else if (st->scope == SCOPE_TYPEDEF)
|
|
|
|
makeTag (nameToken, st, TRUE, TAG_TYPEDEF);
|
|
|
|
else if (st->declaration == DECL_PACKAGE)
|
|
|
|
makeTag (nameToken, st, FALSE, TAG_PACKAGE);
|
|
|
|
else if (st->declaration == DECL_MODULE) /* handle modules in D as namespaces */
|
|
|
|
makeTag (nameToken, st, FALSE, TAG_NAMESPACE);
|
|
|
|
else if (isValidTypeSpecifier (st->declaration))
|
2005-11-22 12:26:26 +00:00
|
|
|
{
|
2008-11-12 19:37:02 +00:00
|
|
|
if (isMember (st))
|
|
|
|
{
|
|
|
|
if (isLanguage (Lang_java) || isLanguage (Lang_csharp) || isLanguage (Lang_vala))
|
|
|
|
makeTag (nameToken, st, (boolean) (st->member.access == ACCESS_PRIVATE), TAG_FIELD);
|
|
|
|
else if (st->scope == SCOPE_GLOBAL || st->scope == SCOPE_STATIC)
|
|
|
|
makeTag (nameToken, st, TRUE, TAG_MEMBER);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (st->scope == SCOPE_EXTERN || ! st->haveQualifyingName)
|
|
|
|
makeTag (nameToken, st, FALSE, TAG_EXTERN_VAR);
|
|
|
|
else
|
|
|
|
makeTag (nameToken, st, (boolean) (st->scope == SCOPE_STATIC), TAG_VARIABLE);
|
|
|
|
}
|
2005-11-22 12:26:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Parsing functions
|
|
|
|
*/
|
|
|
|
|
2007-06-22 17:22:07 +00:00
|
|
|
static int skipToOneOf (const char *const chars)
|
|
|
|
{
|
|
|
|
int c;
|
|
|
|
do
|
|
|
|
c = cppGetc ();
|
|
|
|
while (c != EOF && c != '\0' && strchr (chars, c) == NULL);
|
2008-11-12 19:37:02 +00:00
|
|
|
|
2007-06-22 17:22:07 +00:00
|
|
|
return c;
|
|
|
|
}
|
|
|
|
|
2005-11-22 12:26:26 +00:00
|
|
|
/* Skip to the next non-white character.
|
|
|
|
*/
|
|
|
|
static int skipToNonWhite (void)
|
|
|
|
{
|
2008-11-12 19:37:02 +00:00
|
|
|
int c;
|
2005-11-22 12:26:26 +00:00
|
|
|
|
2008-11-12 19:37:02 +00:00
|
|
|
do
|
2007-01-16 13:18:37 +00:00
|
|
|
{
|
|
|
|
c = cppGetc ();
|
|
|
|
}
|
2008-11-12 19:37:02 +00:00
|
|
|
while (isspace (c));
|
2005-11-22 12:26:26 +00:00
|
|
|
|
2008-11-12 19:37:02 +00:00
|
|
|
return c;
|
2005-11-22 12:26:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Skips to the next brace in column 1. This is intended for cases where
|
|
|
|
* preprocessor constructs result in unbalanced braces.
|
|
|
|
*/
|
|
|
|
static void skipToFormattedBraceMatch (void)
|
|
|
|
{
|
2008-11-12 19:37:02 +00:00
|
|
|
int c, next;
|
2005-11-22 12:26:26 +00:00
|
|
|
|
2008-11-12 19:37:02 +00:00
|
|
|
c = cppGetc ();
|
2005-11-22 12:26:26 +00:00
|
|
|
next = cppGetc ();
|
2008-11-12 19:37:02 +00:00
|
|
|
while (c != EOF && (c != '\n' || next != '}'))
|
|
|
|
{
|
|
|
|
c = next;
|
|
|
|
next = cppGetc ();
|
|
|
|
}
|
2005-11-22 12:26:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Skip to the matching character indicated by the pair string. If skipping
|
|
|
|
* to a matching brace and any brace is found within a different level of a
|
|
|
|
* #if conditional statement while brace formatting is in effect, we skip to
|
|
|
|
* the brace matched by its formatting. It is assumed that we have already
|
|
|
|
* read the character which starts the group (i.e. the first character of
|
|
|
|
* "pair").
|
|
|
|
*/
|
|
|
|
static void skipToMatch (const char *const pair)
|
|
|
|
{
|
2008-11-12 19:37:02 +00:00
|
|
|
const boolean braceMatching = (boolean) (strcmp ("{}", pair) == 0);
|
|
|
|
const boolean braceFormatting = (boolean) (isBraceFormat () && braceMatching);
|
|
|
|
const unsigned int initialLevel = getDirectiveNestLevel ();
|
|
|
|
const int begin = pair [0], end = pair [1];
|
|
|
|
const unsigned long inputLineNumber = getInputLineNumber ();
|
|
|
|
int matchLevel = 1;
|
|
|
|
int c = '\0';
|
|
|
|
while (matchLevel > 0 && (c = cppGetc ()) != EOF)
|
2005-11-22 12:26:26 +00:00
|
|
|
{
|
2008-11-12 19:37:02 +00:00
|
|
|
if (c == begin)
|
|
|
|
{
|
|
|
|
++matchLevel;
|
|
|
|
if (braceFormatting && getDirectiveNestLevel () != initialLevel)
|
|
|
|
{
|
|
|
|
skipToFormattedBraceMatch ();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (c == end)
|
|
|
|
{
|
|
|
|
--matchLevel;
|
|
|
|
if (braceFormatting && getDirectiveNestLevel () != initialLevel)
|
|
|
|
{
|
|
|
|
skipToFormattedBraceMatch ();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (c == EOF)
|
|
|
|
{
|
|
|
|
verbose ("%s: failed to find match for '%c' at line %lu\n",
|
|
|
|
getInputFileName (), begin, inputLineNumber);
|
|
|
|
if (braceMatching)
|
|
|
|
longjmp (Exception, (int) ExceptionBraceFormattingError);
|
|
|
|
else
|
|
|
|
longjmp (Exception, (int) ExceptionFormattingError);
|
|
|
|
}
|
2005-11-22 12:26:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void skipParens (void)
|
|
|
|
{
|
2008-11-12 19:37:02 +00:00
|
|
|
const int c = skipToNonWhite ();
|
2005-11-22 12:26:26 +00:00
|
|
|
|
2008-11-12 19:37:02 +00:00
|
|
|
if (c == '(')
|
|
|
|
skipToMatch ("()");
|
|
|
|
else
|
|
|
|
cppUngetc (c);
|
2005-11-22 12:26:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void skipBraces (void)
|
|
|
|
{
|
2008-11-12 19:37:02 +00:00
|
|
|
const int c = skipToNonWhite ();
|
2005-11-22 12:26:26 +00:00
|
|
|
|
2008-11-12 19:37:02 +00:00
|
|
|
if (c == '{')
|
|
|
|
skipToMatch ("{}");
|
|
|
|
else
|
|
|
|
cppUngetc (c);
|
2005-11-22 12:26:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static keywordId analyzeKeyword (const char *const name)
|
|
|
|
{
|
2008-11-12 19:37:02 +00:00
|
|
|
const keywordId id = (keywordId) lookupKeyword (name, getSourceLanguage ());
|
|
|
|
return id;
|
2005-11-22 12:26:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void analyzeIdentifier (tokenInfo *const token)
|
|
|
|
{
|
2008-11-12 19:37:02 +00:00
|
|
|
char *const name = vStringValue (token->name);
|
|
|
|
const char *replacement = NULL;
|
|
|
|
boolean parensToo = FALSE;
|
2005-11-22 12:26:26 +00:00
|
|
|
|
2008-11-12 19:37:02 +00:00
|
|
|
if (isLanguage (Lang_java) ||
|
|
|
|
! isIgnoreToken (name, &parensToo, &replacement))
|
|
|
|
{
|
|
|
|
if (replacement != NULL)
|
|
|
|
token->keyword = analyzeKeyword (replacement);
|
|
|
|
else
|
|
|
|
token->keyword = analyzeKeyword (vStringValue (token->name));
|
2005-11-22 12:26:26 +00:00
|
|
|
|
2008-11-12 19:37:02 +00:00
|
|
|
if (token->keyword == KEYWORD_NONE)
|
|
|
|
token->type = TOKEN_NAME;
|
|
|
|
else
|
|
|
|
token->type = TOKEN_KEYWORD;
|
|
|
|
}
|
2005-11-22 12:26:26 +00:00
|
|
|
else
|
|
|
|
{
|
2008-11-12 19:37:02 +00:00
|
|
|
initToken (token);
|
|
|
|
if (parensToo)
|
|
|
|
{
|
|
|
|
int c = skipToNonWhite ();
|
2005-11-22 12:26:26 +00:00
|
|
|
|
2008-11-12 19:37:02 +00:00
|
|
|
if (c == '(')
|
|
|
|
skipToMatch ("()");
|
|
|
|
}
|
2005-11-22 12:26:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void readIdentifier (tokenInfo *const token, const int firstChar)
|
|
|
|
{
|
2008-11-12 19:37:02 +00:00
|
|
|
vString *const name = token->name;
|
|
|
|
int c = firstChar;
|
2005-11-22 12:26:26 +00:00
|
|
|
|
2008-11-12 19:37:02 +00:00
|
|
|
initToken (token);
|
2005-11-22 12:26:26 +00:00
|
|
|
|
2008-11-12 19:37:02 +00:00
|
|
|
/* Bug #1585745 (CTags): strangely, C++ destructors allow whitespace between
|
|
|
|
* the ~ and the class name. */
|
2007-06-29 15:42:37 +00:00
|
|
|
if (isLanguage (Lang_cpp) && firstChar == '~')
|
|
|
|
{
|
|
|
|
vStringPut (name, c);
|
|
|
|
c = skipToNonWhite ();
|
|
|
|
}
|
|
|
|
|
2008-11-12 19:37:02 +00:00
|
|
|
do
|
|
|
|
{
|
|
|
|
vStringPut (name, c);
|
|
|
|
c = cppGetc ();
|
2008-12-09 19:00:45 +00:00
|
|
|
} while (isident (c) || (isLanguage (Lang_vala) && '.' == c));
|
2008-11-12 19:37:02 +00:00
|
|
|
vStringTerminate (name);
|
|
|
|
cppUngetc (c); /* unget non-identifier character */
|
2005-11-22 12:26:26 +00:00
|
|
|
|
2008-12-09 19:00:45 +00:00
|
|
|
/* Vala supports '?' at end of a type (with or without whitspace before) for nullable types */
|
|
|
|
if (isLanguage (Lang_vala))
|
|
|
|
{
|
|
|
|
c = skipToNonWhite ();
|
|
|
|
if ('?' == c)
|
|
|
|
vStringPut (name, c);
|
|
|
|
else
|
|
|
|
cppUngetc (c);
|
|
|
|
}
|
|
|
|
|
2008-11-12 19:37:02 +00:00
|
|
|
analyzeIdentifier (token);
|
2005-11-22 12:26:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void readPackageName (tokenInfo *const token, const int firstChar)
|
|
|
|
{
|
2008-11-12 19:37:02 +00:00
|
|
|
vString *const name = token->name;
|
|
|
|
int c = firstChar;
|
2005-11-22 12:26:26 +00:00
|
|
|
|
2008-11-12 19:37:02 +00:00
|
|
|
initToken (token);
|
2005-11-22 12:26:26 +00:00
|
|
|
|
2008-11-12 19:37:02 +00:00
|
|
|
while (isident (c) || c == '.')
|
|
|
|
{
|
|
|
|
vStringPut (name, c);
|
|
|
|
c = cppGetc ();
|
|
|
|
}
|
|
|
|
vStringTerminate (name);
|
|
|
|
cppUngetc (c); /* unget non-package character */
|
2005-11-22 12:26:26 +00:00
|
|
|
}
|
|
|
|
|
2007-06-22 17:22:07 +00:00
|
|
|
static void readPackageOrNamespace (statementInfo *const st, const declType declaration)
|
|
|
|
{
|
|
|
|
st->declaration = declaration;
|
|
|
|
|
2008-11-11 16:33:20 +00:00
|
|
|
if (declaration == DECL_NAMESPACE && !(isLanguage (Lang_csharp) || isLanguage (Lang_vala)))
|
2007-06-22 17:22:07 +00:00
|
|
|
{
|
|
|
|
/* In C++ a namespace is specified one level at a time. */
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* In C#, a namespace can also be specified like a Java package name. */
|
|
|
|
tokenInfo *const token = activeToken (st);
|
|
|
|
Assert (isType (token, TOKEN_KEYWORD));
|
|
|
|
readPackageName (token, skipToNonWhite ());
|
|
|
|
token->type = TOKEN_NAME;
|
|
|
|
st->gotName = TRUE;
|
|
|
|
st->haveQualifyingName = TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-11-22 12:26:26 +00:00
|
|
|
static void readPackage (statementInfo *const st)
|
|
|
|
{
|
2008-11-12 19:37:02 +00:00
|
|
|
tokenInfo *const token = activeToken (st);
|
|
|
|
Assert (isType (token, TOKEN_KEYWORD));
|
|
|
|
readPackageName (token, skipToNonWhite ());
|
|
|
|
token->type = TOKEN_NAME;
|
|
|
|
if (isLanguage (Lang_d))
|
2006-10-18 20:11:05 +00:00
|
|
|
st->declaration = DECL_MODULE;
|
|
|
|
else
|
|
|
|
st->declaration = DECL_PACKAGE;
|
2008-11-12 19:37:02 +00:00
|
|
|
st->gotName = TRUE;
|
|
|
|
st->haveQualifyingName = TRUE;
|
2005-11-22 12:26:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void processName (statementInfo *const st)
|
|
|
|
{
|
2008-11-12 19:37:02 +00:00
|
|
|
Assert (isType (activeToken (st), TOKEN_NAME));
|
|
|
|
if (st->gotName && st->declaration == DECL_NONE)
|
|
|
|
st->declaration = DECL_BASE;
|
|
|
|
st->gotName = TRUE;
|
|
|
|
st->haveQualifyingName = TRUE;
|
2005-11-22 12:26:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void readOperator (statementInfo *const st)
|
|
|
|
{
|
2008-11-12 19:37:02 +00:00
|
|
|
const char *const acceptable = "+-*/%^&|~!=<>,[]";
|
|
|
|
const tokenInfo* const prev = prevToken (st,1);
|
|
|
|
tokenInfo *const token = activeToken (st);
|
|
|
|
vString *const name = token->name;
|
|
|
|
int c = skipToNonWhite ();
|
2005-11-22 12:26:26 +00:00
|
|
|
|
2008-11-12 19:37:02 +00:00
|
|
|
/* When we arrive here, we have the keyword "operator" in 'name'.
|
2005-11-22 12:26:26 +00:00
|
|
|
*/
|
2008-11-12 19:37:02 +00:00
|
|
|
if (isType (prev, TOKEN_KEYWORD) && (prev->keyword == KEYWORD_ENUM ||
|
|
|
|
prev->keyword == KEYWORD_STRUCT || prev->keyword == KEYWORD_UNION))
|
|
|
|
; /* ignore "operator" keyword if preceded by these keywords */
|
|
|
|
else if (c == '(')
|
2005-11-22 12:26:26 +00:00
|
|
|
{
|
2008-11-12 19:37:02 +00:00
|
|
|
/* Verify whether this is a valid function call (i.e. "()") operator.
|
|
|
|
*/
|
|
|
|
if (cppGetc () == ')')
|
|
|
|
{
|
|
|
|
vStringPut (name, ' '); /* always separate operator from keyword */
|
|
|
|
c = skipToNonWhite ();
|
|
|
|
if (c == '(')
|
|
|
|
vStringCatS (name, "()");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
skipToMatch ("()");
|
|
|
|
c = cppGetc ();
|
|
|
|
}
|
2005-11-22 12:26:26 +00:00
|
|
|
}
|
2008-11-12 19:37:02 +00:00
|
|
|
else if (isident1 (c))
|
2005-11-22 12:26:26 +00:00
|
|
|
{
|
2008-11-12 19:37:02 +00:00
|
|
|
/* Handle "new" and "delete" operators, and conversion functions
|
|
|
|
* (per 13.3.1.1.2 [2] of the C++ spec).
|
|
|
|
*/
|
|
|
|
boolean whiteSpace = TRUE; /* default causes insertion of space */
|
|
|
|
do
|
|
|
|
{
|
|
|
|
if (isspace (c))
|
|
|
|
whiteSpace = TRUE;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (whiteSpace)
|
|
|
|
{
|
|
|
|
vStringPut (name, ' ');
|
|
|
|
whiteSpace = FALSE;
|
|
|
|
}
|
|
|
|
vStringPut (name, c);
|
|
|
|
}
|
|
|
|
c = cppGetc ();
|
|
|
|
} while (! isOneOf (c, "(;") && c != EOF);
|
|
|
|
vStringTerminate (name);
|
2005-11-22 12:26:26 +00:00
|
|
|
}
|
2008-11-12 19:37:02 +00:00
|
|
|
else if (isOneOf (c, acceptable))
|
2005-11-22 12:26:26 +00:00
|
|
|
{
|
2008-11-12 19:37:02 +00:00
|
|
|
vStringPut (name, ' '); /* always separate operator from keyword */
|
|
|
|
do
|
2005-11-22 12:26:26 +00:00
|
|
|
{
|
2008-11-12 19:37:02 +00:00
|
|
|
vStringPut (name, c);
|
|
|
|
c = cppGetc ();
|
|
|
|
} while (isOneOf (c, acceptable));
|
|
|
|
vStringTerminate (name);
|
|
|
|
}
|
2005-11-22 12:26:26 +00:00
|
|
|
|
2008-11-12 19:37:02 +00:00
|
|
|
cppUngetc (c);
|
2005-11-22 12:26:26 +00:00
|
|
|
|
2008-11-12 19:37:02 +00:00
|
|
|
token->type = TOKEN_NAME;
|
|
|
|
token->keyword = KEYWORD_NONE;
|
|
|
|
processName (st);
|
2005-11-22 12:26:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void copyToken (tokenInfo *const dest, const tokenInfo *const src)
|
|
|
|
{
|
2008-11-12 19:37:02 +00:00
|
|
|
dest->type = src->type;
|
|
|
|
dest->keyword = src->keyword;
|
2008-11-07 14:37:17 +00:00
|
|
|
if (useFile())
|
|
|
|
dest->filePosition = src->filePosition;
|
|
|
|
else
|
|
|
|
dest->bufferPosition = src->bufferPosition;
|
2008-11-12 19:37:02 +00:00
|
|
|
dest->lineNumber = src->lineNumber;
|
|
|
|
vStringCopy (dest->name, src->name);
|
2005-11-22 12:26:26 +00:00
|
|
|
}
|
|
|
|
|
2007-06-29 15:42:37 +00:00
|
|
|
static void setAccess (statementInfo *const st, const accessType laccess)
|
2005-11-22 12:26:26 +00:00
|
|
|
{
|
2008-11-12 19:37:02 +00:00
|
|
|
if (isMember (st))
|
2005-11-22 12:26:26 +00:00
|
|
|
{
|
2008-11-12 19:37:02 +00:00
|
|
|
if (isLanguage (Lang_cpp) || isLanguage (Lang_d) || isLanguage (Lang_ferite))
|
|
|
|
{
|
|
|
|
int c = skipToNonWhite ();
|
2005-11-22 12:26:26 +00:00
|
|
|
|
2008-11-12 19:37:02 +00:00
|
|
|
if (c == ':')
|
|
|
|
reinitStatementWithToken (st, prevToken (st, 1), FALSE);
|
|
|
|
else
|
|
|
|
cppUngetc (c);
|
2005-11-22 12:26:26 +00:00
|
|
|
|
2008-11-12 19:37:02 +00:00
|
|
|
st->member.accessDefault = laccess;
|
|
|
|
}
|
|
|
|
st->member.access = laccess;
|
2005-11-22 12:26:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void discardTypeList (tokenInfo *const token)
|
|
|
|
{
|
2008-11-12 19:37:02 +00:00
|
|
|
int c = skipToNonWhite ();
|
|
|
|
while (isident1 (c))
|
|
|
|
{
|
|
|
|
readIdentifier (token, c);
|
|
|
|
c = skipToNonWhite ();
|
|
|
|
if (c == '.' || c == ',')
|
|
|
|
c = skipToNonWhite ();
|
|
|
|
}
|
|
|
|
cppUngetc (c);
|
2005-11-22 12:26:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void addParentClass (statementInfo *const st, tokenInfo *const token)
|
|
|
|
{
|
2008-11-12 19:37:02 +00:00
|
|
|
if (vStringLength (token->name) > 0 &&
|
|
|
|
vStringLength (st->parentClasses) > 0)
|
|
|
|
{
|
|
|
|
vStringPut (st->parentClasses, ',');
|
|
|
|
}
|
|
|
|
vStringCat (st->parentClasses, token->name);
|
2005-11-22 12:26:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void readParents (statementInfo *const st, const int qualifier)
|
|
|
|
{
|
2008-11-12 19:37:02 +00:00
|
|
|
tokenInfo *const token = newToken ();
|
|
|
|
tokenInfo *const parent = newToken ();
|
|
|
|
int c;
|
2005-11-22 12:26:26 +00:00
|
|
|
|
2008-11-12 19:37:02 +00:00
|
|
|
do
|
2005-11-22 12:26:26 +00:00
|
|
|
{
|
2008-11-12 19:37:02 +00:00
|
|
|
c = skipToNonWhite ();
|
|
|
|
if (isident1 (c))
|
|
|
|
{
|
|
|
|
readIdentifier (token, c);
|
|
|
|
if (isType (token, TOKEN_NAME))
|
|
|
|
vStringCat (parent->name, token->name);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
addParentClass (st, parent);
|
|
|
|
initToken (parent);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (c == qualifier)
|
|
|
|
vStringPut (parent->name, c);
|
|
|
|
else if (c == '<')
|
|
|
|
skipToMatch ("<>");
|
|
|
|
else if (isType (token, TOKEN_NAME))
|
|
|
|
{
|
|
|
|
addParentClass (st, parent);
|
|
|
|
initToken (parent);
|
|
|
|
}
|
|
|
|
} while (c != '{' && c != EOF);
|
|
|
|
cppUngetc (c);
|
|
|
|
deleteToken (parent);
|
|
|
|
deleteToken (token);
|
2005-11-22 12:26:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void processToken (tokenInfo *const token, statementInfo *const st)
|
|
|
|
{
|
2008-11-12 19:37:02 +00:00
|
|
|
switch (token->keyword) /* is it a reserved word? */
|
|
|
|
{
|
|
|
|
default: break;
|
|
|
|
|
|
|
|
case KEYWORD_NONE: processName (st); break;
|
|
|
|
case KEYWORD_ABSTRACT: st->implementation = IMP_ABSTRACT; break;
|
|
|
|
case KEYWORD_ATTRIBUTE: skipParens (); initToken (token); break;
|
|
|
|
case KEYWORD_CATCH: skipParens (); skipBraces (); break;
|
|
|
|
case KEYWORD_CHAR: st->declaration = DECL_BASE; break;
|
|
|
|
case KEYWORD_CLASS: st->declaration = DECL_CLASS; break;
|
|
|
|
case KEYWORD_CONST: st->declaration = DECL_BASE; break;
|
|
|
|
case KEYWORD_DOUBLE: st->declaration = DECL_BASE; break;
|
|
|
|
case KEYWORD_ENUM: st->declaration = DECL_ENUM; break;
|
|
|
|
case KEYWORD_EXTENDS: readParents (st, '.');
|
|
|
|
setToken (st, TOKEN_NONE); break;
|
|
|
|
case KEYWORD_FLOAT: st->declaration = DECL_BASE; break;
|
|
|
|
case KEYWORD_FRIEND: st->scope = SCOPE_FRIEND; break;
|
|
|
|
case KEYWORD_IMPLEMENTS:readParents (st, '.');
|
|
|
|
setToken (st, TOKEN_NONE); break;
|
|
|
|
case KEYWORD_IMPORT: st->declaration = DECL_IGNORE; break;
|
|
|
|
case KEYWORD_INT: st->declaration = DECL_BASE; break;
|
|
|
|
case KEYWORD_BOOLEAN: st->declaration = DECL_BASE; break;
|
|
|
|
case KEYWORD_WCHAR_T: st->declaration = DECL_BASE; break;
|
|
|
|
case KEYWORD_SIZE_T: st->declaration = DECL_BASE; break;
|
|
|
|
case KEYWORD_INTERFACE: st->declaration = DECL_INTERFACE; break;
|
|
|
|
case KEYWORD_LONG: st->declaration = DECL_BASE; break;
|
|
|
|
case KEYWORD_OPERATOR: readOperator (st); break;
|
|
|
|
case KEYWORD_MODULE: readPackage (st); break;
|
|
|
|
case KEYWORD_PRIVATE: setAccess (st, ACCESS_PRIVATE); break;
|
|
|
|
case KEYWORD_PROTECTED: setAccess (st, ACCESS_PROTECTED); break;
|
|
|
|
case KEYWORD_PUBLIC: setAccess (st, ACCESS_PUBLIC); break;
|
|
|
|
case KEYWORD_SHORT: st->declaration = DECL_BASE; break;
|
|
|
|
case KEYWORD_SIGNED: st->declaration = DECL_BASE; break;
|
|
|
|
case KEYWORD_STRUCT: st->declaration = DECL_STRUCT; break;
|
|
|
|
case KEYWORD_THROWS: discardTypeList (token); break;
|
|
|
|
case KEYWORD_TYPEDEF: st->scope = SCOPE_TYPEDEF; break;
|
|
|
|
case KEYWORD_UNION: st->declaration = DECL_UNION; break;
|
|
|
|
case KEYWORD_UNSIGNED: st->declaration = DECL_BASE; break;
|
|
|
|
case KEYWORD_USING: st->declaration = DECL_IGNORE; break;
|
|
|
|
case KEYWORD_VOID: st->declaration = DECL_BASE; break;
|
|
|
|
case KEYWORD_VOLATILE: st->declaration = DECL_BASE; break;
|
|
|
|
case KEYWORD_VIRTUAL: st->implementation = IMP_VIRTUAL; break;
|
|
|
|
|
|
|
|
case KEYWORD_NAMESPACE: readPackageOrNamespace (st, DECL_NAMESPACE); break;
|
|
|
|
case KEYWORD_PACKAGE: readPackageOrNamespace (st, DECL_PACKAGE); break;
|
|
|
|
case KEYWORD_EVENT:
|
2007-06-22 17:22:07 +00:00
|
|
|
{
|
2008-11-12 19:37:02 +00:00
|
|
|
if (isLanguage (Lang_csharp))
|
|
|
|
st->declaration = DECL_EVENT;
|
|
|
|
break;
|
2007-06-22 17:22:07 +00:00
|
|
|
}
|
2008-11-12 19:37:02 +00:00
|
|
|
case KEYWORD_SIGNAL:
|
2007-06-22 17:22:07 +00:00
|
|
|
{
|
2008-11-12 19:37:02 +00:00
|
|
|
if (isLanguage (Lang_vala))
|
|
|
|
st->declaration = DECL_SIGNAL;
|
|
|
|
break;
|
2007-06-22 17:22:07 +00:00
|
|
|
}
|
2008-11-12 19:37:02 +00:00
|
|
|
case KEYWORD_EXTERN:
|
|
|
|
{
|
|
|
|
if (! isLanguage (Lang_csharp) || !st->gotName)
|
|
|
|
{
|
|
|
|
/*reinitStatement (st, FALSE);*/
|
|
|
|
st->scope = SCOPE_EXTERN;
|
|
|
|
st->declaration = DECL_BASE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case KEYWORD_STATIC:
|
|
|
|
{
|
|
|
|
if (! isLanguage (Lang_java) && ! isLanguage (Lang_csharp) && ! isLanguage (Lang_vala))
|
|
|
|
{
|
|
|
|
/*reinitStatement (st, FALSE);*/
|
|
|
|
st->scope = SCOPE_STATIC;
|
|
|
|
st->declaration = DECL_BASE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2005-11-22 12:26:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Parenthesis handling functions
|
|
|
|
*/
|
|
|
|
|
|
|
|
static void restartStatement (statementInfo *const st)
|
|
|
|
{
|
2008-11-12 19:37:02 +00:00
|
|
|
tokenInfo *const save = newToken ();
|
|
|
|
tokenInfo *token = activeToken (st);
|
2005-11-22 12:26:26 +00:00
|
|
|
|
2008-11-12 19:37:02 +00:00
|
|
|
copyToken (save, token);
|
|
|
|
DebugStatement ( if (debug (DEBUG_PARSE)) printf ("<ES>");)
|
|
|
|
reinitStatement (st, FALSE);
|
|
|
|
token = activeToken (st);
|
|
|
|
copyToken (token, save);
|
|
|
|
deleteToken (save);
|
|
|
|
processToken (token, st);
|
2005-11-22 12:26:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Skips over a the mem-initializer-list of a ctor-initializer, defined as:
|
|
|
|
*
|
|
|
|
* mem-initializer-list:
|
|
|
|
* mem-initializer, mem-initializer-list
|
|
|
|
*
|
|
|
|
* mem-initializer:
|
|
|
|
* [::] [nested-name-spec] class-name (...)
|
|
|
|
* identifier
|
|
|
|
*/
|
|
|
|
static void skipMemIntializerList (tokenInfo *const token)
|
|
|
|
{
|
2008-11-12 19:37:02 +00:00
|
|
|
int c;
|
2005-11-22 12:26:26 +00:00
|
|
|
|
2008-11-12 19:37:02 +00:00
|
|
|
do
|
2005-11-22 12:26:26 +00:00
|
|
|
{
|
2008-11-12 19:37:02 +00:00
|
|
|
c = skipToNonWhite ();
|
|
|
|
while (isident1 (c) || c == ':')
|
|
|
|
{
|
|
|
|
if (c != ':')
|
|
|
|
readIdentifier (token, c);
|
|
|
|
c = skipToNonWhite ();
|
|
|
|
}
|
|
|
|
if (c == '<')
|
|
|
|
{
|
|
|
|
skipToMatch ("<>");
|
|
|
|
c = skipToNonWhite ();
|
|
|
|
}
|
|
|
|
if (c == '(')
|
|
|
|
{
|
|
|
|
skipToMatch ("()");
|
|
|
|
c = skipToNonWhite ();
|
|
|
|
}
|
|
|
|
} while (c == ',');
|
|
|
|
cppUngetc (c);
|
2005-11-22 12:26:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void skipMacro (statementInfo *const st)
|
|
|
|
{
|
2008-11-12 19:37:02 +00:00
|
|
|
tokenInfo *const prev2 = prevToken (st, 2);
|
2005-11-22 12:26:26 +00:00
|
|
|
|
2008-11-12 19:37:02 +00:00
|
|
|
if (isType (prev2, TOKEN_NAME))
|
|
|
|
retardToken (st);
|
|
|
|
skipToMatch ("()");
|
2005-11-22 12:26:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Skips over characters following the parameter list. This will be either
|
|
|
|
* non-ANSI style function declarations or C++ stuff. Our choices:
|
|
|
|
*
|
|
|
|
* C (K&R):
|
|
|
|
* int func ();
|
|
|
|
* int func (one, two) int one; float two; {...}
|
|
|
|
* C (ANSI):
|
|
|
|
* int func (int one, float two);
|
|
|
|
* int func (int one, float two) {...}
|
|
|
|
* C++:
|
|
|
|
* int foo (...) [const|volatile] [throw (...)];
|
|
|
|
* int foo (...) [const|volatile] [throw (...)] [ctor-initializer] {...}
|
|
|
|
* int foo (...) [const|volatile] [throw (...)] try [ctor-initializer] {...}
|
|
|
|
* catch (...) {...}
|
|
|
|
*/
|
|
|
|
static boolean skipPostArgumentStuff (statementInfo *const st,
|
2008-11-12 19:37:02 +00:00
|
|
|
parenInfo *const info)
|
2005-11-22 12:26:26 +00:00
|
|
|
{
|
2008-11-12 19:37:02 +00:00
|
|
|
tokenInfo *const token = activeToken (st);
|
|
|
|
unsigned int parameters = info->parameterCount;
|
|
|
|
unsigned int elementCount = 0;
|
|
|
|
boolean restart = FALSE;
|
|
|
|
boolean end = FALSE;
|
|
|
|
int c = skipToNonWhite ();
|
2005-11-22 12:26:26 +00:00
|
|
|
|
2008-11-12 19:37:02 +00:00
|
|
|
do
|
|
|
|
{
|
|
|
|
switch (c)
|
2005-11-22 12:26:26 +00:00
|
|
|
{
|
2008-11-12 19:37:02 +00:00
|
|
|
case ')': break;
|
|
|
|
case ':': skipMemIntializerList (token);break; /* ctor-initializer */
|
|
|
|
case '[': skipToMatch ("[]"); break;
|
|
|
|
case '=': cppUngetc (c); end = TRUE; break;
|
|
|
|
case '{': cppUngetc (c); end = TRUE; break;
|
|
|
|
case '}': cppUngetc (c); end = TRUE; break;
|
|
|
|
|
|
|
|
case '(':
|
|
|
|
{
|
|
|
|
if (elementCount > 0)
|
|
|
|
++elementCount;
|
|
|
|
skipToMatch ("()");
|
|
|
|
break;
|
|
|
|
}
|
2005-11-22 12:26:26 +00:00
|
|
|
|
2008-11-12 19:37:02 +00:00
|
|
|
case ';':
|
|
|
|
{
|
|
|
|
if (parameters == 0 || elementCount < 2)
|
|
|
|
{
|
|
|
|
cppUngetc (c);
|
|
|
|
end = TRUE;
|
|
|
|
}
|
|
|
|
else if (--parameters == 0)
|
|
|
|
end = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
{
|
|
|
|
if (isident1 (c))
|
|
|
|
{
|
|
|
|
readIdentifier (token, c);
|
2009-11-06 13:03:28 +00:00
|
|
|
if (isLanguage(Lang_d))
|
|
|
|
{ /* parse D contracts */
|
|
|
|
switch (token->keyword)
|
|
|
|
{
|
|
|
|
case KEYWORD_IN:
|
|
|
|
case KEYWORD_OUT:
|
|
|
|
case KEYWORD_BODY:
|
|
|
|
token->keyword = KEYWORD_CONST;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2008-11-12 19:37:02 +00:00
|
|
|
switch (token->keyword)
|
|
|
|
{
|
|
|
|
case KEYWORD_ATTRIBUTE: skipParens (); break;
|
|
|
|
case KEYWORD_THROW: skipParens (); break;
|
|
|
|
case KEYWORD_CONST: break;
|
|
|
|
case KEYWORD_TRY: break;
|
|
|
|
case KEYWORD_VOLATILE: break;
|
|
|
|
|
|
|
|
case KEYWORD_CATCH: case KEYWORD_CLASS:
|
|
|
|
case KEYWORD_EXPLICIT: case KEYWORD_EXTERN:
|
|
|
|
case KEYWORD_FRIEND: case KEYWORD_INLINE:
|
|
|
|
case KEYWORD_MUTABLE: case KEYWORD_NAMESPACE:
|
|
|
|
case KEYWORD_NEW: case KEYWORD_OPERATOR:
|
|
|
|
case KEYWORD_OVERLOAD: case KEYWORD_PRIVATE:
|
|
|
|
case KEYWORD_PROTECTED: case KEYWORD_PUBLIC:
|
|
|
|
case KEYWORD_STATIC: case KEYWORD_TEMPLATE:
|
|
|
|
case KEYWORD_TYPEDEF: case KEYWORD_TYPENAME:
|
|
|
|
case KEYWORD_USING: case KEYWORD_VIRTUAL:
|
|
|
|
/* Never allowed within parameter declarations.
|
|
|
|
*/
|
|
|
|
restart = TRUE;
|
|
|
|
end = TRUE;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
if (isType (token, TOKEN_NONE))
|
|
|
|
;
|
|
|
|
else if (info->isKnrParamList && info->parameterCount > 0)
|
|
|
|
++elementCount;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* If we encounter any other identifier immediately
|
|
|
|
* following an empty parameter list, this is almost
|
|
|
|
* certainly one of those Microsoft macro "thingies"
|
|
|
|
* that the automatic source code generation sticks
|
|
|
|
* in. Terminate the current statement.
|
|
|
|
*/
|
|
|
|
restart = TRUE;
|
|
|
|
end = TRUE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2005-11-22 12:26:26 +00:00
|
|
|
}
|
2008-11-12 19:37:02 +00:00
|
|
|
if (! end)
|
|
|
|
{
|
|
|
|
c = skipToNonWhite ();
|
|
|
|
if (c == EOF)
|
|
|
|
end = TRUE;
|
|
|
|
}
|
|
|
|
} while (! end);
|
2005-11-22 12:26:26 +00:00
|
|
|
|
2008-11-12 19:37:02 +00:00
|
|
|
if (restart)
|
|
|
|
restartStatement (st);
|
|
|
|
else
|
|
|
|
setToken (st, TOKEN_NONE);
|
|
|
|
return (boolean) (c != EOF);
|
2005-11-22 12:26:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void skipJavaThrows (statementInfo *const st)
|
|
|
|
{
|
2008-11-12 19:37:02 +00:00
|
|
|
tokenInfo *const token = activeToken (st);
|
|
|
|
int c = skipToNonWhite ();
|
2005-11-22 12:26:26 +00:00
|
|
|
|
2008-11-12 19:37:02 +00:00
|
|
|
if (isident1 (c))
|
2005-11-22 12:26:26 +00:00
|
|
|
{
|
2008-11-12 19:37:02 +00:00
|
|
|
readIdentifier (token, c);
|
|
|
|
if (token->keyword == KEYWORD_THROWS)
|
2005-11-22 12:26:26 +00:00
|
|
|
{
|
2008-11-12 19:37:02 +00:00
|
|
|
do
|
|
|
|
{
|
|
|
|
c = skipToNonWhite ();
|
|
|
|
if (isident1 (c))
|
|
|
|
{
|
|
|
|
readIdentifier (token, c);
|
|
|
|
c = skipToNonWhite ();
|
|
|
|
}
|
|
|
|
} while (c == '.' || c == ',');
|
2005-11-22 12:26:26 +00:00
|
|
|
}
|
|
|
|
}
|
2008-11-12 19:37:02 +00:00
|
|
|
cppUngetc (c);
|
|
|
|
setToken (st, TOKEN_NONE);
|
2005-11-22 12:26:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void analyzePostParens (statementInfo *const st, parenInfo *const info)
|
|
|
|
{
|
2008-11-12 19:37:02 +00:00
|
|
|
const unsigned long inputLineNumber = getInputLineNumber ();
|
|
|
|
int c = skipToNonWhite ();
|
2005-11-22 12:26:26 +00:00
|
|
|
|
2008-11-12 19:37:02 +00:00
|
|
|
cppUngetc (c);
|
|
|
|
if (isOneOf (c, "{;,="))
|
|
|
|
;
|
|
|
|
else if (isLanguage (Lang_java) || isLanguage (Lang_vala))
|
|
|
|
skipJavaThrows (st);
|
|
|
|
else
|
2005-11-22 12:26:26 +00:00
|
|
|
{
|
2008-11-12 19:37:02 +00:00
|
|
|
if (! skipPostArgumentStuff (st, info))
|
|
|
|
{
|
|
|
|
verbose (
|
|
|
|
"%s: confusing argument declarations beginning at line %lu\n",
|
|
|
|
getInputFileName (), inputLineNumber);
|
|
|
|
longjmp (Exception, (int) ExceptionFormattingError);
|
|
|
|
}
|
2005-11-22 12:26:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int parseParens (statementInfo *const st, parenInfo *const info)
|
|
|
|
{
|
2008-11-12 19:37:02 +00:00
|
|
|
tokenInfo *const token = activeToken (st);
|
|
|
|
unsigned int identifierCount = 0;
|
|
|
|
unsigned int depth = 1;
|
|
|
|
boolean firstChar = TRUE;
|
|
|
|
int nextChar = '\0';
|
2005-11-22 12:26:26 +00:00
|
|
|
|
2008-11-12 19:37:02 +00:00
|
|
|
info->parameterCount = 1;
|
|
|
|
do
|
2005-11-22 12:26:26 +00:00
|
|
|
{
|
2008-11-12 19:37:02 +00:00
|
|
|
int c = skipToNonWhite ();
|
2005-11-22 12:26:26 +00:00
|
|
|
|
2008-11-12 19:37:02 +00:00
|
|
|
switch (c)
|
2005-11-22 12:26:26 +00:00
|
|
|
{
|
2008-11-12 19:37:02 +00:00
|
|
|
case '&':
|
|
|
|
case '*':
|
|
|
|
{
|
|
|
|
/* DEBUG_PRINT("parseParens, po++\n"); */
|
|
|
|
info->isKnrParamList = FALSE;
|
|
|
|
if (identifierCount == 0)
|
|
|
|
info->isParamList = FALSE;
|
|
|
|
initToken (token);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case ':':
|
|
|
|
{
|
|
|
|
info->isKnrParamList = FALSE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case '.':
|
|
|
|
{
|
|
|
|
info->isNameCandidate = FALSE;
|
|
|
|
info->isKnrParamList = FALSE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case ',':
|
|
|
|
{
|
|
|
|
info->isNameCandidate = FALSE;
|
|
|
|
if (info->isKnrParamList)
|
|
|
|
{
|
|
|
|
++info->parameterCount;
|
|
|
|
identifierCount = 0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case '=':
|
|
|
|
{
|
|
|
|
info->isKnrParamList = FALSE;
|
|
|
|
info->isNameCandidate = FALSE;
|
|
|
|
if (firstChar)
|
|
|
|
{
|
|
|
|
info->isParamList = FALSE;
|
|
|
|
skipMacro (st);
|
|
|
|
depth = 0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case '[':
|
|
|
|
{
|
|
|
|
info->isKnrParamList = FALSE;
|
|
|
|
skipToMatch ("[]");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case '<':
|
|
|
|
{
|
|
|
|
info->isKnrParamList = FALSE;
|
|
|
|
skipToMatch ("<>");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case ')':
|
|
|
|
{
|
|
|
|
if (firstChar)
|
|
|
|
info->parameterCount = 0;
|
|
|
|
--depth;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case '(':
|
|
|
|
{
|
|
|
|
info->isKnrParamList = FALSE;
|
|
|
|
if (firstChar)
|
|
|
|
{
|
|
|
|
info->isNameCandidate = FALSE;
|
|
|
|
cppUngetc (c);
|
|
|
|
skipMacro (st);
|
|
|
|
depth = 0;
|
|
|
|
}
|
|
|
|
else if (isType (token, TOKEN_PAREN_NAME))
|
|
|
|
{
|
|
|
|
c = skipToNonWhite ();
|
|
|
|
if (c == '*') /* check for function pointer */
|
|
|
|
{
|
|
|
|
skipToMatch ("()");
|
|
|
|
c = skipToNonWhite ();
|
|
|
|
if (c == '(')
|
|
|
|
skipToMatch ("()");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
cppUngetc (c);
|
|
|
|
cppUngetc ('(');
|
|
|
|
info->nestedArgs = TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
++depth;
|
|
|
|
break;
|
|
|
|
}
|
2005-11-22 12:26:26 +00:00
|
|
|
|
2008-11-12 19:37:02 +00:00
|
|
|
default:
|
|
|
|
{
|
|
|
|
if (isident1 (c))
|
|
|
|
{
|
|
|
|
if (++identifierCount > 1)
|
|
|
|
info->isKnrParamList = FALSE;
|
|
|
|
readIdentifier (token, c);
|
|
|
|
if (isType (token, TOKEN_NAME) && info->isNameCandidate)
|
|
|
|
token->type = TOKEN_PAREN_NAME;
|
|
|
|
else if (isType (token, TOKEN_KEYWORD))
|
|
|
|
{
|
|
|
|
info->isKnrParamList = FALSE;
|
|
|
|
info->isNameCandidate = FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
info->isParamList = FALSE;
|
|
|
|
info->isKnrParamList = FALSE;
|
|
|
|
info->isNameCandidate = FALSE;
|
|
|
|
info->invalidContents = TRUE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2005-11-22 12:26:26 +00:00
|
|
|
}
|
2008-11-12 19:37:02 +00:00
|
|
|
firstChar = FALSE;
|
|
|
|
} while (! info->nestedArgs && depth > 0 &&
|
|
|
|
(info->isKnrParamList || info->isNameCandidate));
|
2005-11-22 12:26:26 +00:00
|
|
|
|
2008-11-12 19:37:02 +00:00
|
|
|
if (! info->nestedArgs) while (depth > 0)
|
|
|
|
{
|
|
|
|
skipToMatch ("()");
|
2005-11-22 12:26:26 +00:00
|
|
|
--depth;
|
2008-11-12 19:37:02 +00:00
|
|
|
}
|
|
|
|
if (st->argEndPosition == 0)
|
2005-11-22 12:26:26 +00:00
|
|
|
{
|
2008-11-12 19:37:02 +00:00
|
|
|
if (useFile())
|
|
|
|
st->argEndPosition = ftell(File.fp);
|
|
|
|
else
|
|
|
|
/* FIXME File.fpBufferPosition is wrong here, this breaks function signatures and
|
|
|
|
* so Geany's calltips */
|
|
|
|
st->argEndPosition = File.fpBufferPosition;
|
2005-11-22 12:26:26 +00:00
|
|
|
}
|
|
|
|
|
2008-11-12 19:37:02 +00:00
|
|
|
if (! info->isNameCandidate)
|
|
|
|
initToken (token);
|
2005-11-22 12:26:26 +00:00
|
|
|
|
2008-11-12 19:37:02 +00:00
|
|
|
return nextChar;
|
2005-11-22 12:26:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void initParenInfo (parenInfo *const info)
|
|
|
|
{
|
2008-11-12 19:37:02 +00:00
|
|
|
info->isParamList = TRUE;
|
|
|
|
info->isKnrParamList = TRUE;
|
|
|
|
info->isNameCandidate = TRUE;
|
|
|
|
info->invalidContents = FALSE;
|
|
|
|
info->nestedArgs = FALSE;
|
|
|
|
info->parameterCount = 0;
|
2005-11-22 12:26:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void analyzeParens (statementInfo *const st)
|
|
|
|
{
|
2008-11-12 19:37:02 +00:00
|
|
|
tokenInfo *const prev = prevToken (st, 1);
|
2005-11-22 12:26:26 +00:00
|
|
|
|
2008-11-12 19:37:02 +00:00
|
|
|
if (! isType (prev, TOKEN_NONE)) /* in case of ignored enclosing macros */
|
|
|
|
{
|
2007-01-16 13:18:37 +00:00
|
|
|
tokenInfo *const token = activeToken (st);
|
|
|
|
parenInfo info;
|
|
|
|
int c;
|
2005-11-22 12:26:26 +00:00
|
|
|
|
2007-01-16 13:18:37 +00:00
|
|
|
initParenInfo (&info);
|
|
|
|
parseParens (st, &info);
|
|
|
|
|
|
|
|
c = skipToNonWhite ();
|
|
|
|
|
|
|
|
cppUngetc (c);
|
|
|
|
if (info.invalidContents)
|
|
|
|
{
|
2008-11-12 19:37:02 +00:00
|
|
|
reinitStatement (st, FALSE);
|
2007-01-16 13:18:37 +00:00
|
|
|
}
|
|
|
|
else if (info.isNameCandidate && isType (token, TOKEN_PAREN_NAME) &&
|
2008-11-12 19:37:02 +00:00
|
|
|
! st->gotParenName &&
|
|
|
|
(! info.isParamList || ! st->haveQualifyingName ||
|
|
|
|
c == '(' ||
|
|
|
|
(c == '=' && st->implementation != IMP_VIRTUAL) ||
|
|
|
|
(st->declaration == DECL_NONE && isOneOf (c, ",;"))))
|
2007-01-16 13:18:37 +00:00
|
|
|
{
|
2008-11-12 19:37:02 +00:00
|
|
|
token->type = TOKEN_NAME;
|
|
|
|
processName (st);
|
|
|
|
st->gotParenName = TRUE;
|
2007-01-16 13:18:37 +00:00
|
|
|
}
|
|
|
|
else if (! st->gotArgs && info.isParamList)
|
|
|
|
{
|
2008-11-12 19:37:02 +00:00
|
|
|
st->gotArgs = TRUE;
|
|
|
|
setToken (st, TOKEN_ARGS);
|
|
|
|
advanceToken (st);
|
|
|
|
analyzePostParens (st, &info);
|
2007-01-16 13:18:37 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2008-11-12 19:37:02 +00:00
|
|
|
setToken (st, TOKEN_NONE);
|
2007-01-16 13:18:37 +00:00
|
|
|
}
|
2008-11-12 19:37:02 +00:00
|
|
|
}
|
2005-11-22 12:26:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Token parsing functions
|
|
|
|
*/
|
|
|
|
|
|
|
|
static void addContext (statementInfo *const st, const tokenInfo* const token)
|
|
|
|
{
|
2008-11-12 19:37:02 +00:00
|
|
|
if (isType (token, TOKEN_NAME))
|
2005-11-22 12:26:26 +00:00
|
|
|
{
|
2008-11-12 19:37:02 +00:00
|
|
|
if (vStringLength (st->context->name) > 0)
|
|
|
|
{
|
|
|
|
if (isLanguage (Lang_c) || isLanguage (Lang_cpp))
|
|
|
|
vStringCatS (st->context->name, "::");
|
|
|
|
else if (isLanguage (Lang_java) ||
|
|
|
|
isLanguage (Lang_d) || isLanguage (Lang_ferite) ||
|
|
|
|
isLanguage (Lang_csharp) || isLanguage (Lang_vala))
|
|
|
|
vStringCatS (st->context->name, ".");
|
|
|
|
}
|
|
|
|
vStringCat (st->context->name, token->name);
|
|
|
|
st->context->type = TOKEN_NAME;
|
2005-11-22 12:26:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-06-22 17:22:07 +00:00
|
|
|
static boolean inheritingDeclaration (declType decl)
|
|
|
|
{
|
2008-11-12 19:37:02 +00:00
|
|
|
return (boolean) (decl == DECL_CLASS ||
|
|
|
|
decl == DECL_STRUCT ||
|
|
|
|
decl == DECL_INTERFACE);
|
2007-06-22 17:22:07 +00:00
|
|
|
}
|
|
|
|
|
2005-11-22 12:26:26 +00:00
|
|
|
static void processColon (statementInfo *const st)
|
|
|
|
{
|
2007-06-22 17:22:07 +00:00
|
|
|
int c = skipToNonWhite ();
|
|
|
|
const boolean doubleColon = (boolean) (c == ':');
|
2005-11-22 12:26:26 +00:00
|
|
|
|
2007-06-22 17:22:07 +00:00
|
|
|
if (doubleColon)
|
2005-11-22 12:26:26 +00:00
|
|
|
{
|
2007-06-22 17:22:07 +00:00
|
|
|
setToken (st, TOKEN_DOUBLE_COLON);
|
|
|
|
st->haveQualifyingName = FALSE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
cppUngetc (c);
|
2008-11-11 16:33:20 +00:00
|
|
|
if (((isLanguage (Lang_cpp) || isLanguage (Lang_csharp) || isLanguage (Lang_vala)) &&
|
2007-12-18 17:32:06 +00:00
|
|
|
inheritingDeclaration (st->declaration)) ||
|
|
|
|
isLanguage (Lang_d))
|
2007-06-22 17:22:07 +00:00
|
|
|
{
|
|
|
|
readParents (st, ':');
|
|
|
|
}
|
|
|
|
else if (parentDecl (st) == DECL_STRUCT)
|
|
|
|
{
|
|
|
|
c = skipToOneOf (",;");
|
|
|
|
if (c == ',')
|
|
|
|
setToken (st, TOKEN_COMMA);
|
|
|
|
else if (c == ';')
|
|
|
|
setToken (st, TOKEN_SEMICOLON);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
const tokenInfo *const prev = prevToken (st, 1);
|
|
|
|
const tokenInfo *const prev2 = prevToken (st, 2);
|
|
|
|
if (prev->keyword == KEYWORD_DEFAULT ||
|
|
|
|
prev2->keyword == KEYWORD_CASE ||
|
|
|
|
st->parent != NULL)
|
|
|
|
{
|
|
|
|
reinitStatement (st, FALSE);
|
|
|
|
}
|
|
|
|
}
|
2005-11-22 12:26:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Skips over any initializing value which may follow an '=' character in a
|
|
|
|
* variable definition.
|
|
|
|
*/
|
|
|
|
static int skipInitializer (statementInfo *const st)
|
|
|
|
{
|
2008-11-12 19:37:02 +00:00
|
|
|
boolean done = FALSE;
|
|
|
|
int c;
|
2005-11-22 12:26:26 +00:00
|
|
|
|
2008-11-12 19:37:02 +00:00
|
|
|
while (! done)
|
2005-11-22 12:26:26 +00:00
|
|
|
{
|
2008-11-12 19:37:02 +00:00
|
|
|
c = skipToNonWhite ();
|
|
|
|
|
|
|
|
if (c == EOF)
|
|
|
|
longjmp (Exception, (int) ExceptionFormattingError);
|
|
|
|
else switch (c)
|
|
|
|
{
|
|
|
|
case ',':
|
|
|
|
case ';': done = TRUE; break;
|
2005-11-22 12:26:26 +00:00
|
|
|
|
2008-11-12 19:37:02 +00:00
|
|
|
case '0':
|
|
|
|
if (st->implementation == IMP_VIRTUAL)
|
|
|
|
st->implementation = IMP_PURE_VIRTUAL;
|
|
|
|
break;
|
2005-11-22 12:26:26 +00:00
|
|
|
|
2008-11-12 19:37:02 +00:00
|
|
|
case '[': skipToMatch ("[]"); break;
|
|
|
|
case '(': skipToMatch ("()"); break;
|
|
|
|
case '{': skipToMatch ("{}"); break;
|
2005-11-22 12:26:26 +00:00
|
|
|
|
2008-11-12 19:37:02 +00:00
|
|
|
case '}':
|
|
|
|
if (insideEnumBody (st))
|
|
|
|
done = TRUE;
|
|
|
|
else if (! isBraceFormat ())
|
|
|
|
{
|
|
|
|
verbose ("%s: unexpected closing brace at line %lu\n",
|
|
|
|
getInputFileName (), getInputLineNumber ());
|
|
|
|
longjmp (Exception, (int) ExceptionBraceFormattingError);
|
|
|
|
}
|
|
|
|
break;
|
2005-11-22 12:26:26 +00:00
|
|
|
|
2008-11-12 19:37:02 +00:00
|
|
|
default: break;
|
|
|
|
}
|
2005-11-22 12:26:26 +00:00
|
|
|
}
|
2008-11-12 19:37:02 +00:00
|
|
|
return c;
|
2005-11-22 12:26:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void processInitializer (statementInfo *const st)
|
|
|
|
{
|
2008-11-12 19:37:02 +00:00
|
|
|
const boolean inEnumBody = insideEnumBody (st);
|
|
|
|
const int c = skipInitializer (st);
|
2005-11-22 12:26:26 +00:00
|
|
|
|
2008-11-12 19:37:02 +00:00
|
|
|
if (c == ';')
|
|
|
|
setToken (st, TOKEN_SEMICOLON);
|
|
|
|
else if (c == ',')
|
|
|
|
setToken (st, TOKEN_COMMA);
|
|
|
|
else if (c == '}' && inEnumBody)
|
|
|
|
{
|
|
|
|
cppUngetc (c);
|
|
|
|
setToken (st, TOKEN_COMMA);
|
|
|
|
}
|
|
|
|
if (st->scope == SCOPE_EXTERN)
|
|
|
|
st->scope = SCOPE_GLOBAL;
|
2005-11-22 12:26:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void parseIdentifier (statementInfo *const st, const int c)
|
|
|
|
{
|
2008-11-12 19:37:02 +00:00
|
|
|
tokenInfo *const token = activeToken (st);
|
2005-11-22 12:26:26 +00:00
|
|
|
|
2008-11-12 19:37:02 +00:00
|
|
|
readIdentifier (token, c);
|
|
|
|
if (! isType (token, TOKEN_NONE))
|
|
|
|
processToken (token, st);
|
2005-11-22 12:26:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void parseGeneralToken (statementInfo *const st, const int c)
|
|
|
|
{
|
2008-11-12 19:37:02 +00:00
|
|
|
const tokenInfo *const prev = prevToken (st, 1);
|
2005-11-22 12:26:26 +00:00
|
|
|
|
2008-11-12 19:37:02 +00:00
|
|
|
if (isident1(c))
|
2005-11-22 12:26:26 +00:00
|
|
|
{
|
2008-11-12 19:37:02 +00:00
|
|
|
parseIdentifier (st, c);
|
|
|
|
if (isType (st->context, TOKEN_NAME) &&
|
|
|
|
isType (activeToken (st), TOKEN_NAME) && isType (prev, TOKEN_NAME))
|
|
|
|
{
|
|
|
|
initToken (st->context);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (isExternCDecl (st, c))
|
|
|
|
{
|
|
|
|
st->declaration = DECL_NOMANGLE;
|
|
|
|
st->scope = SCOPE_GLOBAL;
|
2005-11-22 12:26:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Reads characters from the pre-processor and assembles tokens, setting
|
|
|
|
* the current statement state.
|
|
|
|
*/
|
|
|
|
static void nextToken (statementInfo *const st)
|
|
|
|
{
|
2008-11-12 19:37:02 +00:00
|
|
|
int c;
|
|
|
|
tokenInfo *token = activeToken (st);
|
|
|
|
do
|
|
|
|
{
|
2007-01-16 13:18:37 +00:00
|
|
|
c = skipToNonWhite();
|
|
|
|
switch (c)
|
|
|
|
{
|
2008-11-12 19:37:02 +00:00
|
|
|
case EOF: longjmp (Exception, (int) ExceptionEOF); break;
|
2008-12-09 19:00:45 +00:00
|
|
|
case '(': analyzeParens (st); token = activeToken (st); break;
|
|
|
|
case '*': setToken (st, TOKEN_STAR); break;
|
|
|
|
case ',': setToken (st, TOKEN_COMMA); break;
|
|
|
|
case ':': processColon (st); break;
|
|
|
|
case ';': setToken (st, TOKEN_SEMICOLON); break;
|
|
|
|
case '<': skipToMatch ("<>"); break;
|
|
|
|
case '=': processInitializer (st); break;
|
|
|
|
case '[':
|
|
|
|
/* Hack for Vala: [..] can be a function attribute.
|
|
|
|
* Seems not to have bad side effects, but have to test it more. */
|
|
|
|
if (!isLanguage (Lang_vala))
|
|
|
|
setToken (st, TOKEN_ARRAY);
|
|
|
|
skipToMatch ("[]");
|
|
|
|
break;
|
|
|
|
case '{': setToken (st, TOKEN_BRACE_OPEN); break;
|
|
|
|
case '}': setToken (st, TOKEN_BRACE_CLOSE); break;
|
|
|
|
default: parseGeneralToken (st, c); break;
|
2007-01-16 13:18:37 +00:00
|
|
|
}
|
2008-11-12 19:37:02 +00:00
|
|
|
} while (isType (token, TOKEN_NONE));
|
2006-08-27 17:39:34 +00:00
|
|
|
|
2005-11-22 12:26:26 +00:00
|
|
|
/* We want to know about non-keyword variable types */
|
|
|
|
if (TOKEN_NONE == st->firstToken->type)
|
|
|
|
{
|
2008-11-12 19:37:02 +00:00
|
|
|
if ((TOKEN_NAME == token->type) || isDataTypeKeyword(token))
|
2005-11-22 12:26:26 +00:00
|
|
|
copyToken(st->firstToken, token);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Scanning support functions
|
|
|
|
*/
|
2007-01-16 13:18:37 +00:00
|
|
|
static unsigned int contextual_fake_count = 0;
|
2005-11-22 12:26:26 +00:00
|
|
|
static statementInfo *CurrentStatement = NULL;
|
|
|
|
|
|
|
|
static statementInfo *newStatement (statementInfo *const parent)
|
|
|
|
{
|
2008-11-12 19:37:02 +00:00
|
|
|
statementInfo *const st = xMalloc (1, statementInfo);
|
|
|
|
unsigned int i;
|
2005-11-22 12:26:26 +00:00
|
|
|
|
2008-11-12 19:37:02 +00:00
|
|
|
for (i = 0 ; i < (unsigned int) NumTokens ; ++i)
|
|
|
|
st->token [i] = newToken ();
|
2005-11-22 12:26:26 +00:00
|
|
|
|
2008-11-12 19:37:02 +00:00
|
|
|
st->context = newToken ();
|
|
|
|
st->blockName = newToken ();
|
|
|
|
st->parentClasses = vStringNew ();
|
|
|
|
st->firstToken = newToken();
|
2005-11-22 12:26:26 +00:00
|
|
|
|
2008-11-12 19:37:02 +00:00
|
|
|
initStatement (st, parent);
|
|
|
|
CurrentStatement = st;
|
2005-11-22 12:26:26 +00:00
|
|
|
|
2008-11-12 19:37:02 +00:00
|
|
|
return st;
|
2005-11-22 12:26:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void deleteStatement (void)
|
|
|
|
{
|
2008-11-12 19:37:02 +00:00
|
|
|
statementInfo *const st = CurrentStatement;
|
|
|
|
statementInfo *const parent = st->parent;
|
|
|
|
unsigned int i;
|
2005-11-22 12:26:26 +00:00
|
|
|
|
2008-11-12 19:37:02 +00:00
|
|
|
for (i = 0 ; i < (unsigned int) NumTokens ; ++i)
|
|
|
|
{
|
|
|
|
deleteToken(st->token[i]); st->token[i] = NULL;
|
|
|
|
}
|
|
|
|
deleteToken(st->blockName); st->blockName = NULL;
|
|
|
|
deleteToken(st->context); st->context = NULL;
|
|
|
|
vStringDelete(st->parentClasses); st->parentClasses = NULL;
|
2005-11-22 12:26:26 +00:00
|
|
|
deleteToken(st->firstToken);
|
2008-11-12 19:37:02 +00:00
|
|
|
eFree (st);
|
|
|
|
CurrentStatement = parent;
|
2005-11-22 12:26:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void deleteAllStatements (void)
|
|
|
|
{
|
2008-11-12 19:37:02 +00:00
|
|
|
while (CurrentStatement != NULL)
|
|
|
|
deleteStatement ();
|
2005-11-22 12:26:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static boolean isStatementEnd (const statementInfo *const st)
|
|
|
|
{
|
2008-11-12 19:37:02 +00:00
|
|
|
const tokenInfo *const token = activeToken (st);
|
|
|
|
boolean isEnd;
|
2005-11-22 12:26:26 +00:00
|
|
|
|
2008-11-12 19:37:02 +00:00
|
|
|
if (isType (token, TOKEN_SEMICOLON))
|
2007-02-14 17:35:54 +00:00
|
|
|
isEnd = TRUE;
|
2008-11-12 19:37:02 +00:00
|
|
|
else if (isType (token, TOKEN_BRACE_CLOSE))
|
2008-11-11 16:33:20 +00:00
|
|
|
/* Java, D, C#, Vala do not require semicolons to end a block. Neither do
|
|
|
|
* C++ namespaces. All other blocks require a semicolon to terminate them.
|
2007-02-14 17:35:54 +00:00
|
|
|
*/
|
2008-11-12 19:37:02 +00:00
|
|
|
isEnd = (boolean) (isLanguage (Lang_java) || isLanguage (Lang_d) ||
|
|
|
|
isLanguage (Lang_csharp) || isLanguage (Lang_vala) ||
|
|
|
|
! isContextualStatement (st));
|
|
|
|
else
|
2007-02-14 17:35:54 +00:00
|
|
|
isEnd = FALSE;
|
2005-11-22 12:26:26 +00:00
|
|
|
|
2008-11-12 19:37:02 +00:00
|
|
|
return isEnd;
|
2005-11-22 12:26:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void checkStatementEnd (statementInfo *const st)
|
|
|
|
{
|
2008-11-12 19:37:02 +00:00
|
|
|
const tokenInfo *const token = activeToken (st);
|
|
|
|
boolean comma = isType (token, TOKEN_COMMA);
|
2007-01-16 13:18:37 +00:00
|
|
|
|
2008-11-12 19:37:02 +00:00
|
|
|
if (comma || isStatementEnd (st))
|
|
|
|
{
|
|
|
|
reinitStatementWithToken (st, activeToken (st), comma);
|
2007-01-16 13:18:37 +00:00
|
|
|
|
2008-11-12 19:37:02 +00:00
|
|
|
DebugStatement ( if (debug (DEBUG_PARSE)) printf ("<ES>"); )
|
|
|
|
cppEndStatement ();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
cppBeginStatement ();
|
|
|
|
advanceToken (st);
|
|
|
|
}
|
2005-11-22 12:26:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void nest (statementInfo *const st, const unsigned int nestLevel)
|
|
|
|
{
|
2008-11-12 19:37:02 +00:00
|
|
|
switch (st->declaration)
|
|
|
|
{
|
|
|
|
case DECL_CLASS:
|
|
|
|
case DECL_ENUM:
|
|
|
|
case DECL_INTERFACE:
|
|
|
|
case DECL_NAMESPACE:
|
|
|
|
case DECL_NOMANGLE:
|
|
|
|
case DECL_STRUCT:
|
|
|
|
case DECL_UNION:
|
|
|
|
createTags (nestLevel, st);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
skipToMatch ("{}");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
advanceToken (st);
|
|
|
|
setToken (st, TOKEN_BRACE_CLOSE);
|
2005-11-22 12:26:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void tagCheck (statementInfo *const st)
|
|
|
|
{
|
|
|
|
const tokenInfo *const token = activeToken (st);
|
|
|
|
const tokenInfo *const prev = prevToken (st, 1);
|
|
|
|
const tokenInfo *const prev2 = prevToken (st, 2);
|
|
|
|
|
|
|
|
switch (token->type)
|
|
|
|
{
|
2008-11-12 19:37:02 +00:00
|
|
|
case TOKEN_NAME:
|
|
|
|
{
|
|
|
|
if (insideEnumBody (st))
|
|
|
|
qualifyEnumeratorTag (st, token);
|
|
|
|
break;
|
|
|
|
}
|
2005-11-22 12:26:26 +00:00
|
|
|
#if 0
|
2008-11-12 19:37:02 +00:00
|
|
|
case TOKEN_PACKAGE:
|
|
|
|
{
|
2007-10-17 11:55:59 +00:00
|
|
|
if (st->haveQualifyingName)
|
2008-11-12 19:37:02 +00:00
|
|
|
makeTag (token, st, FALSE, TAG_PACKAGE);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
case TOKEN_BRACE_OPEN:
|
|
|
|
{
|
|
|
|
if (isType (prev, TOKEN_ARGS))
|
2007-10-17 11:55:59 +00:00
|
|
|
{
|
2008-11-12 19:37:02 +00:00
|
|
|
if (st->haveQualifyingName)
|
|
|
|
{
|
|
|
|
st->declaration = DECL_FUNCTION;
|
|
|
|
if (isType (prev2, TOKEN_NAME))
|
|
|
|
copyToken (st->blockName, prev2);
|
|
|
|
qualifyFunctionTag (st, prev2);
|
|
|
|
}
|
2007-10-17 11:55:59 +00:00
|
|
|
}
|
2008-11-12 19:37:02 +00:00
|
|
|
else if (isContextualStatement (st))
|
2007-10-17 11:55:59 +00:00
|
|
|
{
|
2008-11-12 19:37:02 +00:00
|
|
|
tokenInfo *name_token = (tokenInfo *)prev;
|
|
|
|
|
|
|
|
if (isType (name_token, TOKEN_NAME))
|
2008-11-11 16:33:20 +00:00
|
|
|
{
|
2008-11-12 19:37:02 +00:00
|
|
|
if (!isLanguage (Lang_vala))
|
2008-11-11 16:33:20 +00:00
|
|
|
copyToken (st->blockName, name_token);
|
2008-11-12 19:37:02 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
switch (st->declaration)
|
|
|
|
{
|
|
|
|
case DECL_CLASS:
|
|
|
|
case DECL_ENUM:
|
|
|
|
case DECL_INTERFACE:
|
|
|
|
case DECL_NAMESPACE:
|
|
|
|
case DECL_STRUCT:
|
|
|
|
copyToken (st->blockName, name_token);
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* anything else can be a property */
|
|
|
|
default:
|
|
|
|
/* makeTag (prev, st, FALSE, TAG_PROPERTY); */
|
|
|
|
/* FIXME: temporary hack to get properties shown */
|
|
|
|
makeTag (prev, st, FALSE, TAG_FIELD);
|
|
|
|
break;
|
|
|
|
}
|
2008-11-11 16:33:20 +00:00
|
|
|
}
|
|
|
|
}
|
2008-11-12 19:37:02 +00:00
|
|
|
else if (isLanguage (Lang_csharp))
|
2007-10-17 11:55:59 +00:00
|
|
|
makeTag (prev, st, FALSE, TAG_PROPERTY);
|
2008-11-12 19:37:02 +00:00
|
|
|
else
|
2007-10-17 11:55:59 +00:00
|
|
|
{
|
2008-11-12 19:37:02 +00:00
|
|
|
tokenInfo *contextual_token = (tokenInfo *)prev;
|
|
|
|
if(isContextualKeyword (contextual_token))
|
|
|
|
{
|
|
|
|
char buffer[64];
|
2007-10-17 11:55:59 +00:00
|
|
|
|
2008-11-12 19:37:02 +00:00
|
|
|
name_token = newToken ();
|
|
|
|
copyToken (name_token, contextual_token);
|
2007-10-17 11:55:59 +00:00
|
|
|
|
2008-11-12 19:37:02 +00:00
|
|
|
sprintf(buffer, "anon_%s_%d", name_token->name->buffer, contextual_fake_count++);
|
|
|
|
vStringClear(name_token->name);
|
|
|
|
vStringCatS(name_token->name, buffer);
|
2007-10-17 11:55:59 +00:00
|
|
|
|
2008-11-12 19:37:02 +00:00
|
|
|
name_token->type = TOKEN_NAME;
|
|
|
|
name_token->keyword = KEYWORD_NONE;
|
2007-10-17 11:55:59 +00:00
|
|
|
|
2008-11-12 19:37:02 +00:00
|
|
|
advanceToken (st);
|
|
|
|
contextual_token = activeToken (st);
|
|
|
|
copyToken (contextual_token, token);
|
|
|
|
copyToken ((tokenInfo *const)token, name_token);
|
|
|
|
copyToken (st->blockName, name_token);
|
|
|
|
copyToken (st->firstToken, name_token);
|
|
|
|
}
|
2007-10-17 11:55:59 +00:00
|
|
|
}
|
2008-11-12 19:37:02 +00:00
|
|
|
qualifyBlockTag (st, name_token);
|
2007-10-17 11:55:59 +00:00
|
|
|
}
|
2008-11-12 19:37:02 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case TOKEN_ARRAY:
|
|
|
|
case TOKEN_SEMICOLON:
|
|
|
|
case TOKEN_COMMA:
|
|
|
|
{
|
|
|
|
if (insideEnumBody (st))
|
|
|
|
;
|
|
|
|
else if (isType (prev, TOKEN_NAME))
|
|
|
|
{
|
|
|
|
if (isContextualKeyword (prev2))
|
|
|
|
makeTag (prev, st, TRUE, TAG_EXTERN_VAR);
|
|
|
|
else
|
|
|
|
qualifyVariableTag (st, prev);
|
|
|
|
}
|
|
|
|
else if (isType (prev, TOKEN_ARGS) && isType (prev2, TOKEN_NAME))
|
|
|
|
{
|
|
|
|
qualifyFunctionDeclTag (st, prev2);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2005-11-22 12:26:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Parses the current file and decides whether to write out and tags that
|
|
|
|
* are discovered.
|
|
|
|
*/
|
|
|
|
static void createTags (const unsigned int nestLevel,
|
2008-11-12 19:37:02 +00:00
|
|
|
statementInfo *const parent)
|
2005-11-22 12:26:26 +00:00
|
|
|
{
|
2008-11-12 19:37:02 +00:00
|
|
|
statementInfo *const st = newStatement (parent);
|
2005-11-22 12:26:26 +00:00
|
|
|
|
2008-11-12 19:37:02 +00:00
|
|
|
DebugStatement ( if (nestLevel > 0) debugParseNest (TRUE, nestLevel); )
|
|
|
|
while (TRUE)
|
2005-11-22 12:26:26 +00:00
|
|
|
{
|
2007-01-16 13:18:37 +00:00
|
|
|
tokenInfo *token;
|
|
|
|
|
|
|
|
nextToken (st);
|
|
|
|
|
|
|
|
token = activeToken (st);
|
|
|
|
|
|
|
|
if (isType (token, TOKEN_BRACE_CLOSE))
|
|
|
|
{
|
2008-11-12 19:37:02 +00:00
|
|
|
if (nestLevel > 0)
|
2007-01-16 13:18:37 +00:00
|
|
|
break;
|
2008-11-12 19:37:02 +00:00
|
|
|
else
|
|
|
|
{
|
2007-01-16 13:18:37 +00:00
|
|
|
verbose ("%s: unexpected closing brace at line %lu\n",
|
2008-11-12 19:37:02 +00:00
|
|
|
getInputFileName (), getInputLineNumber ());
|
2007-01-16 13:18:37 +00:00
|
|
|
longjmp (Exception, (int) ExceptionBraceFormattingError);
|
2008-11-12 19:37:02 +00:00
|
|
|
}
|
2007-01-16 13:18:37 +00:00
|
|
|
}
|
|
|
|
else if (isType (token, TOKEN_DOUBLE_COLON))
|
|
|
|
{
|
2008-11-12 19:37:02 +00:00
|
|
|
addContext (st, prevToken (st, 1));
|
|
|
|
advanceToken (st);
|
2007-01-16 13:18:37 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2008-11-12 19:37:02 +00:00
|
|
|
tagCheck (st);/* this can add new token */
|
|
|
|
if (isType (activeToken (st), TOKEN_BRACE_OPEN))
|
2007-01-16 13:18:37 +00:00
|
|
|
nest (st, nestLevel + 1);
|
2008-11-12 19:37:02 +00:00
|
|
|
checkStatementEnd (st);
|
2007-01-16 13:18:37 +00:00
|
|
|
}
|
2008-11-12 19:37:02 +00:00
|
|
|
}
|
|
|
|
deleteStatement ();
|
|
|
|
DebugStatement ( if (nestLevel > 0) debugParseNest (FALSE, nestLevel - 1); )
|
2005-11-22 12:26:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static boolean findCTags (const unsigned int passCount)
|
|
|
|
{
|
2008-11-12 19:37:02 +00:00
|
|
|
exception_t exception;
|
|
|
|
boolean retry;
|
2005-11-22 12:26:26 +00:00
|
|
|
|
2008-11-12 19:37:02 +00:00
|
|
|
Assert (passCount < 3);
|
2008-12-09 19:00:45 +00:00
|
|
|
cppInit ((boolean) (passCount > 1), isLanguage (Lang_csharp));
|
2005-11-22 12:26:26 +00:00
|
|
|
|
2008-11-12 19:37:02 +00:00
|
|
|
exception = (exception_t) setjmp (Exception);
|
|
|
|
retry = FALSE;
|
2007-01-16 13:18:37 +00:00
|
|
|
|
2008-11-12 19:37:02 +00:00
|
|
|
if (exception == ExceptionNone)
|
2005-11-22 12:26:26 +00:00
|
|
|
{
|
2007-01-16 13:18:37 +00:00
|
|
|
createTags (0, NULL);
|
2005-11-22 12:26:26 +00:00
|
|
|
}
|
2008-11-12 19:37:02 +00:00
|
|
|
else
|
|
|
|
{
|
2007-01-16 13:18:37 +00:00
|
|
|
deleteAllStatements ();
|
|
|
|
if (exception == ExceptionBraceFormattingError && passCount == 1)
|
|
|
|
{
|
2008-11-12 19:37:02 +00:00
|
|
|
retry = TRUE;
|
|
|
|
verbose ("%s: retrying file with fallback brace matching algorithm\n",
|
|
|
|
getInputFileName ());
|
2007-01-16 13:18:37 +00:00
|
|
|
}
|
2008-11-12 19:37:02 +00:00
|
|
|
}
|
|
|
|
cppTerminate ();
|
|
|
|
return retry;
|
2005-11-22 12:26:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void buildKeywordHash (const langType language, unsigned int idx)
|
|
|
|
{
|
2008-11-12 19:37:02 +00:00
|
|
|
const size_t count = sizeof (KeywordTable) / sizeof (KeywordTable [0]);
|
|
|
|
size_t i;
|
|
|
|
for (i = 0 ; i < count ; ++i)
|
|
|
|
{
|
|
|
|
const keywordDesc* const p = &KeywordTable [i];
|
|
|
|
if (p->isValid [idx])
|
|
|
|
addKeyword (p->name, language, (int) p->id);
|
|
|
|
}
|
2005-11-22 12:26:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void initializeCParser (const langType language)
|
|
|
|
{
|
2008-11-12 19:37:02 +00:00
|
|
|
contextual_fake_count = 0;
|
|
|
|
Lang_c = language;
|
|
|
|
buildKeywordHash (language, 0);
|
2005-11-22 12:26:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void initializeCppParser (const langType language)
|
|
|
|
{
|
2008-11-12 19:37:02 +00:00
|
|
|
contextual_fake_count = 0;
|
|
|
|
Lang_cpp = language;
|
|
|
|
buildKeywordHash (language, 1);
|
2005-11-22 12:26:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void initializeJavaParser (const langType language)
|
|
|
|
{
|
2008-11-12 19:37:02 +00:00
|
|
|
contextual_fake_count = 0;
|
|
|
|
Lang_java = language;
|
|
|
|
buildKeywordHash (language, 3);
|
2005-11-22 12:26:26 +00:00
|
|
|
}
|
|
|
|
|
2006-08-18 19:57:02 +00:00
|
|
|
static void initializeDParser (const langType language)
|
|
|
|
{
|
2008-11-12 19:37:02 +00:00
|
|
|
contextual_fake_count = 0;
|
|
|
|
Lang_d = language;
|
|
|
|
buildKeywordHash (language, 6);
|
2006-08-27 17:39:34 +00:00
|
|
|
}
|
|
|
|
|
2008-08-27 12:44:54 +00:00
|
|
|
static void initializeGLSLParser (const langType language)
|
|
|
|
{
|
2008-11-12 19:37:02 +00:00
|
|
|
contextual_fake_count = 0;
|
|
|
|
Lang_glsl = language;
|
|
|
|
buildKeywordHash (language, 0); /* C keywords */
|
2008-08-27 12:44:54 +00:00
|
|
|
}
|
|
|
|
|
2006-08-27 17:39:34 +00:00
|
|
|
static void initializeFeriteParser (const langType language)
|
|
|
|
{
|
2008-11-12 19:37:02 +00:00
|
|
|
contextual_fake_count = 0;
|
|
|
|
Lang_ferite = language;
|
|
|
|
buildKeywordHash (language, 1); /* C++ keywords */
|
2006-08-18 19:57:02 +00:00
|
|
|
}
|
|
|
|
|
2007-06-22 17:22:07 +00:00
|
|
|
static void initializeCsharpParser (const langType language)
|
|
|
|
{
|
2008-11-12 19:37:02 +00:00
|
|
|
contextual_fake_count = 0;
|
2007-06-22 17:22:07 +00:00
|
|
|
Lang_csharp = language;
|
|
|
|
buildKeywordHash (language, 2);
|
|
|
|
}
|
|
|
|
|
2008-11-11 16:33:20 +00:00
|
|
|
static void initializeValaParser (const langType language)
|
|
|
|
{
|
|
|
|
contextual_fake_count = 0;
|
|
|
|
Lang_vala = language;
|
|
|
|
buildKeywordHash (language, 5);
|
|
|
|
}
|
|
|
|
|
2005-11-22 12:26:26 +00:00
|
|
|
extern parserDefinition* CParser (void)
|
|
|
|
{
|
2008-11-12 19:37:02 +00:00
|
|
|
static const char *const extensions [] = { "c", "pc", "sc", NULL };
|
|
|
|
parserDefinition* def = parserNew ("C");
|
|
|
|
def->kinds = CKinds;
|
|
|
|
def->kindCount = KIND_COUNT (CKinds);
|
|
|
|
def->extensions = extensions;
|
|
|
|
def->parser2 = findCTags;
|
|
|
|
def->initialize = initializeCParser;
|
|
|
|
return def;
|
2005-11-22 12:26:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
extern parserDefinition* CppParser (void)
|
|
|
|
{
|
2008-11-12 19:37:02 +00:00
|
|
|
static const char *const extensions [] = {
|
|
|
|
"c++", "cc", "cp", "cpp", "cxx", "h", "h++", "hh", "hp", "hpp", "hxx",
|
|
|
|
"i",
|
2005-11-22 12:26:26 +00:00
|
|
|
#ifndef CASE_INSENSITIVE_FILENAMES
|
2008-11-12 19:37:02 +00:00
|
|
|
"C", "H",
|
2005-11-22 12:26:26 +00:00
|
|
|
#endif
|
2008-11-12 19:37:02 +00:00
|
|
|
NULL
|
|
|
|
};
|
|
|
|
parserDefinition* def = parserNew ("C++");
|
|
|
|
def->kinds = CKinds;
|
|
|
|
def->kindCount = KIND_COUNT (CKinds);
|
|
|
|
def->extensions = extensions;
|
|
|
|
def->parser2 = findCTags;
|
|
|
|
def->initialize = initializeCppParser;
|
|
|
|
return def;
|
2005-11-22 12:26:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
extern parserDefinition* JavaParser (void)
|
|
|
|
{
|
2008-11-12 19:37:02 +00:00
|
|
|
static const char *const extensions [] = { "java", NULL };
|
|
|
|
parserDefinition* def = parserNew ("Java");
|
|
|
|
def->kinds = JavaKinds;
|
|
|
|
def->kindCount = KIND_COUNT (JavaKinds);
|
|
|
|
def->extensions = extensions;
|
|
|
|
def->parser2 = findCTags;
|
|
|
|
def->initialize = initializeJavaParser;
|
|
|
|
return def;
|
2005-11-22 12:26:26 +00:00
|
|
|
}
|
|
|
|
|
2006-08-18 19:57:02 +00:00
|
|
|
extern parserDefinition* DParser (void)
|
|
|
|
{
|
2008-11-12 19:37:02 +00:00
|
|
|
static const char *const extensions [] = { "d", "di", NULL };
|
|
|
|
parserDefinition* def = parserNew ("D");
|
|
|
|
def->kinds = CKinds;
|
|
|
|
def->kindCount = KIND_COUNT (CKinds);
|
|
|
|
def->extensions = extensions;
|
|
|
|
def->parser2 = findCTags;
|
|
|
|
def->initialize = initializeDParser;
|
|
|
|
return def;
|
2006-08-18 19:57:02 +00:00
|
|
|
}
|
|
|
|
|
2008-08-27 12:44:54 +00:00
|
|
|
extern parserDefinition* GLSLParser (void)
|
|
|
|
{
|
2008-11-12 19:37:02 +00:00
|
|
|
static const char *const extensions [] = { "glsl", "frag", "vert", NULL };
|
|
|
|
parserDefinition* def = parserNew ("GLSL");
|
|
|
|
def->kinds = CKinds;
|
|
|
|
def->kindCount = KIND_COUNT (CKinds);
|
|
|
|
def->extensions = extensions;
|
|
|
|
def->parser2 = findCTags;
|
|
|
|
def->initialize = initializeGLSLParser;
|
|
|
|
return def;
|
2008-08-27 12:44:54 +00:00
|
|
|
}
|
|
|
|
|
2006-08-27 17:39:34 +00:00
|
|
|
extern parserDefinition* FeriteParser (void)
|
|
|
|
{
|
2008-11-12 19:37:02 +00:00
|
|
|
static const char *const extensions [] = { "fe", NULL };
|
|
|
|
parserDefinition* def = parserNew ("Ferite");
|
|
|
|
def->kinds = CKinds;
|
|
|
|
def->kindCount = KIND_COUNT (CKinds);
|
|
|
|
def->extensions = extensions;
|
|
|
|
def->parser2 = findCTags;
|
|
|
|
def->initialize = initializeFeriteParser;
|
|
|
|
return def;
|
2006-08-27 17:39:34 +00:00
|
|
|
}
|
2006-08-18 19:57:02 +00:00
|
|
|
|
2007-06-22 17:22:07 +00:00
|
|
|
extern parserDefinition* CsharpParser (void)
|
|
|
|
{
|
2008-11-12 19:37:02 +00:00
|
|
|
static const char *const extensions [] = { "cs", NULL };
|
|
|
|
parserDefinition* def = parserNew ("C#");
|
|
|
|
def->kinds = CsharpKinds;
|
|
|
|
def->kindCount = KIND_COUNT (CsharpKinds);
|
|
|
|
def->extensions = extensions;
|
|
|
|
def->parser2 = findCTags;
|
|
|
|
def->initialize = initializeCsharpParser;
|
|
|
|
return def;
|
2007-06-22 17:22:07 +00:00
|
|
|
}
|
2008-11-11 16:33:20 +00:00
|
|
|
|
|
|
|
extern parserDefinition* ValaParser (void)
|
|
|
|
{
|
2008-11-12 19:37:02 +00:00
|
|
|
static const char *const extensions [] = { "vala", NULL };
|
|
|
|
parserDefinition* def = parserNew ("Vala");
|
|
|
|
def->kinds = ValaKinds;
|
|
|
|
def->kindCount = KIND_COUNT (ValaKinds);
|
|
|
|
def->extensions = extensions;
|
|
|
|
def->parser2 = findCTags;
|
|
|
|
def->initialize = initializeValaParser;
|
|
|
|
return def;
|
2008-11-11 16:33:20 +00:00
|
|
|
}
|
2005-11-22 12:26:26 +00:00
|
|
|
/* vi:set tabstop=8 shiftwidth=4: */
|