Commit 0cb40f9a authored by Gábor Szalai's avatar Gábor Szalai
Browse files

Correcting Boolean default length handling



The default field length for boolean was not set, when rawAST descriptor
was generated for boolean types. The default length was set only for integer
and real at some places.

The fault was unnoticed because the RAW_encoder and decoder treated the 0 as
the default 1.
But when the raw offset/lenght was calculated by the compiler the boolean
fields was treated as zero length field, resulting a faulty offset for TAG fields

Change-Id: I12809fb00cfb60a3fb3f839b2023be16ed631a3a
Signed-off-by: Gábor Szalai's avatarGabor Szalai <gabor.szalai@ericsson.com>
parent e37a5f8e
......@@ -1911,6 +1911,26 @@ namespace Common {
return false;
}
int Type::get_default_raw_fieldlength(){
switch(typetype) {
case T_REFD:
return get_type_refd_last()->get_default_raw_fieldlength();
break;
case T_INT:
return 8;
break;
case T_BOOL:
return 1;
break;
case T_REAL:
return 64;
break;
default:
break;
}
return 0;
}
int Type::get_raw_length(){
if(!raw_checked) FATAL_ERROR("Type::get_raw_length()");
if(raw_length_calculated) return raw_length;
......@@ -1919,13 +1939,11 @@ namespace Common {
case T_REFD:
raw_length=get_type_refd()->get_raw_length();
break;
case T_INT:
if(rawattrib) raw_length=rawattrib->fieldlength;
else raw_length=8;
break;
case T_BOOL:
case T_INT:
case T_REAL:
if(rawattrib) raw_length=rawattrib->fieldlength;
else raw_length=1;
else raw_length=get_default_raw_fieldlength();
break;
case T_BSTR:
case T_HSTR:
......@@ -2011,10 +2029,7 @@ namespace Common {
restrlength=(int)sub_type->get_length_restriction();
if(restrlength!=-1){
if(!rawattrib){
Type *t=get_type_refd_last();
typetype_t basic_type=t->typetype;
rawattrib=new RawAST(basic_type==T_INT);
if(basic_type==T_REAL) rawattrib->fieldlength=64;
rawattrib=new RawAST(get_default_raw_fieldlength());
}
rawattrib->length_restrition=restrlength;
}
......@@ -2199,14 +2214,10 @@ namespace Common {
CompField *cfield=get_comp_byIndex(i);
RawAST *field_rawattr=cfield->get_type()->rawattrib;
if(field_rawattr==NULL){
Type *t=cfield->get_type()->get_type_refd_last();
typetype_t basic_type=t->typetype;
t=cfield->get_type();
Type *t=cfield->get_type();
if(t->is_ref()) t=t->get_type_refd();
while(!t->rawattrib && t->is_ref()) t=t->get_type_refd();
field_rawattr= new RawAST(t->rawattrib,basic_type==T_INT);
if(!t->rawattrib && basic_type==T_REAL) field_rawattr->fieldlength=64;
cfield->get_type()->rawattrib=field_rawattr;
cfield->get_type()->rawattrib= new RawAST(t->rawattrib,cfield->get_type()->get_default_raw_fieldlength());
}
if(field_rawattr->padding==0)
field_rawattr->padding=rawattrib->padding;
......@@ -2227,14 +2238,10 @@ namespace Common {
CompField *cfield=get_comp_byIndex(i);
RawAST *field_rawattr=cfield->get_type()->rawattrib;
if(field_rawattr==NULL){
Type *t=cfield->get_type()->get_type_refd_last();
typetype_t basic_type=t->typetype;
t=cfield->get_type();
Type *t=cfield->get_type();
if(t->is_ref()) t=t->get_type_refd();
while(!t->rawattrib && t->is_ref()) t=t->get_type_refd();
field_rawattr= new RawAST(t->rawattrib,basic_type==T_INT);
if(!t->rawattrib && basic_type==T_REAL) field_rawattr->fieldlength=64;
cfield->get_type()->rawattrib=field_rawattr;
cfield->get_type()->rawattrib= new RawAST(t->rawattrib,cfield->get_type()->get_default_raw_fieldlength());
}
if(field_rawattr->fieldorder==XDEFDEFAULT)
field_rawattr->fieldorder=rawattrib->fieldorder;
......@@ -2604,7 +2611,7 @@ namespace Common {
case T_ENUM_T:
case T_SEQ_T:
case T_SET_T:
rawattrib = new RawAST(false);
rawattrib = new RawAST(get_default_raw_fieldlength());
break;
default:
if (is_ref()) get_type_refd()->force_raw();
......
......@@ -838,6 +838,7 @@ namespace Common {
void chk_raw();
/** If the type does not have a rawattrib, create one. */
void force_raw();
int get_default_raw_fieldlength();
void chk_text();
void chk_text_matching_values(textAST_matching_values *matching_values,
const char *attrib_name);
......
......@@ -116,7 +116,7 @@ void Type::chk()
// If this sequence type has no attributes but one of its fields does,
// create an empty attribute structure.
if(!rawattrib && hasVariantAttrs() && hasNeedofRawAttrs())
rawattrib = new RawAST;
rawattrib = new RawAST(get_default_raw_fieldlength());
if(!textattrib && hasVariantAttrs() && hasNeedofTextAttrs())
textattrib = new TextAST;
if(!xerattrib && hasVariantAttrs() && hasNeedofXerAttrs())
......@@ -304,13 +304,10 @@ void Type::parse_attributes()
}
}
if(!rawattrib && !override_ref){
Type *t=get_type_refd_last(&refch);
typetype_t basic_type=t->typetype;
t=this; // go back to the beginning
Type *t=this;
refch.reset();
while(!t->rawattrib && t->is_ref()) t=t->get_type_refd(&refch);
rawattrib=new RawAST(t->rawattrib,basic_type==T_INT);
if(!t->rawattrib && basic_type==T_REAL) rawattrib->fieldlength=64;
rawattrib=new RawAST(t->rawattrib,t->get_default_raw_fieldlength());
new_raw=true;
}
if(!textattrib && !override_ref){
......@@ -350,8 +347,7 @@ void Type::parse_attributes()
case T_VERDICT: // TTCN-3 verdict, for XER
if(rawattrib==NULL){
rawattrib= new RawAST(typetype==T_INT);
if(typetype==T_REAL) rawattrib->fieldlength=64;
rawattrib= new RawAST(get_default_raw_fieldlength());
new_raw=true;
}
if(textattrib==NULL){textattrib= new TextAST; new_text=true;}
......@@ -407,7 +403,7 @@ void Type::parse_attributes()
case T_SET_T:
case T_ANYTYPE:
case T_ARRAY:
if(rawattrib==NULL) {rawattrib= new RawAST; new_raw=true;}
if(rawattrib==NULL) {rawattrib= new RawAST(get_default_raw_fieldlength()); new_raw=true;}
if(textattrib==NULL){textattrib= new TextAST; new_text=true;}
if(xerattrib==NULL) {xerattrib = new XerAttributes; new_xer = true;}
if(berattrib==NULL) {berattrib = new BerAST; new_ber = true;}
......
......@@ -690,7 +690,7 @@ void Type::generate_code_rawdescriptor(output_struct *target)
gennameown_str);
bool dummy_raw = rawattrib == NULL;
if (dummy_raw) {
rawattrib = new RawAST(get_type_refd_last()->typetype == T_INT);
rawattrib = new RawAST(get_type_refd_last()->get_default_raw_fieldlength());
}
if (rawattrib->intx) {
str = mputstr(str, "RAW_INTX,");
......@@ -1317,7 +1317,7 @@ void Type::generate_code_Choice(output_struct *target)
if(sdef.hasRaw) {
bool dummy_raw = rawattrib == NULL;
if (dummy_raw) {
rawattrib = new RawAST;
rawattrib = new RawAST(get_default_raw_fieldlength());
}
copy_rawAST_to_struct(rawattrib,&(sdef.raw));
// building taglist
......@@ -1731,7 +1731,7 @@ void Type::generate_code_Se(output_struct *target)
if(sdef.hasRaw) {
bool dummy_raw = rawattrib == NULL;
if (dummy_raw) {
rawattrib = new RawAST;
rawattrib = new RawAST(get_default_raw_fieldlength());
}
copy_rawAST_to_struct(rawattrib,&(sdef.raw));
// building taglist
......@@ -2135,7 +2135,7 @@ void Type::generate_code_SeOf(output_struct *target)
if(sofdef.hasRaw) {
bool dummy_raw = rawattrib == NULL;
if (dummy_raw) {
rawattrib = new RawAST;
rawattrib = new RawAST(get_default_raw_fieldlength());
}
copy_rawAST_to_struct(rawattrib,&(sofdef.raw));
if (dummy_raw) {
......
......@@ -19,14 +19,14 @@
#include "../main.hh"
RawAST::RawAST(){
init_rawast(false);
init_rawast(0);
}
RawAST::RawAST(bool int_type){
init_rawast(int_type);
RawAST::RawAST(int default_length){
init_rawast(default_length);
}
RawAST::RawAST(RawAST *other,bool int_type){
RawAST::RawAST(RawAST *other, int default_length){
if(other){
fieldlength=other->fieldlength;
comp=other->comp;
......@@ -67,11 +67,11 @@ RawAST::RawAST(RawAST *other,bool int_type){
intx = other->intx;
stringformat = other->stringformat;
}
else init_rawast(int_type);
else init_rawast(default_length);
}
void RawAST::init_rawast(bool int_type){
fieldlength=int_type?8:0;
void RawAST::init_rawast(int default_length){
fieldlength=default_length;
comp=XDEFDEFAULT;
byteorder=XDEFDEFAULT;
align=XDEFDEFAULT;
......
......@@ -68,11 +68,12 @@ typedef struct{
/** Parsed RAW encoder attributes */
class RawAST{
private:
void init_rawast(bool int_type);
void init_rawast(int default_length);
/** No copying */
RawAST(const RawAST&);
/** No assignment */
RawAST& operator=(const RawAST&);
RawAST();
public:
int fieldlength; /**< Nr of bits per character, hexstring : 4,
octetstring and charstring : 8, etc */
......@@ -121,12 +122,12 @@ public:
/** Default constructor.
* Calls \c init_rawast(false).
* \todo should be merged with the next one */
RawAST();
// RawAST();
/** Constructor.
* Calls \c init_rawast(int_type). */
RawAST(bool int_type);
RawAST(int default_length);
/** Sort-of copy constructor. */
RawAST(RawAST *other, bool int_type);
RawAST(RawAST *other, int default_length );
~RawAST();
void print_RawAST();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment