Commit 84beb47c authored by David Gobbi's avatar David Gobbi Committed by Marcus D. Hanwell
Browse files

ENH: more powerful parser, more efficient vtkStdString ref handling

parent be876cb1
This diff is collapsed.
......@@ -30,14 +30,12 @@
int HintSize;
int ArgTypes[MAX_ARGS];
int ArgCounts[MAX_ARGS];
int ArgExternals[MAX_ARGS];
char *ArgClasses[MAX_ARGS];
int ReturnType;
char *ReturnClass;
char *Comment;
char *Signature;
int IsLegacy;
int ReturnExternal;
} FunctionInfo;
typedef struct _FileInfo
......@@ -48,7 +46,6 @@
char *ClassName;
char *FileName;
char *OutputFileName;
char *SuperClasses[10];
int NumberOfSuperClasses;
int NumberOfFunctions;
......
......@@ -80,6 +80,26 @@ Modify lex.yy.c:
}
};
^[\t ]*"#ifdef"[\t ]*"VTK_WORKAROUND_WINDOWS_MANGLE".*$ {
int c1 = 0, c2 = 0, c3 = 0, c4 = 0, c5 = 0, c6 = input();
for (;;)
{
if (c6 == 0)
{
fprintf(yyout,"Cannot find matching #endif.\n");
break;
}
if (c1 == '#' && c2 == 'e' && c3 == 'n' && c4 == 'd' && c5 == 'i' && c6 == 'f') break;
c1 = c2; c2 = c3; c3 = c4; c4 = c5; c5 = c6; c6 = input();
}
for (;;)
{
if (c6 == 0) break;
if (c6 == '\n') break;
c6 = input();
}
};
^[\t ]*"// .NAME".* {
int pos = 1;
while (yytext[pos-1] != 'M' || yytext[pos] != 'E')
......@@ -152,8 +172,8 @@ Modify lex.yy.c:
"["[\t\n\r\ ]*[1-9][0-9]*[\t\n\r ]*"]" {
sscanf(yytext+1,"%d",&yylval.integer); return(ARRAY_NUM);}
"struct "[\t\n\r ]*"vtk"[a-zA-Z0-9_]*[\t\n\r ]*";" return(CLASS_REF);
"class "[\t\n\r ]*"vtk"[a-zA-Z0-9_]*[\t\n\r ]*";" return(CLASS_REF);
("friend"[\t\n\r ]+)?("template"[\t\n\r ]*"<"[^>]*">"[\t\n\r ]*)?"class"[\t\n\r ]+[a-zA-Z_][a-zA-Z0-9_]*("::"[a-zA-Z_][a-zA-Z0-9_]*)*[\t\n\r ]*";" return(CLASS_REF);
("friend"[\t\n\r ]+)?("template"[\t\n\r ]*"<"[^>]*">"[\t\n\r ]*)?"struct"[\t\n\r ]+[a-zA-Z_][a-zA-Z0-9_]*("::"[a-zA-Z_][a-zA-Z0-9_]*)*[\t\n\r ]*";" return(CLASS_REF);
"void"[\t\n\r ]*"("[\t\n\r ]*"*"[a-zA-Z0-9_]*[\t\n\r ]*")"[\t\n\r ]*"("[\t\n\r ]*"void"[\t\n\r ]*"*"[\n\t ]*")" return(VAR_FUNCTION);
......@@ -170,25 +190,39 @@ Modify lex.yy.c:
"signed"[\t\n\r ]*"char" return(SIGNED_CHAR);
"class" return(CLASS);
"public" return(PUBLIC);
"private" return(PRIVATE);
"protected" return(PROTECTED);
"int" return(INT);
"ostream" return(OSTREAM);
"istream" return(ISTREAM);
"class" return(CLASS);
"struct" return(CLASS);
"public" return(PUBLIC);
"private" return(PRIVATE);
"protected" return(PROTECTED);
"int" return(INT);
"float" return(FLOAT);
"short" return(SHORT);
"long" return(LONG);
"double" return(DOUBLE);
"void" return(VOID);
"char" return(CHAR);
"bool" return(BOOL);
"double" return(DOUBLE);
"void" return(VOID);
"char" return(CHAR);
"bool" return(BOOL);
"enum" return(ENUM);
"union" return(UNION);
"virtual" return(VIRTUAL);
"const" return(CONST);
"mutable" return(MUTABLE);
"operator" return(OPERATOR);
"unsigned" return(UNSIGNED);
"friend" return(FRIEND);
"inline" return(INLINE);
"static" return(STATIC);
"template" return(TEMPLATE);
"typename" return(TYPENAME);
"typedef" return(TYPEDEF);
"namespace" return(NAMESPACE);
"using" return(USING);
"new" return(NEW);
"delete" return(DELETE);
"vtkFloatingPointType" return(DOUBLE);
"vtkIdType" return(IdType);
......@@ -219,7 +253,8 @@ Modify lex.yy.c:
"vtkTypeMacro" return(TypeMacro);
"vtkTypeRevisionMacro" return(TypeMacro);
"VTK_LEGACY" return(VTK_LEGACY);
"VTK_WRAP_EXTERN" return(VTK_WRAP_EXTERN);
"VTK_WRAP_EXTERN" ;
"VTK_BYTE_SWAP_DECL" return(VTK_BYTE_SWAP_DECL);
"vtkTypeInt8" return(TypeInt8);
"vtkTypeUInt8" return(TypeUInt8);
"vtkTypeInt16" return(TypeInt16);
......@@ -231,16 +266,51 @@ Modify lex.yy.c:
"vtkTypeFloat32" return(TypeFloat32);
"vtkTypeFloat64" return(TypeFloat64);
"const"[\r\n\t ]*"*" return(CONST_PTR);
"const"[\r\n\t ]*"&" return(CONST_REF);
"const"[\r\n\t ]*"=" return(CONST_EQUAL);
[0-9]+ { sscanf(yytext,"%d",&yylval.integer); return(NUM);}
[0-9]+"."[0-9]*([eE][+-]?[0-9]+)?[fFlL]? {
yylval.str = (char *)malloc(yyleng + 1);
memcpy(yylval.str,yytext,yyleng);
yylval.str[yyleng] = '\0';
return(FLOAT_LITERAL);
}
"0x"[0-9a-fA-F]+[uU]?[lL]? {
yylval.str = (char *)malloc(yyleng + 1);
memcpy(yylval.str,yytext,yyleng);
yylval.str[yyleng] = '\0';
return(HEX_LITERAL);
}
[0-9]+[uU]?[lL]? { yylval.str = (char *)malloc(yyleng + 1);
memcpy(yylval.str,yytext,yyleng);
yylval.str[yyleng] = '\0';
return(INT_LITERAL);
}
\"[^\"]+\" {
yylval.str = vtkstrdup(yytext + 1);
yylval.str[strlen(yytext)-2] = '\0';
return(STRING);
\"([^\"]|\\\")+\" {
yylval.str = (char *)malloc(yyleng + 1);
memcpy(yylval.str,yytext,yyleng);
yylval.str[yyleng] = '\0';
return(STRING_LITERAL);
}
\'([^\']|\\\')+\' {
yylval.str = (char *)malloc(yyleng + 1);
memcpy(yylval.str,yytext,yyleng);
yylval.str[yyleng] = '\0';
return(CHAR_LITERAL);
}
^"#"[^\n]*$ ;
^"#"[\t ]*"define"[\t ]+"VTK_"[a-zA-Z0-9_]+.*$ {
int i;
for (i = 0; i < yyleng && yytext[i] != 'V'; i++) { ; };
yylval.str = (char *)malloc(yyleng - i + 1);
memcpy(yylval.str, &yytext[i], yyleng-i);
yylval.str[yyleng-i] = '\0';
return (VTK_CONSTANT_DEF); }
^"#"(\\\n|\\\r\n|[^\n])*$ ;
"vtk"[0-9a-zA-Z_]* { yylval.str = (char *)malloc(yyleng + 1);
......@@ -255,14 +325,49 @@ Modify lex.yy.c:
return(ID);
}
[\t\n\r ] ;
"[" return(yytext[0]);
"]" return(yytext[0]);
"("[\t\n\r ]*"&" return(LPAREN_AMPERSAND);
"("[\t\n\r ]*([a-zA-Z_][a-zA-Z0-9_]*::)*"*" {
int i = 1;
while (yytext[i]==' ' || yytext[i]=='\r' || yytext[i]=='\n')
{ i++; }
yylval.str = vtkstrdup(yytext + i);
yylval.str[strlen(yytext)-2] = '\0';
return(LPAREN_POINTER);
}
[\t\n\r ] ;
[~{}():;*=,&.\-] { return(yytext[0]); }
"<<=" return(OP_LSHIFT_EQ);
">>=" return(OP_RSHIFT_EQ);
"<<" return(OP_LSHIFT);
"->*" return(OP_ARROW_POINTER);
"->" return(OP_ARROW);
">>" return(OP_RSHIFT);
"++" return(OP_INCR);
"--" return(OP_DECR);
"+=" return(OP_PLUS_EQ);
"-=" return(OP_MINUS_EQ);
"*=" return(OP_TIMES_EQ);
"/=" return(OP_DIVIDE_EQ);
"%=" return(OP_REMAINDER_EQ);
"&=" return(OP_AND_EQ);
"|=" return(OP_OR_EQ);
"^=" return(OP_XOR_EQ);
"&&=" return(OP_LOGIC_AND_EQ);
"||=" return(OP_LOGIC_OR_EQ);
"&&" return(OP_LOGIC_AND);
"||" return(OP_LOGIC_OR);
"==" return(OP_LOGIC_EQ);
"!=" return(OP_LOGIC_NEQ);
"<=" return(OP_LOGIC_LEQ);
">=" return(OP_LOGIC_GEQ);
"..." return(ELLIPSIS);
"::" return(DOUBLE_COLON);
"[" { return(yytext[0]); }
"]" { return(yytext[0]); }
[~{}()<>:;*/%=,&.!+|^\-] { return(yytext[0]); }
. return(OTHER);
%%
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
......@@ -61,21 +61,18 @@
/*
* Pointers, arrays, and references
* (note that [] and * are equivalent)
*
* 0x100 = &
* 0x300 = * or e.g. int val[n]
* 0x500 = *& i.e. a ref to a pointer, like vtkIdType* &pts
* 0x700 = ** or e.g. char *val[3]
*
* The following are defined, but not really supported by vtkParse:
* 0x200 = &&, 0x400 = &*, 0x600 = [n][m], 0x900 = [n][m][l]
*/
#define VTK_PARSE_INDIRECT 0xF00
#define VTK_PARSE_REF 0x100
#define VTK_PARSE_POINTER 0x300
#define VTK_PARSE_ARRAY_2D 0x600
#define VTK_PARSE_ARRAY_3D 0x900
#define VTK_PARSE_POINTER_REF 0x500
#define VTK_PARSE_POINTER_POINTER 0x700
#define VTK_PARSE_POINTER_CONST_REF 0x200
#define VTK_PARSE_POINTER_CONST_POINTER 0x400
#define VTK_PARSE_BAD_INDIRECT 0x800
/*
* The lowest two hex digits describe the basic type,
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment