1 ///////////////////////////////////////////////////////////////////////////////
2 // Copyright (c) 2000-2015 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"
17 RawAST::RawAST(bool int_type
){
18 init_rawast(int_type
);
21 RawAST::RawAST(RawAST
*other
,bool int_type
){
23 fieldlength
=other
->fieldlength
;
25 byteorder
=other
->byteorder
;
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
;
39 repeatable
=other
->repeatable
;
46 ptroffset
=other
->ptroffset
;
51 crosstaglist
.nElements
=0;
52 crosstaglist
.tag
=NULL
;
53 presence
.fieldName
=NULL
;
55 presence
.keyList
=NULL
;
56 topleveleind
=other
->topleveleind
;
57 toplevel
.bitorder
=other
->toplevel
.bitorder
;
58 length_restrition
=other
->length_restrition
;
61 else init_rawast(int_type
);
64 void RawAST::init_rawast(bool int_type
){
65 fieldlength
=int_type
?8:0;
67 byteorder
=XDEFDEFAULT
;
69 bitorderinfield
=XDEFDEFAULT
;
70 bitorderinoctet
=XDEFDEFAULT
;
71 extension_bit
=XDEFDEFAULT
;
75 repeatable
=XDEFDEFAULT
;
79 padding_pattern_length
=0;
81 fieldorder
=XDEFDEFAULT
;
92 crosstaglist
.nElements
=0;
93 crosstaglist
.tag
=NULL
;
94 presence
.fieldName
=NULL
;
96 presence
.keyList
=NULL
;
103 for(int a
=0;a
<lengthto_num
;a
++){delete lengthto
[a
];}
106 if(pointerto
!=NULL
){delete pointerto
;}
107 if(ptrbase
!=NULL
){delete ptrbase
;}
108 if(padding_pattern
!=NULL
){Free(padding_pattern
);}
109 free_rawAST_tag_list(&taglist
);
110 free_rawAST_tag_list(&crosstaglist
);
111 free_rawAST_single_tag(&presence
);
112 if(lengthindex
!=NULL
) {
113 for(int a
=0;a
<lengthindex
->nElements
;a
++) delete lengthindex
->names
[a
];
114 Free(lengthindex
->names
);
117 if(ext_bit_goup_num
){
118 for(int a
=0;a
<ext_bit_goup_num
;a
++){
119 delete ext_bit_groups
[a
].from
;
120 delete ext_bit_groups
[a
].to
;
122 Free(ext_bit_groups
);
127 void RawAST::print_RawAST(){
128 printf("Fieldlength: %d\n\r",fieldlength
);
129 printf("comp: %d\n\r",comp
);
130 printf("byteorder: %d\n\r",byteorder
);
131 printf("align: %d\n\r",align
);
132 printf("bitorderinfield: %d\n\r",bitorderinfield
);
133 printf("bitorderinoctet: %d\n\r",bitorderinoctet
);
134 printf("extension_bit: %d\n\r",extension_bit
);
135 printf("hexorder: %d\n\r",hexorder
);
136 printf("fieldorder: %d\n\r",fieldorder
);
137 printf("ptroffset: %d\n\r",ptroffset
);
138 printf("unit: %d\n\r",unit
);
139 printf("repeatable: %d\n\r",repeatable
);
140 printf("presence:\n\r");
141 printf(" nElements:%d \n\r",presence
.nElements
);
142 for(int a
=0;a
<presence
.nElements
;a
++){
143 printf(" Element%d:\n\r",a
);
144 printf(" value:%s\n\r",presence
.keyList
[a
].value
);
146 for(int b
=0;b
<presence
.keyList
[a
].keyField
->nElements
;b
++){
147 printf("%s.",presence
.keyList
[a
].keyField
->names
[b
]->get_name().c_str());
151 printf("crosstag:\n\r");
152 printf(" nElements:%d \n\r",crosstaglist
.nElements
);
153 for(int a
=0;a
<crosstaglist
.nElements
;a
++){
154 printf(" Element%d:\n\r",a
);
155 printf(" fieldname:%s\n\r",crosstaglist
.tag
[a
].fieldName
156 ->get_name().c_str());
157 printf(" nElements:%d\n\r",crosstaglist
.tag
[a
].nElements
);
158 for(int c
=0;c
<crosstaglist
.tag
[a
].nElements
;c
++){
159 printf(" Element%d:\n\r",c
);
160 printf(" value:%s\n\r",crosstaglist
.tag
[a
].keyList
[c
].value
);
162 for(int b
=0;b
<crosstaglist
.tag
[a
].keyList
[c
].keyField
->nElements
;b
++){
163 printf("%s.",crosstaglist
.tag
[a
].keyList
[c
].keyField
->names
[b
]
164 ->get_name().c_str());
170 printf(" nElements:%d \n\r",taglist
.nElements
);
171 for(int a
=0;a
<taglist
.nElements
;a
++){
172 printf(" Element%d:\n\r",a
);
173 printf(" fieldname:%s\n\r",taglist
.tag
[a
].fieldName
174 ->get_name().c_str());
175 printf(" nElements:%d\n\r",taglist
.tag
[a
].nElements
);
176 for(int c
=0;c
<taglist
.tag
[a
].nElements
;c
++){
177 printf(" Element%d:\n\r",c
);
178 printf(" value:%s\n\r",taglist
.tag
[a
].keyList
[c
].value
);
180 for(int b
=0;b
<taglist
.tag
[a
].keyList
[c
].keyField
->nElements
;b
++){
181 printf("%s.",taglist
.tag
[a
].keyList
[c
].keyField
->names
[b
]
182 ->get_name().c_str());
187 printf("%sIntX encoding\n\r", intx
? "" : "not ");
190 void copy_rawAST_to_struct(RawAST
*from
, raw_attrib_struct
*to
){
191 to
->fieldlength
=from
->fieldlength
;
193 to
->byteorder
=from
->byteorder
;
194 to
->align
=from
->align
;
195 to
->bitorderinfield
=from
->bitorderinfield
;
196 to
->bitorderinoctet
=from
->bitorderinoctet
;
197 to
->extension_bit
=from
->extension_bit
;
198 to
->ext_bit_goup_num
=from
->ext_bit_goup_num
;
199 if (from
->ext_bit_goup_num
> 0)
200 to
->ext_bit_groups
= (rawAST_coding_ext_group
*)
201 Malloc(from
->ext_bit_goup_num
* sizeof(*to
->ext_bit_groups
));
202 else to
->ext_bit_groups
= NULL
;
203 to
->hexorder
=from
->hexorder
;
204 to
->padding
=from
->padding
;
205 to
->lengthto_num
=from
->lengthto_num
;
206 if (from
->lengthto_num
> 0)
207 to
->lengthto
= (int*)Malloc(from
->lengthto_num
* sizeof(int));
208 else to
->lengthto
= NULL
;
210 to
->ptroffset
=from
->ptroffset
;
212 if (from
->lengthindex
!= NULL
)
213 to
->lengthindex
= (rawAST_coding_fields
*)
214 Malloc(sizeof(rawAST_coding_fields
));
215 else to
->lengthindex
= NULL
;
216 to
->crosstaglist
.nElements
= from
->crosstaglist
.nElements
;
217 if (to
->crosstaglist
.nElements
> 0) {
218 to
->crosstaglist
.list
= (rawAST_coding_taglist
*)
219 Malloc(to
->crosstaglist
.nElements
* sizeof(rawAST_coding_taglist
));
220 for (int i
= 0; i
< to
->crosstaglist
.nElements
; i
++) {
221 to
->crosstaglist
.list
[i
].nElements
= 0;
222 to
->crosstaglist
.list
[i
].fields
= NULL
;
224 } else to
->crosstaglist
.list
= NULL
;
225 to
->taglist
.nElements
= from
->taglist
.nElements
;
226 if (to
->taglist
.nElements
> 0) {
227 to
->taglist
.list
= (rawAST_coding_taglist
*)
228 Malloc(to
->taglist
.nElements
* sizeof(rawAST_coding_taglist
));
229 for (int i
= 0; i
< to
->taglist
.nElements
; i
++) {
230 to
->taglist
.list
[i
].nElements
= 0;
231 to
->taglist
.list
[i
].fields
= NULL
;
233 } else to
->taglist
.list
= NULL
;
234 to
->presence
.nElements
= from
->presence
.nElements
;
235 if (to
->presence
.nElements
> 0)
236 to
->presence
.fields
=(rawAST_coding_field_list
*)
237 Malloc(to
->presence
.nElements
* sizeof(rawAST_coding_field_list
));
238 else to
->presence
.fields
= NULL
;
239 to
->topleveleind
=from
->topleveleind
;
240 to
->toplevel
.bitorder
=from
->toplevel
.bitorder
;
241 to
->union_member_num
=0;
242 to
->member_name
=NULL
;
243 to
->repeatable
=from
->repeatable
;
247 void free_raw_attrib_struct(raw_attrib_struct
*raw
)
249 // extension bit groups
250 Free(raw
->ext_bit_groups
);
254 Free(raw
->lengthindex
);
256 for (int i
= 0; i
< raw
->taglist
.nElements
; i
++) {
257 for (int j
= 0; j
< raw
->taglist
.list
[i
].nElements
; j
++)
258 Free(raw
->taglist
.list
[i
].fields
[j
].fields
);
259 Free(raw
->taglist
.list
[i
].fields
);
261 Free(raw
->taglist
.list
);
263 for (int i
= 0; i
< raw
->crosstaglist
.nElements
; i
++) {
264 for (int j
= 0; j
< raw
->crosstaglist
.list
[i
].nElements
; j
++)
265 Free(raw
->crosstaglist
.list
[i
].fields
[j
].fields
);
266 Free(raw
->crosstaglist
.list
[i
].fields
);
268 Free(raw
->crosstaglist
.list
);
270 for (int i
= 0; i
< raw
->presence
.nElements
; i
++)
271 Free(raw
->presence
.fields
[i
].fields
);
272 Free(raw
->presence
.fields
);
274 Free(raw
->member_name
);
277 int compare_raw_attrib(RawAST
*a
, RawAST
*b
){
278 if(a
==NULL
) return 0;
280 if(b
==NULL
) return 1;
281 return a
->fieldlength
!=b
->fieldlength
||
283 a
->byteorder
!=b
->byteorder
||
284 a
->align
!=b
->align
||
285 a
->bitorderinfield
!=b
->bitorderinfield
||
286 a
->bitorderinoctet
!=b
->bitorderinoctet
||
287 a
->extension_bit
!=b
->extension_bit
||
288 a
->hexorder
!=b
->hexorder
||
289 a
->fieldorder
!=b
->fieldorder
||
290 a
->topleveleind
!=b
->topleveleind
||
291 (a
->topleveleind
&& a
->toplevel
.bitorder
!=b
->toplevel
.bitorder
) ||
292 a
->padding
!=b
->padding
||
293 a
->ptroffset
!=b
->ptroffset
||
294 a
->repeatable
!=b
->repeatable
||
This page took 0.044068 seconds and 6 git commands to generate.