comments updated
[henge/apc.git] / src / ir.h
1 /*!@file
2
3 \brief Intermediate Representation (IR) between Directory Structure and Engine
4 Input
5
6 \details The IR serves as a storage structure that is populated during the
7 parsing of the input directory structure. After parsing is complete,
8 the IR will be condensed (removed of excess allocated space) and then
9 output as the input for the engine. In this file we describe the
10 semantic actions that are called at each step, and the memory buffers
11 that they populate. See parser.y for the description on how the input
12 grammar is constructed, and where/when semantic actions are called.
13
14 All input values are duplicated internally and their memory may be
15 freed.
16
17 \author Jordan Lavatai
18 \date Aug 2016
19 ----------------------------------------------------------------------------*/
20 #ifndef _IR_H_
21 #define _IR_H_
22 #include <unitypes.h>
23 #include "apc.h"
24
25 typedef union ir_setdata_t* ir_setdata;
26 typedef struct ir_frameinfo_t* ir_frameinfo;
27 typedef struct ir_set_t* ir_set;
28 typedef struct ir_class_t* ir_class;
29 typedef struct ir_setld_t* ir_setld;
30 typedef struct ir_classld_t* ir_classld;
31 typedef struct ir_facinglist_t* facinglist;
32 /* Classes and Sets
33 Classes are rooted at a special root class, representing the current working
34 directory at scan-time, named ".". The root class can always be identified
35 with ir_class_root, and children may be added to it. The add series of
36 functions will return a reference to the newly created object, which may also
37 be used the root for further add functions.
38
39 E.G.
40 ir_class x = ir_class_root();
41 x = ir_class_addchild(x, "mychild");
42 x = ir_class_addchild(x, "child of mychild");
43
44 Sets, like classes, must be rooted. Unlike classes, sets may be rooted on
45 other sets, in addition to classes. ir_class_addset will return a set rooted
46 on the class specified, while ir_set_addchild will return a set rooted on the
47 specified set.
48 */
49 ir_class ir_class_root(void);
50 ir_class ir_class_addchild(ir_class,const uint8_t*);
51 uint8_t* ir_class_name(ir_class);
52 ir_set ir_class_addset(ir_class,const uint8_t*);
53 ir_set ir_class_rootset(ir_class);
54 ir_set ir_set_addchild(ir_set,const uint8_t*);
55 uint8_t* ir_set_name(ir_set);
56 /* Output */
57 ir_class ir_class_nextsib(ir_class);
58 ir_class ir_class_nextchild(ir_class);
59 long ir_class_fpos(ir_class);
60 void ir_class_assign_fpos(ir_class,long);
61 ir_set ir_set_from_ref(uint32_t);
62 ir_set ir_set_nextsib(ir_set);
63 ir_set ir_set_nextchild(ir_set);
64 long ir_set_fpos(ir_set);
65 void ir_set_assign_fpos(ir_set,long);
66 /* Set Data
67 Each set can contain up to FACING_MAX each of framesheets and mapsheets, one
68 sheet for each facing, per label. Each set can contain any number of audio
69 objects, supplied by label. Repeat assignment of conflicting data (e.g. two
70 SFACE framesheets assigned to the same set and label, or two audio objects
71 with the same label) causes an internal error.
72 Each set may also contain any number of link objects, which will be linked in
73 the order that they are encountered. At link time, repeated assignments of
74 conflicting data cause data to be silently overwritten for those sets. This
75 is an intentional side-effect of the linker.
76 Each setdata may have a path associated with it. If the data depends on the
77 data of an associated file at that path and no path is provided, the data
78 will be entered null.
79 */
80 typedef ir_setdata framebox;
81 typedef ir_setdata audiodata;
82 typedef ir_setdata linkdata;
83 typedef ir_setdata framedata;
84 enum ltype { OLINK, MLINK, VLINK, ALINK };
85 void ir_set_assign_data(ir_set,ir_setdata);
86 void ir_set_assign_ref(ir_set,uint32_t);
87 void ir_data_assign_path(ir_setdata,const uint8_t*);
88 ir_setdata ir_framesheet(const uint8_t*,facinglist,int,int);
89 ir_setdata ir_mapsheet(const uint8_t*,facinglist,int,int);
90 ir_setdata ir_audio(const uint8_t*);
91 ir_setdata ir_link(enum ltype,ir_setld,const uint8_t*);
92 /* Facing Lists for creating frame/mapsheets */
93 facinglist ir_facinglist(apc_facing);
94 facinglist ir_facinglist_push(facinglist,apc_facing);
95 /* Output */
96 framebox ir_set_framebox(ir_set);
97 audiodata ir_set_audio(ir_set);
98 linkdata ir_set_link(ir_set);
99 enum ltype ir_linkdata_type(linkdata);
100 uint32_t ir_linkdata_ref(linkdata);
101 ir_set ir_linkdata_set(linkdata);
102 void ir_linkdata_assign_set(linkdata,ir_set);
103 void ir_linkdata_assign_type(linkdata,enum ltype);
104 uint8_t* ir_linkdata_dlink_name(linkdata);
105 ir_setdata ir_setdata_nextsib(ir_setdata);
106 uint8_t* ir_setdata_name(ir_setdata);
107 uint8_t* ir_setdata_filename(ir_setdata);
108 long ir_setdata_fpos(ir_setdata);
109 void ir_setdata_assign_fpos(ir_setdata,long);
110 void ir_setdata_assign_name(ir_setdata,uint8_t*);
111 /* Framedata */
112 framedata ir_framebox_framesheet(framebox,apc_facing);
113 framedata ir_framebox_mapsheet(framebox,apc_facing);
114 int ir_framedata_width(framedata);
115 int ir_framedata_height(framedata);
116 apc_facing ir_framedata_firstfacing(framedata);
117 apc_facing ir_framedata_nextfacing(framedata);
118 /* Reference Linking Data
119 Create linking data to sets or classes that will be resolved at a later
120 stage. Class references can be created from an ir_class object, if
121 available, or from the root class. Set references can be created from a
122 64-bit integer ID, or from a class linking data and a child name. Once
123 created, both Class and Set link data can traverse children, specified by
124 name, which will be resolved at the linking stage as well.
125 */
126 ir_classld ir_classld_from_class(ir_class);
127 ir_classld ir_classld_from_root(void);
128 ir_classld ir_classld_addchild(ir_classld,const uint8_t*);
129 ir_setld ir_setld_from_ref(uint32_t);
130 ir_setld ir_setld_from_classld(ir_classld,const uint8_t*);
131 ir_setld ir_setld_addchild(ir_setld,const uint8_t*);
132 /* Output */
133 enum ltype ir_setld_type(ir_setld);
134 uint32_t ir_setld_ref(ir_setld);
135 #endif //_IR_H_