forked from Kitware/VTK
/
vtkParse.y
4868 lines (4260 loc) · 126 KB
/
vtkParse.y
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*=========================================================================
Program: Visualization Toolkit
Module: vtkParse.y
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
%{
/*
This file must be translated to C and modified to build everywhere.
Run bison like this (use bison 3.0.2 or later)
bison --no-lines -b vtkParse vtkParse.y
Modify vtkParse.tab.c:
- convert TABs to spaces (eight per tab)
- replace all instances of "static inline" with "static"
- replace "#if ! defined lint || defined __GNUC__" with "#if 1"
- remove YY_ATTRIBUTE_UNUSED from yyfillin, yyfill, and yynormal
- remove the "break;" after "return yyreportAmbiguity"
- replace "(1-yyrhslen)" with "(1-(int)yyrhslen)"
*/
/*
The purpose of this parser is to read C++ header files in order to
generate data structures that describe the C++ interface of a library,
one header file at a time. As such, it is not a complete C++ parser.
It only parses what is relevant to the interface and skips the rest.
While the parser reads method definitions, type definitions, and
template definitions it generates a "signature" which is a string
that matches (apart from whitespace) the text that was parsed.
While parsing types, the parser creates an unsigned int that describes
the type as well as creating other data structures for arrays, function
pointers, etc. The parser also creates a typeId string, which is either
a simple id that gives the class name or type name, or is "function" for
function pointer types, or "method" for method pointer types.
*/
/*
Conformance Notes:
This parser was designed empirically and incrementally. It has been
refactored to make it more similar to the C++ 1998 grammar, but there
are still many very significant differences.
The most significant difference between this parser and a "standard"
parser is that it only parses declarations in detail. All other
statements and expressions are parsed as arbitrary sequences of symbols,
without any syntactic analysis.
The "unqualified_id" does not directly include "operator_function_id" or
"conversion_function_id" (e.g. ids like "operator=" or "operator int*").
Instead, these two id types are used to allow operator functions to be
handled by their own rules, rather than by the generic function rules.
These ids can only be used in function declarations and using declarations.
Types are handled quite differently from the C++ BNF. These differences
represent a prolonged (and ultimately successful) attempt to empirically
create a yacc parser without any shift/reduce conflicts. The rules for
types are organized according to the way that types are usually defined
in working code, rather than strictly according to C++ grammar.
The declaration specifier "typedef" can only appear at the beginning
of a declaration sequence. There are also restrictions on where class
and enum specifiers can be used: you can declare a new struct within a
variable declaration, but not within a parameter declaration.
The lexer returns each of "(scope::*", "(*", "(a::b::*", etc. as single
tokens. The C++ BNF, in contrast, would consider these to be a "("
followed by a "ptr_operator". The lexer concatenates these tokens in
order to eliminate shift/reduce conflicts in the parser. However, this
means that this parser will only recognize "scope::*" as valid if it is
preceded by "(", e.g. as part of a member function pointer specification.
An odd bit of C++ ambiguity is that y(x); can be interpreted variously
as declaration of variable "x" of type "y", as a function call if "y"
is the name of a function, or as a constructor if "y" is the name of
a class. This parser always interprets this pattern as a constructor
declaration, because function calls are ignored by the parser, and
variable declarations of the form y(x); are exceedingly rare compared
to the more usual form y x; without parentheses.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define yyerror(a) print_parser_error(a, NULL, 0)
#define yywrap() 1
/* Make sure yacc-generated code knows we have included stdlib.h. */
#ifndef _STDLIB_H
# define _STDLIB_H
#endif
#define YYINCLUDED_STDLIB_H
/* Borland and MSVC do not define __STDC__ properly. */
#if !defined(__STDC__)
# if defined(_MSC_VER) || defined(__BORLANDC__)
# define __STDC__ 1
# endif
#endif
/* Disable warnings in generated code. */
#if defined(_MSC_VER)
# pragma warning (disable: 4127) /* conditional expression is constant */
# pragma warning (disable: 4244) /* conversion to smaller integer type */
#endif
#if defined(__BORLANDC__)
# pragma warn -8004 /* assigned a value that is never used */
# pragma warn -8008 /* conditional is always true */
# pragma warn -8066 /* unreachable code */
#endif
/* Map from the type anonymous_enumeration in vtkType.h to the
VTK wrapping type system number for the type. */
#include "vtkParse.h"
#include "vtkParsePreprocess.h"
#include "vtkParseData.h"
#include "vtkType.h"
static unsigned int vtkParseTypeMap[] =
{
VTK_PARSE_VOID, /* VTK_VOID 0 */
0, /* VTK_BIT 1 */
VTK_PARSE_CHAR, /* VTK_CHAR 2 */
VTK_PARSE_UNSIGNED_CHAR, /* VTK_UNSIGNED_CHAR 3 */
VTK_PARSE_SHORT, /* VTK_SHORT 4 */
VTK_PARSE_UNSIGNED_SHORT, /* VTK_UNSIGNED_SHORT 5 */
VTK_PARSE_INT, /* VTK_INT 6 */
VTK_PARSE_UNSIGNED_INT, /* VTK_UNSIGNED_INT 7 */
VTK_PARSE_LONG, /* VTK_LONG 8 */
VTK_PARSE_UNSIGNED_LONG, /* VTK_UNSIGNED_LONG 9 */
VTK_PARSE_FLOAT, /* VTK_FLOAT 10 */
VTK_PARSE_DOUBLE, /* VTK_DOUBLE 11 */
VTK_PARSE_ID_TYPE, /* VTK_ID_TYPE 12 */
VTK_PARSE_STRING, /* VTK_STRING 13 */
0, /* VTK_OPAQUE 14 */
VTK_PARSE_SIGNED_CHAR, /* VTK_SIGNED_CHAR 15 */
VTK_PARSE_LONG_LONG, /* VTK_LONG_LONG 16 */
VTK_PARSE_UNSIGNED_LONG_LONG, /* VTK_UNSIGNED_LONG_LONG 17 */
VTK_PARSE___INT64, /* VTK___INT64 18 */
VTK_PARSE_UNSIGNED___INT64, /* VTK_UNSIGNED___INT64 19 */
0, /* VTK_VARIANT 20 */
0, /* VTK_OBJECT 21 */
VTK_PARSE_UNICODE_STRING /* VTK_UNICODE_STRING 22 */
};
/* Define some constants to simplify references to the table lookup in
the primitive_type production rule code. */
#define VTK_PARSE_INT8 vtkParseTypeMap[VTK_TYPE_INT8]
#define VTK_PARSE_UINT8 vtkParseTypeMap[VTK_TYPE_UINT8]
#define VTK_PARSE_INT16 vtkParseTypeMap[VTK_TYPE_INT16]
#define VTK_PARSE_UINT16 vtkParseTypeMap[VTK_TYPE_UINT16]
#define VTK_PARSE_INT32 vtkParseTypeMap[VTK_TYPE_INT32]
#define VTK_PARSE_UINT32 vtkParseTypeMap[VTK_TYPE_UINT32]
#define VTK_PARSE_INT64 vtkParseTypeMap[VTK_TYPE_INT64]
#define VTK_PARSE_UINT64 vtkParseTypeMap[VTK_TYPE_UINT64]
#define VTK_PARSE_FLOAT32 vtkParseTypeMap[VTK_TYPE_FLOAT32]
#define VTK_PARSE_FLOAT64 vtkParseTypeMap[VTK_TYPE_FLOAT64]
#define vtkParseDebug(s1, s2) \
if ( parseDebug ) { fprintf(stderr, " %s %s\n", s1, s2); }
/* the tokenizer */
int yylex(void);
/* global variables */
FileInfo *data = NULL;
int parseDebug;
/* the "preprocessor" */
PreprocessInfo *preprocessor = NULL;
/* include dirs specified on the command line */
int NumberOfIncludeDirectories= 0;
const char **IncludeDirectories;
/* macros specified on the command line */
int NumberOfDefinitions = 0;
const char **Definitions;
/* options that can be set by the programs that use the parser */
int IgnoreBTX = 0;
int Recursive = 0;
const char *CommandName = NULL;
/* various state variables */
NamespaceInfo *currentNamespace = NULL;
ClassInfo *currentClass = NULL;
FunctionInfo *currentFunction = NULL;
TemplateInfo *currentTemplate = NULL;
const char *currentEnumName = NULL;
const char *currentEnumValue = NULL;
unsigned int currentEnumType = 0;
parse_access_t access_level = VTK_ACCESS_PUBLIC;
/* functions from vtkParse.l */
void print_parser_error(const char *text, const char *cp, size_t n);
/* helper functions */
const char *type_class(unsigned int type, const char *classname);
void start_class(const char *classname, int is_struct_or_union);
void end_class();
void add_base_class(ClassInfo *cls, const char *name, int access_lev,
unsigned int extra);
void output_friend_function(void);
void output_function(void);
void reject_function(void);
void set_return(FunctionInfo *func, unsigned int type,
const char *typeclass, int count);
void add_parameter(FunctionInfo *func, unsigned int type,
const char *classname, int count);
void add_template_parameter(unsigned int datatype,
unsigned int extra, const char *funcSig);
void add_using(const char *name, int is_namespace);
void start_enum(const char *name, int is_scoped,
unsigned int type, const char *basename);
void add_enum(const char *name, const char *value);
void end_enum();
unsigned int guess_constant_type(const char *value);
void add_constant(const char *name, const char *value,
unsigned int type, const char *typeclass, int global);
const char *add_const_scope(const char *name);
void prepend_scope(char *cp, const char *arg);
unsigned int guess_id_type(const char *cp);
unsigned int add_indirection(unsigned int tval, unsigned int ptr);
unsigned int add_indirection_to_array(unsigned int ptr);
void handle_complex_type(ValueInfo *val, unsigned int datatype,
unsigned int extra, const char *funcSig);
void handle_function_type(ValueInfo *param, const char *name,
const char *funcSig);
void add_legacy_parameter(FunctionInfo *func, ValueInfo *param);
void outputSetVectorMacro(const char *var, unsigned int paramType,
const char *typeText, int n);
void outputGetVectorMacro(const char *var, unsigned int paramType,
const char *typeText, int n);
/*----------------------------------------------------------------
* String utility methods
*
* Strings are centrally allocated and are const, and they are not
* freed until the program exits. If they need to be freed before
* then, vtkParse_FreeStringCache() can be called.
*/
/* duplicate the first n bytes of a string and terminate */
static const char *vtkstrndup(const char *in, size_t n)
{
return vtkParse_CacheString(data->Strings, in, n);
}
/* duplicate a string */
static const char *vtkstrdup(const char *in)
{
if (in)
{
in = vtkParse_CacheString(data->Strings, in, strlen(in));
}
return in;
}
/* helper function for concatenating strings */
static const char *vtkstrncat(size_t n, const char **str)
{
char *cp;
size_t i;
size_t j[8];
size_t m = 0;
for (i = 0; i < n; i++)
{
j[i] = 0;
if (str[i])
{
j[i] = strlen(str[i]);
m += j[i];
}
}
cp = vtkParse_NewString(data->Strings, m);
m = 0;
for (i = 0; i < n; i++)
{
if (j[i])
{
strncpy(&cp[m], str[i], j[i]);
m += j[i];
}
}
cp[m] = '\0';
return cp;
}
/* concatenate strings */
static const char *vtkstrcat(const char *str1, const char *str2)
{
const char *cp[2];
cp[0] = str1;
cp[1] = str2;
return vtkstrncat(2, cp);
}
static const char *vtkstrcat3(const char *str1, const char *str2,
const char *str3)
{
const char *cp[3];
cp[0] = str1;
cp[1] = str2;
cp[2] = str3;
return vtkstrncat(3, cp);
}
static const char *vtkstrcat4(const char *str1, const char *str2,
const char *str3, const char *str4)
{
const char *cp[4];
cp[0] = str1;
cp[1] = str2;
cp[2] = str3;
cp[3] = str4;
return vtkstrncat(4, cp);
}
static const char *vtkstrcat5(const char *str1, const char *str2,
const char *str3, const char *str4,
const char *str5)
{
const char *cp[5];
cp[0] = str1;
cp[1] = str2;
cp[2] = str3;
cp[3] = str4;
cp[4] = str5;
return vtkstrncat(5, cp);
}
static const char *vtkstrcat7(const char *str1, const char *str2,
const char *str3, const char *str4,
const char *str5, const char *str6,
const char *str7)
{
const char *cp[7];
cp[0] = str1;
cp[1] = str2;
cp[2] = str3;
cp[3] = str4;
cp[4] = str5;
cp[5] = str6;
cp[6] = str7;
return vtkstrncat(7, cp);
}
/*----------------------------------------------------------------
* Comments
*/
/* "private" variables */
char *commentText = NULL;
size_t commentLength = 0;
size_t commentAllocatedLength = 0;
int commentState = 0;
const char *getComment()
{
if (commentState != 0)
{
return commentText;
}
return NULL;
}
void clearComment()
{
commentLength = 0;
if (commentText)
{
commentText[commentLength] = '\0';
}
commentState = 0;
}
void addCommentLine(const char *line, size_t n)
{
if (commentState <= 0)
{
clearComment();
return;
}
if (commentText == NULL)
{
commentAllocatedLength = n+80;
commentText = (char *)malloc(commentAllocatedLength);
commentLength = 0;
commentText[0] = '\0';
}
else if (commentLength + n + 2 > commentAllocatedLength)
{
commentAllocatedLength = commentAllocatedLength + commentLength + n + 2;
commentText = (char *)realloc(commentText, commentAllocatedLength);
if (!commentText)
{
fprintf(stderr, "Wrapping: out of memory\n");
exit(1);
}
}
if (n > 0)
{
memcpy(&commentText[commentLength], line, n);
}
commentLength += n;
commentText[commentLength++] = '\n';
commentText[commentLength] = '\0';
}
void closeComment()
{
switch (commentState)
{
case 1:
/* Make comment persist until a new comment starts */
commentState = -1;
break;
case 2:
data->Description = vtkstrdup(getComment());
clearComment();
break;
case 3:
data->SeeAlso = vtkstrdup(getComment());
clearComment();
break;
case 4:
data->Caveats = vtkstrdup(getComment());
clearComment();
break;
}
}
void closeOrClearComment()
{
if (commentState < 0)
{
clearComment();
}
else
{
closeComment();
}
}
void setCommentState(int state)
{
switch (state)
{
case 0:
closeComment();
break;
default:
closeComment();
clearComment();
break;
}
commentState = state;
}
/*----------------------------------------------------------------
* Macros
*/
/* "private" variables */
const char *macroName = NULL;
int macroUsed = 0;
int macroEnded = 0;
const char *getMacro()
{
if (macroUsed == 0)
{
macroUsed = macroEnded;
return macroName;
}
return NULL;
}
/*----------------------------------------------------------------
* Namespaces
*
* operates on: currentNamespace
*/
/* "private" variables */
NamespaceInfo *namespaceStack[10];
int namespaceDepth = 0;
/* enter a namespace */
void pushNamespace(const char *name)
{
int i;
NamespaceInfo *oldNamespace = currentNamespace;
for (i = 0; i < oldNamespace->NumberOfNamespaces; i++)
{
/* see if the namespace already exists */
if (strcmp(name, oldNamespace->Namespaces[i]->Name) == 0)
{
currentNamespace = oldNamespace->Namespaces[i];
}
}
/* create a new namespace */
if (i == oldNamespace->NumberOfNamespaces)
{
currentNamespace = (NamespaceInfo *)malloc(sizeof(NamespaceInfo));
vtkParse_InitNamespace(currentNamespace);
currentNamespace->Name = name;
vtkParse_AddNamespaceToNamespace(oldNamespace, currentNamespace);
}
namespaceStack[namespaceDepth++] = oldNamespace;
}
/* leave the namespace */
void popNamespace()
{
currentNamespace = namespaceStack[--namespaceDepth];
}
/*----------------------------------------------------------------
* Classes
*
* operates on: currentClass, access_level
*/
/* "private" variables */
ClassInfo *classStack[10];
parse_access_t classAccessStack[10];
int classDepth = 0;
/* start an internal class definition */
void pushClass()
{
classAccessStack[classDepth] = access_level;
classStack[classDepth++] = currentClass;
}
/* leave the internal class */
void popClass()
{
currentClass = classStack[--classDepth];
access_level = classAccessStack[classDepth];
}
/*----------------------------------------------------------------
* Templates
*
* operates on: currentTemplate
*/
/* "private" variables */
TemplateInfo *templateStack[10];
int templateDepth = 0;
/* begin a template */
void startTemplate()
{
currentTemplate = (TemplateInfo *)malloc(sizeof(TemplateInfo));
vtkParse_InitTemplate(currentTemplate);
}
/* clear a template, if set */
void clearTemplate()
{
if (currentTemplate)
{
free(currentTemplate);
}
currentTemplate = NULL;
}
/* push the template onto the stack, and start a new one */
void pushTemplate()
{
templateStack[templateDepth++] = currentTemplate;
startTemplate();
}
/* pop a template off the stack */
void popTemplate()
{
currentTemplate = templateStack[--templateDepth];
}
/*----------------------------------------------------------------
* Function signatures
*
* operates on: currentFunction
*/
/* "private" variables */
int sigClosed = 0;
size_t sigMark[10];
size_t sigLength = 0;
size_t sigAllocatedLength = 0;
int sigMarkDepth = 0;
char *signature = NULL;
/* start a new signature */
void startSig()
{
signature = NULL;
sigLength = 0;
sigAllocatedLength = 0;
sigClosed = 0;
sigMarkDepth = 0;
sigMark[0] = 0;
}
/* get the signature */
const char *getSig()
{
return signature;
}
/* get the signature length */
size_t getSigLength()
{
return sigLength;
}
/* reset the sig to the specified length */
void resetSig(size_t n)
{
if (n < sigLength)
{
sigLength = n;
}
}
/* reallocate Signature if n chars cannot be appended */
void checkSigSize(size_t n)
{
const char *ccp;
if (sigAllocatedLength == 0)
{
sigLength = 0;
sigAllocatedLength = 80 + n;
signature = vtkParse_NewString(data->Strings, sigAllocatedLength);
signature[0] = '\0';
}
else if (sigLength + n > sigAllocatedLength)
{
sigAllocatedLength += sigLength + n;
ccp = signature;
signature = vtkParse_NewString(data->Strings, sigAllocatedLength);
strncpy(signature, ccp, sigLength);
signature[sigLength] = '\0';
}
}
/* close the signature, i.e. allow no more additions to it */
void closeSig()
{
sigClosed = 1;
}
/* re-open the signature */
void openSig()
{
sigClosed = 0;
}
/* insert text at the beginning of the signature */
void preSig(const char *arg)
{
if (!sigClosed)
{
size_t n = strlen(arg);
checkSigSize(n);
if (n > 0)
{
memmove(&signature[n], signature, sigLength);
strncpy(signature, arg, n);
sigLength += n;
}
signature[sigLength] = '\0';
}
}
/* append text to the end of the signature */
void postSig(const char *arg)
{
if (!sigClosed)
{
size_t n = strlen(arg);
checkSigSize(n);
if (n > 0)
{
strncpy(&signature[sigLength], arg, n);
sigLength += n;
}
signature[sigLength] = '\0';
}
}
/* set a mark in the signature for later operations */
void markSig()
{
sigMark[sigMarkDepth] = 0;
if (signature)
{
sigMark[sigMarkDepth] = sigLength;
}
sigMarkDepth++;
}
/* get the contents of the sig from the mark, and clear the mark */
const char *copySig()
{
const char *cp = NULL;
if (sigMarkDepth > 0)
{
sigMarkDepth--;
}
if (signature)
{
cp = &signature[sigMark[sigMarkDepth]];
}
return vtkstrdup(cp);
}
/* swap the signature text using the mark as the radix */
void swapSig()
{
if (sigMarkDepth > 0)
{
sigMarkDepth--;
}
if (signature && sigMark[sigMarkDepth] > 0)
{
size_t i, m, n, nn;
char c;
char *cp;
cp = signature;
n = sigLength;
m = sigMark[sigMarkDepth];
nn = m/2;
for (i = 0; i < nn; i++)
{
c = cp[i]; cp[i] = cp[m-i-1]; cp[m-i-1] = c;
}
nn = (n-m)/2;
for (i = 0; i < nn; i++)
{
c = cp[i+m]; cp[i+m] = cp[n-i-1]; cp[n-i-1] = c;
}
nn = n/2;
for (i = 0; i < nn; i++)
{
c = cp[i]; cp[i] = cp[n-i-1]; cp[n-i-1] = c;
}
}
}
/* chop the last space from the signature */
void chopSig(void)
{
if (signature)
{
size_t n = sigLength;
if (n > 0 && signature[n-1] == ' ')
{
signature[n-1] = '\0';
sigLength--;
}
}
}
/*----------------------------------------------------------------
* Subroutines for building a type
*/
/* "private" variables */
unsigned int storedType;
unsigned int typeStack[10];
int typeDepth = 0;
/* save the type on the stack */
void pushType()
{
typeStack[typeDepth++] = storedType;
}
/* pop the type stack */
void popType()
{
storedType = typeStack[--typeDepth];
}
/* clear the storage type */
void clearType()
{
storedType = 0;
}
/* save the type */
void setTypeBase(unsigned int base)
{
storedType &= ~(unsigned int)(VTK_PARSE_BASE_TYPE);
storedType |= base;
}
/* set a type modifier bit */
void setTypeMod(unsigned int mod)
{
storedType |= mod;
}
/* modify the indirection (pointers, refs) in the storage type */
void setTypePtr(unsigned int ind)
{
storedType &= ~(unsigned int)(VTK_PARSE_INDIRECT | VTK_PARSE_RVALUE);
ind &= (VTK_PARSE_INDIRECT | VTK_PARSE_RVALUE);
storedType |= ind;
}
/* retrieve the storage type */
unsigned int getType()
{
return storedType;
}
/* combine two primitive type parts, e.g. "long int" */
unsigned int buildTypeBase(unsigned int a, unsigned int b)
{
unsigned int base = (a & VTK_PARSE_BASE_TYPE);
unsigned int basemod = (b & VTK_PARSE_BASE_TYPE);
switch (base)
{
case 0:
base = basemod;
break;
case VTK_PARSE_UNSIGNED_INT:
base = (basemod | VTK_PARSE_UNSIGNED);
break;
case VTK_PARSE_INT:
base = basemod;
if (base == VTK_PARSE_CHAR)
{
base = VTK_PARSE_SIGNED_CHAR;
}
break;
case VTK_PARSE_CHAR:
if (basemod == VTK_PARSE_INT)
{
base = VTK_PARSE_SIGNED_CHAR;
}
else if (basemod == VTK_PARSE_UNSIGNED_INT)
{
base = VTK_PARSE_UNSIGNED_CHAR;
}
break;
case VTK_PARSE_SHORT:
if (basemod == VTK_PARSE_UNSIGNED_INT)
{
base = VTK_PARSE_UNSIGNED_SHORT;
}
break;
case VTK_PARSE_LONG:
if (basemod == VTK_PARSE_UNSIGNED_INT)
{
base = VTK_PARSE_UNSIGNED_LONG;
}
else if (basemod == VTK_PARSE_LONG)
{
base = VTK_PARSE_LONG_LONG;
}
else if (basemod == VTK_PARSE_DOUBLE)
{
base = VTK_PARSE_LONG_DOUBLE;
}
break;
case VTK_PARSE_UNSIGNED_LONG:
if (basemod == VTK_PARSE_LONG)
{
base = VTK_PARSE_UNSIGNED_LONG_LONG;
}
break;
case VTK_PARSE_LONG_LONG:
if (basemod == VTK_PARSE_UNSIGNED_INT)
{
base = VTK_PARSE_UNSIGNED_LONG_LONG;
}
break;
case VTK_PARSE___INT64:
if (basemod == VTK_PARSE_UNSIGNED_INT)
{
base = VTK_PARSE_UNSIGNED___INT64;
}
break;
case VTK_PARSE_DOUBLE:
if (basemod == VTK_PARSE_LONG)
{
base = VTK_PARSE_LONG_DOUBLE;
}
break;
}
return ((a & ~(unsigned int)(VTK_PARSE_BASE_TYPE)) | base);
}
/*----------------------------------------------------------------
* Array information
*/
/* "private" variables */
int numberOfDimensions = 0;
const char **arrayDimensions = NULL;
/* clear the array counter */
void clearArray(void)
{
numberOfDimensions = 0;
arrayDimensions = NULL;
}
/* add another dimension */
void pushArraySize(const char *size)
{
vtkParse_AddStringToArray(&arrayDimensions, &numberOfDimensions,
size);
}
/* add another dimension to the front */
void pushArrayFront(const char *size)
{
int i;
vtkParse_AddStringToArray(&arrayDimensions, &numberOfDimensions, 0);
for (i = numberOfDimensions-1; i > 0; i--)
{
arrayDimensions[i] = arrayDimensions[i-1];
}
arrayDimensions[0] = size;
}
/* get the number of dimensions */
int getArrayNDims()
{
return numberOfDimensions;
}
/* get the whole array */
const char **getArray()
{
if (numberOfDimensions > 0)
{
return arrayDimensions;
}
return NULL;
}
/*----------------------------------------------------------------
* Variables and Parameters
*/
/* "private" variables */
const char *currentVarName = 0;
const char *currentVarValue = 0;