Commit | Line | Data |
---|---|---|
970ed795 EL |
1 | /////////////////////////////////////////////////////////////////////////////// |
2 | // Copyright (c) 2000-2014 Ericsson Telecom AB | |
3 | // All rights reserved. This program and the accompanying materials | |
4 | // are made available under the terms of the Eclipse Public License v1.0 | |
5 | // which accompanies this distribution, and is available at | |
6 | // http://www.eclipse.org/legal/epl-v10.html | |
7 | /////////////////////////////////////////////////////////////////////////////// | |
8 | #include "../../common/memory.h" | |
9 | #include "RawAST.hh" | |
10 | #include <stdio.h> | |
11 | #include "../main.hh" | |
12 | ||
13 | RawAST::RawAST(){ | |
14 | init_rawast(false); | |
15 | } | |
16 | ||
17 | RawAST::RawAST(bool int_type){ | |
18 | init_rawast(int_type); | |
19 | } | |
20 | ||
21 | RawAST::RawAST(RawAST *other,bool int_type){ | |
22 | if(other){ | |
23 | fieldlength=other->fieldlength; | |
24 | comp=other->comp; | |
25 | byteorder=other->byteorder; | |
26 | align=other->align; | |
27 | bitorderinfield=other->bitorderinfield; | |
28 | bitorderinoctet=other->bitorderinoctet; | |
29 | extension_bit=other->extension_bit; | |
30 | hexorder=other->hexorder; | |
31 | padding=other->padding; | |
32 | prepadding=other->prepadding; | |
33 | padding_pattern_length=other->padding_pattern_length; | |
34 | if (other->padding_pattern != NULL) | |
35 | padding_pattern = mcopystr(other->padding_pattern); | |
36 | else padding_pattern = NULL; | |
37 | fieldorder=other->fieldorder; | |
38 | paddall=XDEFDEFAULT; | |
39 | repeatable=other->repeatable; | |
40 | ext_bit_goup_num=0; | |
41 | ext_bit_groups=NULL; | |
42 | lengthto_num=0; | |
43 | lengthto=NULL; | |
44 | pointerto=NULL; | |
45 | ptrbase=NULL; | |
46 | ptroffset=other->ptroffset; | |
47 | unit=other->unit; | |
48 | lengthindex=NULL; | |
49 | taglist.nElements=0; | |
50 | taglist.tag=NULL; | |
51 | crosstaglist.nElements=0; | |
52 | crosstaglist.tag=NULL; | |
53 | presence.fieldName=NULL; | |
54 | presence.nElements=0; | |
55 | presence.keyList=NULL; | |
56 | topleveleind=other->topleveleind; | |
57 | toplevel.bitorder=other->toplevel.bitorder; | |
58 | length_restrition=other->length_restrition; | |
59 | } | |
60 | else init_rawast(int_type); | |
61 | } | |
62 | ||
63 | void RawAST::init_rawast(bool int_type){ | |
64 | fieldlength=int_type?8:0; | |
65 | comp=XDEFDEFAULT; | |
66 | byteorder=XDEFDEFAULT; | |
67 | align=XDEFDEFAULT; | |
68 | bitorderinfield=XDEFDEFAULT; | |
69 | bitorderinoctet=XDEFDEFAULT; | |
70 | extension_bit=XDEFDEFAULT; | |
71 | ext_bit_goup_num=0; | |
72 | ext_bit_groups=NULL; | |
73 | hexorder=XDEFDEFAULT; | |
74 | repeatable=XDEFDEFAULT; | |
75 | paddall=XDEFDEFAULT; | |
76 | padding=0; | |
77 | prepadding=0; | |
78 | padding_pattern_length=0; | |
79 | padding_pattern=NULL; | |
80 | fieldorder=XDEFDEFAULT; | |
81 | lengthto_num=0; | |
82 | lengthto=NULL; | |
83 | pointerto=NULL; | |
84 | ptrbase=NULL; | |
85 | ptroffset=0; | |
86 | unit=8; | |
87 | lengthindex=NULL; | |
88 | length_restrition=-1; | |
89 | taglist.nElements=0; | |
90 | taglist.tag=NULL; | |
91 | crosstaglist.nElements=0; | |
92 | crosstaglist.tag=NULL; | |
93 | presence.fieldName=NULL; | |
94 | presence.nElements=0; | |
95 | presence.keyList=NULL; | |
96 | topleveleind=0; | |
97 | ||
98 | } | |
99 | ||
100 | RawAST::~RawAST(){ | |
101 | if(lengthto_num){ | |
102 | for(int a=0;a<lengthto_num;a++){delete lengthto[a];} | |
103 | Free(lengthto); | |
104 | } | |
105 | if(pointerto!=NULL){delete pointerto;} | |
106 | if(ptrbase!=NULL){delete ptrbase;} | |
107 | if(padding_pattern!=NULL){Free(padding_pattern);} | |
108 | free_rawAST_tag_list(&taglist); | |
109 | free_rawAST_tag_list(&crosstaglist); | |
110 | free_rawAST_single_tag(&presence); | |
111 | if(lengthindex!=NULL) { | |
112 | for(int a=0;a<lengthindex->nElements;a++) delete lengthindex->names[a]; | |
113 | Free(lengthindex->names); | |
114 | Free(lengthindex); | |
115 | } | |
116 | if(ext_bit_goup_num){ | |
117 | for(int a=0;a<ext_bit_goup_num;a++){ | |
118 | delete ext_bit_groups[a].from; | |
119 | delete ext_bit_groups[a].to; | |
120 | } | |
121 | Free(ext_bit_groups); | |
122 | } | |
123 | ||
124 | } | |
125 | ||
126 | void RawAST::print_RawAST(){ | |
127 | printf("Fieldlength: %d\n\r",fieldlength); | |
128 | printf("comp: %d\n\r",comp); | |
129 | printf("byteorder: %d\n\r",byteorder); | |
130 | printf("align: %d\n\r",align); | |
131 | printf("bitorderinfield: %d\n\r",bitorderinfield); | |
132 | printf("bitorderinoctet: %d\n\r",bitorderinoctet); | |
133 | printf("extension_bit: %d\n\r",extension_bit); | |
134 | printf("hexorder: %d\n\r",hexorder); | |
135 | printf("fieldorder: %d\n\r",fieldorder); | |
136 | printf("ptroffset: %d\n\r",ptroffset); | |
137 | printf("unit: %d\n\r",unit); | |
138 | printf("repeatable: %d\n\r",repeatable); | |
139 | printf("presence:\n\r"); | |
140 | printf(" nElements:%d \n\r",presence.nElements); | |
141 | for(int a=0;a<presence.nElements;a++){ | |
142 | printf(" Element%d:\n\r",a); | |
143 | printf(" value:%s\n\r",presence.keyList[a].value); | |
144 | printf(" field:"); | |
145 | for(int b=0;b<presence.keyList[a].keyField->nElements;b++){ | |
146 | printf("%s.",presence.keyList[a].keyField->names[b]->get_name().c_str()); | |
147 | } | |
148 | printf("\n\r"); | |
149 | } | |
150 | printf("crosstag:\n\r"); | |
151 | printf(" nElements:%d \n\r",crosstaglist.nElements); | |
152 | for(int a=0;a<crosstaglist.nElements;a++){ | |
153 | printf(" Element%d:\n\r",a); | |
154 | printf(" fieldname:%s\n\r",crosstaglist.tag[a].fieldName | |
155 | ->get_name().c_str()); | |
156 | printf(" nElements:%d\n\r",crosstaglist.tag[a].nElements); | |
157 | for(int c=0;c<crosstaglist.tag[a].nElements;c++){ | |
158 | printf(" Element%d:\n\r",c); | |
159 | printf(" value:%s\n\r",crosstaglist.tag[a].keyList[c].value); | |
160 | printf(" field:"); | |
161 | for(int b=0;b<crosstaglist.tag[a].keyList[c].keyField->nElements;b++){ | |
162 | printf("%s.",crosstaglist.tag[a].keyList[c].keyField->names[b] | |
163 | ->get_name().c_str()); | |
164 | } | |
165 | printf("\n\r"); | |
166 | } | |
167 | } | |
168 | printf("Tag:\n\r"); | |
169 | printf(" nElements:%d \n\r",taglist.nElements); | |
170 | for(int a=0;a<taglist.nElements;a++){ | |
171 | printf(" Element%d:\n\r",a); | |
172 | printf(" fieldname:%s\n\r",taglist.tag[a].fieldName | |
173 | ->get_name().c_str()); | |
174 | printf(" nElements:%d\n\r",taglist.tag[a].nElements); | |
175 | for(int c=0;c<taglist.tag[a].nElements;c++){ | |
176 | printf(" Element%d:\n\r",c); | |
177 | printf(" value:%s\n\r",taglist.tag[a].keyList[c].value); | |
178 | printf(" field:"); | |
179 | for(int b=0;b<taglist.tag[a].keyList[c].keyField->nElements;b++){ | |
180 | printf("%s.",taglist.tag[a].keyList[c].keyField->names[b] | |
181 | ->get_name().c_str()); | |
182 | } | |
183 | printf("\n\r"); | |
184 | } | |
185 | } | |
186 | ||
187 | } | |
188 | ||
189 | void copy_rawAST_to_struct(RawAST *from, raw_attrib_struct *to){ | |
190 | to->fieldlength=from->fieldlength; | |
191 | to->comp=from->comp; | |
192 | to->byteorder=from->byteorder; | |
193 | to->align=from->align; | |
194 | to->bitorderinfield=from->bitorderinfield; | |
195 | to->bitorderinoctet=from->bitorderinoctet; | |
196 | to->extension_bit=from->extension_bit; | |
197 | to->ext_bit_goup_num=from->ext_bit_goup_num; | |
198 | if (from->ext_bit_goup_num > 0) | |
199 | to->ext_bit_groups = (rawAST_coding_ext_group*) | |
200 | Malloc(from->ext_bit_goup_num * sizeof(*to->ext_bit_groups)); | |
201 | else to->ext_bit_groups = NULL; | |
202 | to->hexorder=from->hexorder; | |
203 | to->padding=from->padding; | |
204 | to->lengthto_num=from->lengthto_num; | |
205 | if (from->lengthto_num > 0) | |
206 | to->lengthto = (int*)Malloc(from->lengthto_num * sizeof(int)); | |
207 | else to->lengthto = NULL; | |
208 | to->pointerto=-1; | |
209 | to->ptroffset=from->ptroffset; | |
210 | to->unit=from->unit; | |
211 | if (from->lengthindex != NULL) | |
212 | to->lengthindex = (rawAST_coding_fields*) | |
213 | Malloc(sizeof(rawAST_coding_fields)); | |
214 | else to->lengthindex = NULL; | |
215 | to->crosstaglist.nElements = from->crosstaglist.nElements; | |
216 | if (to->crosstaglist.nElements > 0) { | |
217 | to->crosstaglist.list = (rawAST_coding_taglist*) | |
218 | Malloc(to->crosstaglist.nElements * sizeof(rawAST_coding_taglist)); | |
219 | for (int i = 0; i < to->crosstaglist.nElements; i++) { | |
220 | to->crosstaglist.list[i].nElements = 0; | |
221 | to->crosstaglist.list[i].fields = NULL; | |
222 | } | |
223 | } else to->crosstaglist.list = NULL; | |
224 | to->taglist.nElements = from->taglist.nElements; | |
225 | if (to->taglist.nElements > 0) { | |
226 | to->taglist.list = (rawAST_coding_taglist*) | |
227 | Malloc(to->taglist.nElements * sizeof(rawAST_coding_taglist)); | |
228 | for (int i = 0; i < to->taglist.nElements; i++) { | |
229 | to->taglist.list[i].nElements = 0; | |
230 | to->taglist.list[i].fields = NULL; | |
231 | } | |
232 | } else to->taglist.list = NULL; | |
233 | to->presence.nElements = from->presence.nElements; | |
234 | if (to->presence.nElements > 0) | |
235 | to->presence.fields=(rawAST_coding_field_list*) | |
236 | Malloc(to->presence.nElements * sizeof(rawAST_coding_field_list)); | |
237 | else to->presence.fields = NULL; | |
238 | to->topleveleind=from->topleveleind; | |
239 | to->toplevel.bitorder=from->toplevel.bitorder; | |
240 | to->union_member_num=0; | |
241 | to->member_name=NULL; | |
242 | to->repeatable=from->repeatable; | |
243 | to->length = -1; | |
244 | } | |
245 | ||
246 | void free_raw_attrib_struct(raw_attrib_struct *raw) | |
247 | { | |
248 | // extension bit groups | |
249 | Free(raw->ext_bit_groups); | |
250 | // lengthto | |
251 | Free(raw->lengthto); | |
252 | // lengthindex | |
253 | Free(raw->lengthindex); | |
254 | // tag | |
255 | for (int i = 0; i < raw->taglist.nElements; i++) { | |
256 | for (int j = 0; j < raw->taglist.list[i].nElements; j++) | |
257 | Free(raw->taglist.list[i].fields[j].fields); | |
258 | Free(raw->taglist.list[i].fields); | |
259 | } | |
260 | Free(raw->taglist.list); | |
261 | // crosstag | |
262 | for (int i = 0; i < raw->crosstaglist.nElements; i++) { | |
263 | for (int j = 0; j < raw->crosstaglist.list[i].nElements; j++) | |
264 | Free(raw->crosstaglist.list[i].fields[j].fields); | |
265 | Free(raw->crosstaglist.list[i].fields); | |
266 | } | |
267 | Free(raw->crosstaglist.list); | |
268 | // presence | |
269 | for (int i = 0; i < raw->presence.nElements; i++) | |
270 | Free(raw->presence.fields[i].fields); | |
271 | Free(raw->presence.fields); | |
272 | // member name | |
273 | Free(raw->member_name); | |
274 | } | |
275 | ||
276 | int compare_raw_attrib(RawAST *a, RawAST *b){ | |
277 | if(a==NULL) return 0; | |
278 | if(a==b) return 0; | |
279 | if(b==NULL) return 1; | |
280 | return a->fieldlength!=b->fieldlength || | |
281 | a->comp!=b->comp || | |
282 | a->byteorder!=b->byteorder || | |
283 | a->align!=b->align || | |
284 | a->bitorderinfield!=b->bitorderinfield || | |
285 | a->bitorderinoctet!=b->bitorderinoctet || | |
286 | a->extension_bit!=b->extension_bit || | |
287 | a->hexorder!=b->hexorder || | |
288 | a->fieldorder!=b->fieldorder || | |
289 | a->topleveleind!=b->topleveleind || | |
290 | (a->topleveleind && a->toplevel.bitorder!=b->toplevel.bitorder) || | |
291 | a->padding!=b->padding || | |
292 | a->ptroffset!=b->ptroffset || | |
293 | a->repeatable!=b->repeatable || | |
294 | a->unit!=b->unit; | |
295 | } |