Commit 4493aade authored by rdubner's avatar rdubner

Renamed and simplified.

parent 975e781e
......@@ -48,7 +48,7 @@
using namespace std;
//#define DUMPING
#define DUMPING
void
scan_test(const string &filename)
......@@ -335,7 +335,7 @@ main(int argc, char *argv[])
//program_labels.Dump();
//cob_pic_symbols.Dump();
cob_data.Dump();
//cob_field_attributes.Dump();
cob_field_attributes.Dump();
cob_fields.Dump();
#endif
// We now have a nice complete list of COB_DATA, COB_FIELD_ATTRIBUTES, COB_FIELDS
......
......@@ -281,13 +281,13 @@ ProcessDataStorage(ifstream &ifs,
nfound += strlen(SZ_COB_FIELD_F);
// Pick up the c_symbol
string c_symbol="f_";
string f_name = "f_" ;
while( nfound < input.length() ) {
char ch = input[nfound++];
if( !isdigit(ch) ) {
break;
}
c_symbol += ch;
f_name += ch;
}
// Skip past the '{'
......@@ -385,10 +385,10 @@ ProcessDataStorage(ifstream &ifs,
mapped_program_id = it->second;
}
cob_fields.Insert(c_symbol,
size,
cob_fields.Insert(f_name,
name_of_data,
offset,
size,
name_of_attr,
mapped_program_id,
cbl_name);
......@@ -674,7 +674,7 @@ ScanForLinkage(ifstream &ifs,
nfound = param2.find(" + ",nfound+3);
}
}
cob_fields.Modify(f_symbol,base,offset);
cob_fields.Modify(f_symbol,"NULL",offset);
}
// Go see if there are more on this line
......@@ -699,64 +699,25 @@ DATA_DESCRIPTIONS::Flatten(const COB_FIELDS &cob_fields,
) {
COB_FIELD field = *it;
DATA_DESCRIPTION ds;
ds.field_data_name = field.name ;
ds.field_size = field.size ;
ds.c_symbol = field.name_of_data;
ds.field_data_offset = field.offset ;
ds.field_attr_name = field.name_of_attr;
ds.f_name = field.f_name ;
ds.size = field.size ;
ds.b_name = field.b_name;
ds.offset = field.offset ;
ds.program_id = field.program_id ;
ds.cbl_symbol = field.cbl_name ;
const COB_FIELD_ATTRIBUTE *cfa = cob_field_attributes.GetFieldAttribute(field.name_of_attr);
if( cfa ) {
ds.attr_type = cfa->type;
ds.attr_digits = cfa->digits;
ds.attr_scale = cfa->scale;
ds.attr_flags = cfa->flags;
ds.attr_pic_name = cfa->name_of_pic;
const COB_PIC_SYMBOL *pic_pointer = cob_pic_symbols.GetPicSymbol(ds.attr_pic_name);
if( pic_pointer ) {
ds.picture_string = pic_pointer->pic_symbol;
}
}
ds.cobol_symbol = field.cbl_name ;
const COB_DATUM *cd = cob_data.GetCobDatum(ds.c_symbol);
const COB_DATUM *cd = cob_data.GetCobDatum(ds.b_name);
if( cd ) {
ds.storage_size = cd->size;
ds.size = cd->size;
ds.storage_type = cd->storage_type;
}
if( ds.storage_type.empty() AND ds.c_symbol.empty() ) {
if( ds.storage_type.empty() AND ds.b_name.empty() ) {
ds.storage_type = "Local";
}
DsInsert(ds);
}
// Now walk through the b_ data fields. In general, these will already
// be in the symbols array. But in cases where a working-storage variable
// is declared, but never used, there won't be an f_ entry. This means that
// the debugger won't be able to show you properly formatted data, but it
// will, at least, know where it is and show you the byte values.
for(V_COB_DATUM::const_iterator it=cob_data.v_data.begin();
it != cob_data.v_data.end();
it++
) {
COB_DATUM cob_data = *it;
if( !IsInDs(cob_data.program_id,cob_data.name) ) {
// It's not already there. So, put it there.
DATA_DESCRIPTION ds;
ds.program_id = cob_data.program_id;
ds.cbl_symbol = cob_data.cbl_name;
ds.c_symbol = cob_data.name;
ds.storage_size = cob_data.size;
ds.storage_type = cob_data.storage_type;
DsInsert(ds);
}
}
}
void
......@@ -813,19 +774,14 @@ void
DATA_DESCRIPTIONS::Dump() const
{
cout << "DATA_DESCRIPTION:" << endl ;
cout << setw(20) << "program_id" ;
cout << setw(20) << "cbl_symbol" ;
cout << setw( 9) << "c_symbol" ;
cout << setw( 9) << "f_symbol" ;
cout << setw( 7) << "offset" ;
cout << setw(13) << "storage_type" ;
cout << setw(20) << "program_id" ;
cout << setw(20) << "cobol_symbol" ;
cout << setw(13) << "storage_type" ;
cout << setw( 9) << "b_name" ;
cout << setw( 7) << "offset" ;
cout << setw( 6) << "size" ;
cout << setw( 9) << "f_symbol" ;
cout << setw(16) << "picture" ;
cout << setw( 6) << "ssize" ;
cout << setw( 6) << "fsize" ;
cout << setw(10) << "attr_type" ;
cout << setw(12) << "attr_digits" ;
cout << setw(11) << "attr_scale" ;
cout << setw(11) << "attr_flags" ;
cout << endl;
for(VDATA_DESCRIPTION::const_iterator it=symbols.begin();
......@@ -833,18 +789,13 @@ DATA_DESCRIPTIONS::Dump() const
it++ ) {
DATA_DESCRIPTION symbol = *it;
cout << setw(20) << symbol.program_id ;
cout << setw(20) << symbol.cbl_symbol ;
cout << setw( 9) << symbol.c_symbol ;
cout << setw( 9) << symbol.field_data_name ;
cout << setw( 7) << symbol.field_data_offset ;
cout << setw(20) << symbol.cobol_symbol ;
cout << setw(13) << symbol.storage_type ;
cout << setw( 9) << symbol.b_name ;
cout << setw( 7) << symbol.offset ;
cout << setw( 6) << symbol.size ;
cout << setw( 9) << symbol.f_name ;
cout << setw(16) << symbol.picture_string ;
cout << setw( 6) << symbol.storage_size ;
cout << setw( 6) << symbol.field_size ;
cout << setw(10) << symbol.attr_type ;
cout << setw(12) << symbol.attr_digits ;
cout << setw(11) << symbol.attr_scale ;
cout << setw(11) << symbol.attr_flags ;
cout << endl;
}
cout << endl;
......
......@@ -263,12 +263,12 @@ class COB_FIELD_ATTRIBUTES;
class COB_FIELD_ATTRIBUTE
{
public:
std::string name; /* name of attribute */
std::string a_name; /* name of attribute */
unsigned short type; /* Field type */
unsigned short digits; /* Digit count */
signed short scale; /* Field scale */
unsigned short flags; /* Field flags */
std::string name_of_pic;/* picture string */
std::string p_name; /* picture string */
std::string program_id; /* picture string */
public:
......@@ -280,12 +280,12 @@ public:
std::string name_of_pic_,
std::string program_id_)
{
name = name_ ;
a_name = name_ ;
type = type_ ;
digits = digits_ ;
scale = scale_ ;
flags = flags_ ;
name_of_pic = name_of_pic_ ;
p_name = name_of_pic_ ;
program_id = program_id_ ;
}
friend COB_FIELD_ATTRIBUTES;
......@@ -304,28 +304,28 @@ public:
{
}
void
Insert(std::string name, /* name of attribute */
Insert(std::string a_name, /* name of attribute */
unsigned short type, /* Field type */
unsigned short digits, /* Digit count */
signed short scale, /* Field scale */
unsigned short flags, /* Field flags */
std::string name_of_pic,/* picture string */
std::string p_name, /* picture string */
std::string program_id) /* picture string */
{
M_COB_FIELD_ATTRIBUTES::const_iterator it = m_cob_field_attributes.find(name);
M_COB_FIELD_ATTRIBUTES::const_iterator it = m_cob_field_attributes.find(a_name);
if( it != m_cob_field_attributes.end() ) {
std::cout << "Creating the symbol " << name << " more than once in COB_FIELD_ATTRIBUTES::Insert()\n" ;
std::cout << "Creating the symbol " << a_name << " more than once in COB_FIELD_ATTRIBUTES::Insert()\n" ;
exit(1);
}
COB_FIELD_ATTRIBUTE cfa(name,
COB_FIELD_ATTRIBUTE cfa(a_name,
type,
digits,
scale,
flags,
name_of_pic,
p_name,
program_id);
m_cob_field_attributes[name] = v_cob_field_attributes.size();
m_cob_field_attributes[a_name] = v_cob_field_attributes.size();
v_cob_field_attributes.push_back(cfa);
}
......@@ -333,24 +333,24 @@ public:
Dump() const
{
std::cout << "COB_FIELD_ATTRIBUTES:" << std::endl;
std::cout << std::setw(20) << "name" ;
std::cout << std::setw(20) << "a_name" ;
std::cout << std::setw(20) << "type";
std::cout << std::setw(20) << "digits";
std::cout << std::setw(20) << "scale" ;
std::cout << std::setw(20) << "flags";
std::cout << std::setw(20) << "name_of_pic";
std::cout << std::setw(20) << "p_name";
std::cout << std::setw(20) << "program_id";
std::cout << std::endl;
for(V_COB_FIELD_ATTRIBUTE::const_iterator it=v_cob_field_attributes.begin();
it!=v_cob_field_attributes.end();
it++) {
COB_FIELD_ATTRIBUTE attr = *it;
std::cout << std::setw(20) << attr.name ;
std::cout << std::setw(20) << attr.a_name ;
std::cout << std::setw(20) << attr.type;
std::cout << std::setw(20) << attr.digits;
std::cout << std::setw(20) << attr.scale ;
std::cout << std::setw(20) << attr.flags;
std::cout << std::setw(20) << attr.name_of_pic;
std::cout << std::setw(20) << attr.p_name;
std::cout << std::setw(20) << attr.program_id;
std::cout << std::endl;
}
......@@ -374,28 +374,28 @@ class COB_FIELDS;
class COB_FIELD
{
public:
std::string name; /* name of field */
int size; /* Field size */
std::string name_of_data; /* name of data field */
int offset; /* any internal + offset */
std::string name_of_attr; /* name of attribute */
std::string program_id; /* Where defined */
std::string cbl_name; /* From the comment in the .h code */
std::string f_name; /* name of field */
std::string b_name; /* name of data field */
int offset; /* any internal + offset */
int size; /* Field size */
std::string a_name; /* name of attribute */
std::string program_id; /* Where defined */
std::string cbl_name; /* From the comment in the .h code */
public:
COB_FIELD(std::string name_,
int size_,
std::string data_,
COB_FIELD(std::string f_name_,
std::string b_name_,
int offset_,
std::string attr_,
int size_,
std::string a_name_,
std::string program_id_,
std::string cbl_name_)
{
name = name_ ;
size = size_ ;
name_of_data = data_ ;
f_name = f_name_ ;
b_name = b_name_ ;
offset = offset_ ;
name_of_attr = attr_ ;
size = size_ ;
a_name = a_name_ ;
program_id = program_id_;
cbl_name = cbl_name_ ;
}
......@@ -415,42 +415,42 @@ public:
public:
void
Insert(std::string name,
int size,
std::string name_of_data,
Insert(std::string f_name,
std::string b_name,
int offset,
std::string name_of_attr,
int size,
std::string a_name,
std::string program_id,
std::string cbl_name)
{
M_COB_FIELDS::const_iterator it = m_cob_fields.find(name);
M_COB_FIELDS::const_iterator it = m_cob_fields.find(f_name);
if( it != m_cob_fields.end() ) {
std::cout << "Creating the symbol " << name << " more than once in COB_FIELDS::Insert()\n" ;
std::cout << "Creating the symbol " << f_name << " more than once in COB_FIELDS::Insert()\n" ;
exit(1);
}
COB_FIELD cf(name,
size,
name_of_data,
COB_FIELD cf(f_name,
b_name,
offset,
name_of_attr,
size,
a_name,
program_id,
cbl_name);
m_cob_fields[name] = v_cob_fields.size();
m_cob_fields[f_name] = v_cob_fields.size();
v_cob_fields.push_back(cf);
}
void
Modify(std::string name_,
std::string name_of_data_,
Modify(std::string f_name_,
std::string b_name_,
int offset_)
{
M_COB_FIELDS::iterator it = m_cob_fields.find(name_);
M_COB_FIELDS::iterator it = m_cob_fields.find(f_name_);
if( it EQ m_cob_fields.end() ) {
std::cout << "Couldn't modify symbol " << name_ << " COB_FIELDS::Modify()\n" ;
std::cout << "Couldn't find symbol " << f_name_ << " COB_FIELDS::Modify()\n" ;
exit(1);
}
size_t i = it->second;
v_cob_fields[i].name_of_data = name_of_data_;
v_cob_fields[i].b_name = b_name_;
v_cob_fields[i].offset = offset_;
}
......@@ -458,11 +458,11 @@ public:
Dump() const
{
std::cout << "COB_FIELDS:" << std::endl;
std::cout << std::setw(20) << "name" ;
std::cout << std::setw(20) << "size";
std::cout << std::setw(20) << "name_of_data";
std::cout << std::setw(20) << "f_name" ;
std::cout << std::setw(20) << "b_name";
std::cout << std::setw(20) << "offset" ;
std::cout << std::setw(20) << "name_of_attr";
std::cout << std::setw(20) << "size";
std::cout << std::setw(20) << "a_name";
std::cout << std::setw(20) << "program_id";
std::cout << std::setw(20) << "cbl_name";
std::cout << std::endl;
......@@ -471,11 +471,11 @@ public:
it!=v_cob_fields.end();
it++) {
COB_FIELD field = *it;
std::cout << std::setw(20) << field.name ;
std::cout << std::setw(20) << field.size;
std::cout << std::setw(20) << field.name_of_data;
std::cout << std::setw(20) << field.f_name ;
std::cout << std::setw(20) << field.b_name;
std::cout << std::setw(20) << field.offset ;
std::cout << std::setw(20) << field.name_of_attr;
std::cout << std::setw(20) << field.size;
std::cout << std::setw(20) << field.a_name;
std::cout << std::setw(20) << field.program_id;
std::cout << std::setw(20) << field.cbl_name;
std::cout << std::endl;
......@@ -591,37 +591,19 @@ class DATA_DESCRIPTION
{
public:
std::string program_id;
std::string cobol_symbol;
std::string storage_type;
std::string cbl_symbol;
std::string c_symbol;
std::string b_name;
int offset;
int size;
std::string f_name;
std::string picture_string;
// storage comes with a size parameter: b_17[21];
// It's often not right. Too big?
int storage_size;
// See cobc/cobc/libcob/common.h declaration for cob_field_attr
USHORT attr_type;
USHORT attr_digits;
short attr_scale;
USHORT attr_flags;
std::string attr_pic_name;
int field_size;
std::string field_data_name;
int field_data_offset;
std::string field_attr_name;
public:
DATA_DESCRIPTION()
{
storage_size = 0;
attr_type = 0;
attr_digits = 0;
attr_scale = 0;
attr_flags = 0;
field_size = 0;
field_data_offset = 0;
offset = 0;
size = 0;
}
friend DATA_DESCRIPTIONS;
};
......@@ -635,8 +617,6 @@ private:
VDATA_DESCRIPTION symbols;
// We are going to key that table by (program-id, cbl_symbol,offset)
M_VKEY symbols_key;
// We are also going to create an non-unique "index" (program-id, cbl_symbol,-1)
M_VKEY symbols_index;
std::map<std::string,size_t>location_of_c_symbol;
......@@ -675,18 +655,18 @@ public:
void
DsInsert(const DATA_DESCRIPTION &ds )
{
symbols_key[MakeVKey(ds.program_id,ds.c_symbol,ds.field_data_offset)] = symbols.size();
symbols_index[MakeVKey(ds.program_id,ds.c_symbol,-1)] = symbols.size();
symbols_key[MakeVKey(ds.program_id,ds.cobol_symbol,ds.offset)] = symbols.size();
symbols.push_back(ds);
}
bool
IsInDs(std::string const &program_id, std::string const &c_symbol,int offset) const
IsInDs(std::string const &program_id, std::string const &cobol_symbol,int offset) const
{
std::string dskey=MakeVKey(program_id,c_symbol,offset);
std::string dskey=MakeVKey(program_id,cobol_symbol,offset);
M_VKEY::const_iterator it = symbols_key.find(dskey);
return it != symbols_key.end();
}
size_t
GetIndex(std::string const &program_id, std::string const &c_symbol,int offset) const
{
......@@ -699,25 +679,6 @@ public:
return retval;
}
bool
IsInDs(std::string const &program_id, std::string const &c_symbol) const
{
std::string dskey=MakeVKey(program_id,c_symbol,-1);
M_VKEY::const_iterator it = symbols_index.find(dskey);
return it != symbols_index.end();
}
size_t
GetIndex(std::string const &program_id, std::string const &c_symbol) const
{
size_t retval = (size_t)(-1);
std::string dskey=MakeVKey(program_id,c_symbol,-1);
M_VKEY::const_iterator it = symbols_index.find(dskey);
if(it != symbols_index.end()) {
retval = it->second;
}
return retval;
}
void Dump() const;
void Flatten(const COB_FIELDS &cob_fields,
......
......@@ -1120,9 +1120,10 @@ VARIABLE_TREE::Consolidive(VAR_NODE *node,const DATA_DESCRIPTIONS &data_descript
int offset = node->GetOffset();
size_t index = NO_INDEX;
if( node->level <= 1 OR node->level EQ 77 ) {
if(node->section != "LOCAL-STORAGE" AND node->level <= 1 OR node->level EQ 77 ) {
// We're starting work on a brand-new level-one(ish) variable.
// Let's check to see if there is a b_ buffer for this 01/77 symbol
base_symbol = "";
const COB_DATUM *pdatum = cob_data.GetCobDatumFromProgAndName(program_id,cbl_symbol);
if( pdatum ) {
// Pick up the base symbol
......@@ -1130,55 +1131,17 @@ VARIABLE_TREE::Consolidive(VAR_NODE *node,const DATA_DESCRIPTIONS &data_descript
}
}
if( base_symbol.empty() ) {
}
if( !base_symbol.empty() ) {
// See if we have a data_descriptions entry for that cbl_symbol
if( data_description.IsInDs(program_id,base_symbol,offset) ) {
// We do! Save the index
index = data_description.GetIndex(program_id,base_symbol,offset);
node->data_description_index = index;
DATA_DESCRIPTION symbol = data_description[index];
// Here is where we combine the VARIABLE_TREE data with the DATA_DESCRIPTIONS
// data to create everything we need:
node->base_symbol = base_symbol;
if( symbol.storage_size EQ 0 ) {
node->best_size = symbol.field_size;
} else if( symbol.field_size EQ 0 ) {
node->best_size = symbol.storage_size;
} else {
node->best_size = symbol.field_size;
}
if( node->picture.empty() ) {
node->best_picture = symbol.picture_string;
} else if ( symbol.picture_string.empty() ) {
node->best_picture = node->picture;
} else {
// If they're both on, go with the one from the listing file
node->best_picture = node->picture;
}
if( node->level EQ 66 ) {
// The .cbl.lst file doesn't have good offset information
// for 66 REDEFINES. But the symbol *might* have good information,
// which it gets from the f_ field_attribute record when the 66
// variable is referenced in the code.
node->offset = symbol.field_data_offset ;
}
node->base_symbol = symbol.c_symbol ;
node->attr_type = symbol.attr_type ;
node->attr_digits = symbol.attr_digits ;
node->attr_scale = symbol.attr_scale ;
node->attr_flags = symbol.attr_flags ;
} else {
node->best_size = node->size;
node->best_picture = node->picture;
}
}
}
......
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