2 * info.h - Store information about parsed "treecc" input files.
4 * Copyright (C) 2001 Southern Storm Software, Pty Ltd.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #ifndef _TREECC_INFO_H
22 #define _TREECC_INFO_H
31 * Forward declarations.
33 typedef struct _tagTreeCCField TreeCCField
;
34 typedef struct _tagTreeCCNode TreeCCNode
;
35 typedef struct _tagTreeCCOperation TreeCCOperation
;
36 typedef struct _tagTreeCCParam TreeCCParam
;
37 typedef struct _tagTreeCCVirtual TreeCCVirtual
;
38 typedef struct _tagTreeCCTrigger TreeCCTrigger
;
39 typedef struct _tagTreeCCOperationCase TreeCCOperationCase
;
42 * Field definition flags.
44 #define TREECC_FIELD_NOCREATE 1
47 * Node definition flags.
49 #define TREECC_NODE_UNDEFINED 1
50 #define TREECC_NODE_ABSTRACT 2
51 #define TREECC_NODE_TYPEDEF 4
52 #define TREECC_NODE_ENUM 8
53 #define TREECC_NODE_ENUM_VALUE 16
54 #define TREECC_NODE_MARK(n) (0x100 << (n))
55 #define TREECC_NODE_MARK_BITS 0xFF00
60 #define TREECC_OPER_VIRTUAL 1
61 #define TREECC_OPER_INLINE 2
62 #define TREECC_OPER_SPLIT 4
67 #define TREECC_PARAM_TRIGGER 1
72 #define TREECC_LANG_C 0
73 #define TREECC_LANG_CPP 1
74 #define TREECC_LANG_JAVA 2
75 #define TREECC_LANG_CSHARP 3
76 #define TREECC_LANG_RUBY 4
77 #define TREECC_LANG_PHP 5
80 * Information that is stored about a field.
82 struct _tagTreeCCField
84 char *name
; /* Name of the field */
85 char *type
; /* Type associated with the field */
86 char *value
; /* Default value for the field */
87 int flags
; /* Field flags */
88 char *filename
; /* File that defines the field */
89 long linenum
; /* Line where the field is defined */
90 TreeCCField
*next
; /* Next field for the node type */
95 * Information that is stored about a node type.
99 TreeCCNode
*parent
; /* Parent node type */
100 TreeCCNode
*firstChild
; /* First child node type */
101 TreeCCNode
*lastChild
; /* Last child node type */
102 TreeCCNode
*nextSibling
;/* Next sibling node type under parent */
103 char *name
; /* Name of this node type */
104 int flags
; /* Node flags */
105 int number
; /* Number associated with this node type */
106 int position
; /* Position within the tree for operations */
107 char *filename
; /* File that defines the node type */
108 long linenum
; /* Line where the node type is defined */
109 TreeCCField
*fields
; /* List of fields for this node type */
110 TreeCCVirtual
*virtuals
; /* List of virtual methods for this node */
111 TreeCCNode
*nextHash
; /* Next in the name hash table */
112 TreeCCStream
*header
; /* Stream to write header to */
113 TreeCCStream
*source
; /* Stream to write source to */
118 * Information that is stored about an operation.
120 struct _tagTreeCCOperation
122 char *name
; /* Name of the operation */
123 char *className
; /* Name of the enclosing class */
124 char *returnType
; /* Return type for the operation */
125 char *defValue
; /* Default value for the operation */
126 TreeCCParam
*params
; /* Parameters for the operation */
127 int flags
; /* Flags associated with the operation */
128 int numTriggers
;/* Number of trigger parameters */
129 char *filename
; /* File where the operation is declared */
130 long linenum
; /* Line where the operation is declared */
131 TreeCCOperation
*nextHash
; /* Next in the operation hash table */
132 TreeCCOperationCase
*firstCase
; /* First case associated with operation */
133 TreeCCOperationCase
*lastCase
; /* Last case associated with operation */
134 TreeCCOperationCase
**sortedCases
; /* Cases sorted for non-virtual ops */
135 int numCases
; /* Number of operation cases */
136 TreeCCStream
*header
; /* Stream to write header to */
137 TreeCCStream
*source
; /* Stream to write source to */
142 * Information that is stored about an operation parameter.
144 struct _tagTreeCCParam
146 char *name
; /* Name of the parameter */
147 char *type
; /* Type for the parameter */
148 int flags
; /* Flags associated with the parameter */
149 int size
; /* Dimension size for non-virtual operations */
150 TreeCCParam
*next
; /* Next parameter for the operation */
155 * Information that is stored about a virtual method on a node type.
157 struct _tagTreeCCVirtual
159 char *name
; /* Name of the virtual method */
160 char *returnType
; /* Return type for the virtual method */
161 TreeCCParam
*params
; /* Non-instance parameters */
162 TreeCCOperation
*oper
; /* Operation block for the virtual */
163 TreeCCVirtual
*next
; /* Next virtual method for the node type */
168 * Information that is stored about a trigger match on an operation case.
170 struct _tagTreeCCTrigger
172 TreeCCNode
*node
; /* Node type for the trigger */
173 TreeCCTrigger
*next
; /* Next trigger for this case */
178 * Information that is stored about an operation case.
180 struct _tagTreeCCOperationCase
182 TreeCCTrigger
*triggers
; /* Trigger list for this case */
183 char *code
; /* Code associated with the case */
184 TreeCCOperation
*oper
; /* Operation this case is associated with */
185 int number
; /* Reference number for code generation */
186 char *filename
; /* File that starts the case definition */
187 long linenum
; /* Line that starts the case definition */
188 char *codeFilename
;/* File that starts the code */
189 long codeLinenum
;/* Line that starts the code */
190 TreeCCOperationCase
*next
; /* Next case for the operation */
191 TreeCCOperationCase
*nextHeader
; /* Next header for same code block */
196 * Context object that stores all definitions parsed from the input.
198 #define TREECC_HASH_SIZE 512
199 typedef struct _tagTreeCCContext
201 /* Hash table that allows quick lookup of node types */
202 TreeCCNode
*nodeHash
[TREECC_HASH_SIZE
];
204 /* Hash table that allows quick lookup of operation names */
205 TreeCCOperation
*operHash
[TREECC_HASH_SIZE
];
207 /* Current input stream */
211 TreeCCStream
*streamList
; /* List of all streams */
212 TreeCCStream
*headerStream
; /* Current header stream */
213 TreeCCStream
*sourceStream
; /* Current source stream */
214 TreeCCStream
*commonHeader
; /* Stream for common definitions */
215 TreeCCStream
*commonSource
; /* Stream for common source */
217 /* Flags that control the behaviour of the program */
218 int debugMode
: 1; /* Enable debug output */
219 int track_lines
: 1; /* Track node creation lines */
220 int no_singletons
: 1; /* Don't handle singletons specially */
221 int reentrant
: 1; /* Build a re-entrant system */
222 int force
: 1; /* Force the creation of files */
223 int virtual_factory
: 1;/* Allow overrides of factory methods */
224 int abstract_factory
: 1;/* Declare factory methods abstract */
225 int kind_in_vtable
: 1; /* Put kind value in vtable only */
226 int strip_filenames
: 1; /* Strip names in #line directives */
227 int print_lines
: 1; /* Dont emit #line directives */
228 int internal_access
: 1; /* Use "internal" classes in C# */
229 int use_allocator
: 1; /* Use the skeleton allocator */
230 int use_gc_allocator
: 1; /* Use the libgc allocator */
232 /* String to use to replace "yy" in output files */
233 char *yy_replacement
;
235 /* Name of the type to use for re-entrant state */
238 /* Namespace to store declarations within */
241 /* Current node type number */
244 /* Output source language to use */
247 /* Size of blocks to use in C/C++ memory alloction */
250 /* Name of the directory to output Java source files to */
251 char *outputDirectory
;
253 /* name of the base type which is what %typedef expands to */
261 TreeCCContext
*TreeCCContextCreate(TreeCCInput
*input
);
266 void TreeCCContextDestroy(TreeCCContext
*context
);
271 unsigned int TreeCCHashString(const char *str
);
274 * Flags for "TreeCCAddLiteralDefn".
276 #define TREECC_LITERAL_CODE 1 /* In source */
277 #define TREECC_LITERAL_DECLS 2 /* In header */
278 #define TREECC_LITERAL_END 4 /* Place at end */
281 * Add a literal code definition block to the context.
283 void TreeCCAddLiteralDefn(TreeCCContext
*context
, char *code
, int flags
);
286 * Free a node definition.
288 void TreeCCNodeFree(TreeCCNode
*node
);
291 * Create a new node definition.
293 TreeCCNode
*TreeCCNodeCreate(TreeCCContext
*context
, long linenum
,
294 char *name
, char *parent
, int flags
);
297 * Find a node definition given its name.
299 TreeCCNode
*TreeCCNodeFind(TreeCCContext
*context
, const char *name
);
302 * Find a node definition given a type name, which may be
303 * either "identifier" or "identifier *".
305 TreeCCNode
*TreeCCNodeFindByType(TreeCCContext
*context
, const char *name
);
308 * Validate the node type hierarchy to ensure that everything is defined.
310 void TreeCCNodeValidate(TreeCCContext
*context
);
313 * Visit every node type in a context's hierarchy.
315 typedef void (*TreeCCNodeVisitor
)(TreeCCContext
*context
, TreeCCNode
*node
);
316 void TreeCCNodeVisitAll(TreeCCContext
*context
, TreeCCNodeVisitor visitor
);
319 * Determine if a node type is a singleton. i.e. no fields.
321 int TreeCCNodeIsSingleton(TreeCCNode
*node
);
324 * Determine if a node type has abstract virtual operation cases.
326 int TreeCCNodeHasAbstracts(TreeCCContext
*context
, TreeCCNode
*node
);
329 * Add a virtual operation to a node.
331 void TreeCCNodeAddVirtual(TreeCCContext
*context
, TreeCCNode
*node
,
332 TreeCCOperation
*oper
);
335 * Determine if "nodea" inherits from "nodeb".
337 int TreeCCNodeInheritsFrom(TreeCCNode
*nodea
, TreeCCNode
*nodeb
);
340 * Clear all marking bits that are used to track operation coverage.
342 void TreeCCNodeClearMarking(TreeCCContext
*context
, int flags
);
345 * Assign positions to all nodes started at a particular place
346 * in the node type hierarchy. Returns the number of positions.
348 int TreeCCNodeAssignPositions(TreeCCNode
*node
);
351 * Create a new field definition and add it to a node.
353 void TreeCCFieldCreate(TreeCCContext
*context
, TreeCCNode
*node
,
354 char *name
, char *type
, char *value
, int flags
);
359 void TreeCCOperationFree(TreeCCOperation
*oper
);
362 * Create a new operation.
364 TreeCCOperation
*TreeCCOperationCreate(TreeCCContext
*context
,
365 char *returnType
, char *name
,
366 char *className
, char *defValue
,
367 TreeCCParam
*params
, int flags
,
368 int numTriggers
, char *filename
,
372 * Find an operation with a specific name.
374 TreeCCOperation
*TreeCCOperationFind(TreeCCContext
*context
, char *name
);
377 * Add a case definition to an operation.
379 TreeCCOperationCase
*TreeCCOperationAddCase
380 (TreeCCContext
*context
, TreeCCOperation
*oper
,
381 TreeCCTrigger
*triggers
, char *filename
, long linenum
);
384 * Validate all operations.
386 void TreeCCOperationValidate(TreeCCContext
*context
);
389 * Find the operation case that corresponds to a virtual method.
390 * Returns NULL if the node does not have a virtual implementation.
392 TreeCCOperationCase
*TreeCCOperationFindCase
393 (TreeCCContext
*context
, TreeCCNode
*node
, char *name
);
396 * Visit all operations declared by a context.
398 typedef void (*TreeCCOperationVisitor
)(TreeCCContext
*context
,
399 TreeCCOperation
*oper
);
400 void TreeCCOperationVisitAll(TreeCCContext
*context
,
401 TreeCCOperationVisitor visitor
);
404 * Include the contents of a skeleton file in an output stream.
406 void TreeCCIncludeSkeleton(TreeCCContext
*context
, TreeCCStream
*stream
,
407 const char *skeleton
);
413 #endif /* _TREECC_INFO_H */