FreeWRL / FreeX3D 4.3.0
CParseParser.h
1/*
2
3
4Parser (input of non-terminal symbols) for CParse
5
6*/
7
8/****************************************************************************
9 This file is part of the FreeWRL/FreeX3D Distribution.
10
11 Copyright 2009 CRC Canada. (http://www.crc.gc.ca)
12
13 FreeWRL/FreeX3D is free software: you can redistribute it and/or modify
14 it under the terms of the GNU Lesser Public License as published by
15 the Free Software Foundation, either version 3 of the License, or
16 (at your option) any later version.
17
18 FreeWRL/FreeX3D is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 GNU General Public License for more details.
22
23 You should have received a copy of the GNU General Public License
24 along with FreeWRL/FreeX3D. If not, see <http://www.gnu.org/licenses/>.
25****************************************************************************/
26
27
28#ifndef __FREEWRL_CPARSE_PARSER_H__
29#define __FREEWRL_CPARSE_PARSER_H__
30
31void resetParseSuccessfullyFlag(void);
32int parsedSuccessfully(void);
33
34struct ProtoDefinition;
35struct Shader_Script;
36struct OffsetPointer;
37
39{
40 indexT mode; /* field, exposedField, eventIn, eventOut */
41 indexT type; /* field type */
42 indexT name; /* field "name" (its lexer-index) */
43 char *cname; /* field name */
44 char *fieldString; /* the field, in ascii form */
45 #ifdef OLDDEST
46/* This is the list of desination pointers for this field */
47 struct Vector* dests;
48#endif
49
50 /* Only for exposedField or field */
51 BOOL alreadySet; /* Has the value already been set? */
52 union anyVrml defaultVal; /* Default value */
53 /* Script fields */
54 struct Vector* scriptDests;
55};
56
57/* Constructor and destructor */
58struct ProtoFieldDecl* newProtoFieldDecl(indexT, indexT, indexT);
59void deleteProtoFieldDecl(struct ProtoFieldDecl*);
60int newProtoDefinitionPointer (struct ProtoDefinition *vrmlpd, int xmlpd);
61struct ProtoDefinition* newProtoDefinition();
62void deleteProtoDefinition(struct ProtoDefinition *ret);
63struct ProtoFieldDecl* copy_ProtoFieldDecl(struct ProtoFieldDecl *sdecl);
64
65/* Accessors */
66#define protoFieldDecl_getType(me) \
67 ((me)->type)
68#define protoFieldDecl_getAccessType(me) \
69 ((me)->mode)
70#define protoFieldDecl_getIndexName(me) \
71 ((me)->name)
72#define protoFieldDecl_getStringName(lex, me) \
73 lexer_stringUser_fieldName(lex, protoFieldDecl_getIndexName(me), \
74 protoFieldDecl_getAccessType(me))
75
76
77#define protoFieldDecl_getDefaultValue(me) \
78 ((me)->defaultVal)
79
80
81/* Finish this field - if value is not yet set, use default. */
82#define protoFieldDecl_finish(lex, me) \
83 if(((me)->mode==PKW_initializeOnly || (me)->mode==PKW_inputOutput) && \
84 !(me)->alreadySet) \
85 protoFieldDecl_setValue(lex, me, &(me)->defaultVal)
86
87/* ************************************************************************** */
88/* ****************************** ProtoDefinition *************************** */
89/* ************************************************************************** */
90
91/* The object */
93{
94 indexT protoDefNumber; /* unique sequence number */
95 struct Vector* iface; /* The ProtoFieldDecls making up the interface */
96 struct Vector* deconstructedProtoBody; /* PROTO body tokenized */
97 int estimatedBodyLen; /* an estimate of the expanded proto body size, to give us an output string len */
98 char *protoName; /* proto name as a string - used in EAI calls */
99 int isCopy; /* is this the original or a copy? the original keeps the deconstructedProtoBody */
100 int isExtern; /* a flag to tell interface parsing not to look for fieldvalues */
101};
102BOOL isProto(struct X3D_Node *);
103/* Adds a field declaration to the interface */
104#define protoDefinition_addIfaceField(me, field) \
105 vector_pushBack(struct ProtoFieldDecl*, (me)->iface, field)
106
107/* Get fields by indices */
108#define protoDefinition_getFieldCount(me) \
109 vectorSize((me)->iface)
110#define protoDefinition_getFieldByNum(me, i) \
111 vector_get(struct ProtoFieldDecl*, (me)->iface, i)
112
113/* Retrieves a field declaration of this PROTO */
114struct ProtoFieldDecl* protoDefinition_getField(struct ProtoDefinition*,
115 indexT, indexT);
116
117
118#define BLOCK_STATEMENT(LOCATION) \
119 if(parser_routeStatement(me)) { \
120 continue; \
121 } \
122 \
123 if (parser_componentStatement(me)) { \
124 continue; \
125 } \
126 \
127 if (parser_exportStatement(me)) { \
128 continue; \
129 } \
130 \
131 if (parser_importStatement(me)) { \
132 continue; \
133 } \
134 \
135 if (parser_metaStatement(me)) { \
136 continue; \
137 } \
138 \
139 if (parser_unitStatement(me)) { \
140 continue; \
141 } \
142 \
143 if (parser_profileStatement(me)) { \
144 continue; \
145 }
146
147/* This is our parser-object. */
149{
150 struct VRMLLexer* lexer; /* The lexer used. */
151 /* Where to put the parsed nodes? */
152 void *ectx; //broto executionContext
153 void* ptr; //node with mfnode field
154 unsigned ofs; //offset of mfnode field from ptr
155 /* Currently parsing a PROTO? */
156 struct ProtoDefinition* curPROTO;
157
158 /* This is the DEF/USE memory. */
159 Stack* DEFedNodes;
160
161 /* This is for PROTOs -- not stacked, as explained in CParseLexer.h */
162 struct Vector* PROTOs;
163
164 /* which format some field strings will be in - XML and "classic" VRML are different */
165 int parsingX3DfromXML;
166 Stack* brotoDEFedNodes;
167};
168
169/* Functions parsing a type by its index */
170extern BOOL (*PARSE_TYPE[])(struct VRMLParser*, void*);
171
172/* Constructor and destructor */
173struct VRMLParser* newParser(void *ectx, void* ptr, unsigned, int isX3DFormat);
174struct VRMLParser* reuseParser(void *ectx, void* ptr, unsigned);
175void deleteParser(struct VRMLParser*);
176
177/* Other clean up */
178void parser_destroyData(struct VRMLParser*);
179
180/* Scoping */
181void parser_scopeIn(struct VRMLParser*);
182void parser_scopeOut(struct VRMLParser*);
183
184/* Sets parser's input */
185#define parser_fromString(me, str) \
186 lexer_fromString(me->lexer, str)
187
188/* Parses SF* field values */
189#define parser_sffloatValue(me, ret) \
190 lexer_float(me->lexer, ret)
191#define parser_sfint32Value(me, ret) \
192 lexer_int32(me->lexer, ret)
193#define parser_sfstringValue(me, ret) \
194 lexer_string(me->lexer, ret)
195#define lexer_sfstringValue(me, ret) \
196 lexer_string(me, ret)
197
198/* Initializes node-specific fields */
199void parser_specificInitNode(struct X3D_Node*, struct VRMLParser*);
200
201/* Registers a ROUTE, in current PROTO or scene */
202void parser_registerRoute(struct VRMLParser*,
203 struct X3D_Node*, int, struct X3D_Node*, int, int);
204
205BOOL parseType(struct VRMLParser* me, int type, union anyVrml *defaultVal);
206
207
208void replaceProtoField(struct VRMLLexer *me, struct ProtoDefinition *thisProto, char *thisID, char **outTextPtr, size_t *outSize);
209
210void cParseErrorCurID(struct VRMLParser *me, char *str);
211void cParseErrorFieldString(struct VRMLParser *me, char *str1, const char *str2);
212
213#define CPARSE_ERROR_CURID(str) cParseErrorCurID(me, str);
214#define CPARSE_ERROR_FIELDSTRING(str1,str2) cParseErrorFieldString(me, str1, str2);
215
216/* Main parsing routine, parses the start symbol (vrmlScene) */
217BOOL parser_vrmlScene(struct VRMLParser*);
218
219BOOL nodeTypeSupportsUserFields(struct X3D_Node *node);
220int PKW_from_KW(int KW_index);
221BOOL find_anyfield_by_nameAndRouteDir( struct X3D_Node* node, union anyVrml **anyptr,
222 int *imode, int *itype, char* nodeFieldName, int *isource, void** fdecl, int *ifield, int PKW_eventType);
223BOOL found_IS_field(struct VRMLParser* me, struct X3D_Node *node);
224BOOL isAvailableBroto(const char *pname, struct X3D_Proto* currentContext, struct X3D_Proto **proto);
225void registerParentIfManagedField(int type, int mode, int isPublic, union anyVrml* any, struct X3D_Node* parent);
226void shallow_copy_field(int typeIndex, union anyVrml* source, union anyVrml* dest);
227BOOL usingBrotos();
228int X3DMODE(int val);
229void load_externProtoInstance (struct X3D_Proto *node);
230int getFieldFromNodeAndName(struct X3D_Node* node,const char *fieldname, int *type, int *kind, int *iifield, union anyVrml **value);
231int getFieldFromNodeAndIndexSource(struct X3D_Node* node, int ifield, int builtIn, const char **fieldname, int *type, int *kind, union anyVrml **value);
232int getFieldFromNodeAndIndex(struct X3D_Node* node, int ifield, const char **fieldname, int *type, int *kind, union anyVrml **value);
233void deep_copy_broto_body2(struct X3D_Proto** proto, struct X3D_Proto** dest);
234struct X3D_Proto *brotoInstance(struct X3D_Proto* proto, BOOL ideep);
235struct X3D_Proto *hasContext(struct X3D_Node* node);
237 struct X3D_Node* node;
238 char* name;
239};
240void add_node_to_broto_context(struct X3D_Proto *currentContext,struct X3D_Node *node);
241/* structure used for both import and export tables*/
242struct IMEXPORT {
243 struct X3D_Node *nodeptr; //used in exports to point to exported node in inline body, not used in imports
244 char *inlinename; //of inline, used only by imports
245 char *mxname; //of node being exported or imported, without AS alias/nickname
246 char *as; //nickname of mxname in local execution context as expressed by AS keyword, defaults to mxname if no AS, so normally use this when searching
247
248};
249struct IMEXPORT *broto_search_IMPORTname(struct X3D_Proto *context, const char *name);
250struct IMEXPORT *broto_search_EXPORTname(struct X3D_Proto *context, const char *name);
251#endif /* __FREEWRL_CPARSE_PARSER_H__ */