Commit 8edf37f7 authored by rdubner's avatar rdubner

Partway through downporting the cobcd-st source code to GCC-4.8.5

parent 2c70e77d
......@@ -85,7 +85,7 @@ ProcessDataStorage(ifstream &ifs,
string storage = "Working"; // This is the default
string program_id;
unordered_map<std::string,std::string>b_symbol_to_program_id;
map<std::string,std::string>b_symbol_to_program_id;
// Variables for building a picture string
bool inpic = false;
......@@ -237,7 +237,7 @@ ProcessDataStorage(ifstream &ifs,
// to get around that, which we have to do to get these
// variables lined up with the .cbl.lst variable list.
unordered_map<string,string>::const_iterator it =
map<string,string>::const_iterator it =
b_symbol_to_program_id.find(name_of_data);
if(it != b_symbol_to_program_id.end()) {
mapped_program_id = it->second;
......
......@@ -30,12 +30,13 @@
#pragma once
#include <stdlib.h>
#include <string>
#include <vector>
#include <unordered_map>
#include <unordered_set>
#include <map>
#include <set>
#include <fstream>
#include <regex>
#include <regex.h>
#include <sstream>
#include <iomanip>
#include "profiler.h"
......@@ -49,6 +50,10 @@
#define NEEDED_TO_DEFINE_EQ
#endif
#if __GNUC__ < 7
#define nullptr NULL
#endif
//////////////////////////////////////////////////////////////////////////
// These data structures are based on from GnuCOBOL3.1-dev/libcob/common.h
......@@ -77,7 +82,7 @@ public:
friend COB_PIC_SYMBOLS;
};
typedef std::vector<COB_PIC_SYMBOL> V_COB_PIC_SYMBOLS;
typedef std::unordered_map<std::string,size_t> M_COB_PIC_SYMBOLS;
typedef std::map<std::string,size_t> M_COB_PIC_SYMBOLS;
class COB_PIC_SYMBOLS
{
......@@ -110,7 +115,12 @@ public:
std::cout << " ";
std::cout << std::setw(20) << "pic_symbol";
std::cout << std::endl;
for( auto symbol : v_pic_symbols) {
for( V_COB_PIC_SYMBOLS::const_iterator it = v_pic_symbols.begin();
it != v_pic_symbols.end();
it++)
{
const COB_PIC_SYMBOL symbol = *it;
std::cout << std::setw(20) << symbol.name ;
std::cout << " ";
std::cout << std::setw(20) << symbol.pic_symbol;
......@@ -156,7 +166,7 @@ public:
friend COB_DATA;
} ;
typedef std::vector<COB_DATUM> V_COB_DATUM;
typedef std::unordered_map<std::string,size_t> M_COB_DATUM;
typedef std::map<std::string,size_t> M_COB_DATUM;
class COB_DATA
{
......@@ -196,7 +206,12 @@ public:
std::cout << std::setw(20) << "storage";
std::cout << std::setw(20) << "cbl_name";
std::cout << std::endl;
for( auto symbol : v_data) {
for( V_COB_DATUM::const_iterator it=v_data.begin();
it!= v_data.end();
it++) {
COB_DATUM symbol = *it;
std::cout << std::setw(20) << symbol.name ;
std::cout << std::setw(20) << symbol.size;
std::cout << std::setw(20) << symbol.program_id;
......@@ -253,7 +268,7 @@ public:
friend COB_FIELD_ATTRIBUTES;
} ;
typedef std::vector<COB_FIELD_ATTRIBUTE> V_COB_FIELD_ATTRIBUTE;
typedef std::unordered_map<std::string,size_t> M_COB_FIELD_ATTRIBUTES;
typedef std::map<std::string,size_t> M_COB_FIELD_ATTRIBUTES;
class COB_FIELD_ATTRIBUTES
{
......@@ -303,7 +318,10 @@ public:
std::cout << std::setw(20) << "name_of_pic";
std::cout << std::setw(20) << "program_id";
std::cout << std::endl;
for( auto attr : v_cob_field_attributes) {
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.type;
std::cout << std::setw(20) << attr.digits;
......@@ -362,7 +380,7 @@ public:
friend COB_FIELDS;
} ;
typedef std::vector<COB_FIELD> V_COB_FIELDS;
typedef std::unordered_map<std::string,size_t> M_COB_FIELDS;
typedef std::map<std::string,size_t> M_COB_FIELDS;
class COB_FIELDS
{
......@@ -425,7 +443,11 @@ public:
std::cout << std::setw(20) << "program_id";
std::cout << std::setw(20) << "cbl_name";
std::cout << std::endl;
for( auto field : v_cob_fields) {
for( V_COB_FIELDS::const_iterator it = v_cob_fields.begin();
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;
......@@ -524,7 +546,10 @@ public:
std::cout << std::setw(30) << "paragraph";
std::cout << std::endl;
for( auto label : program_labels ) {
for( VCOB_PROGRAM_LABEL::const_iterator it=program_labels.begin();
it!=program_labels.end();
it++) {
COB_PROGRAM_LABEL label = *it;
std::cout << std::setw( 5) << label.type;
std::cout << std::setw(15) << label.source_file;
std::cout << std::setw( 6) << label.line_number;
......@@ -581,7 +606,7 @@ public:
};
typedef std::vector<DATA_DESCRIPTION> VDATA_DESCRIPTION;
typedef std::unordered_map<std::string,size_t> M_VKEY;
typedef std::map<std::string,size_t> M_VKEY;
class DATA_DESCRIPTIONS
{
......@@ -592,7 +617,7 @@ private:
// We are also going to create an non-unique "index" (program-id, cbl_symbol,-1)
M_VKEY symbols_index;
std::unordered_map<std::string,size_t>location_of_c_symbol;
std::map<std::string,size_t>location_of_c_symbol;
public:
int
......@@ -610,7 +635,7 @@ public:
int
IndexOfSymbol(const std::string &symbol) const
{
std::unordered_map<std::string,size_t>::const_iterator it =
std::map<std::string,size_t>::const_iterator it =
location_of_c_symbol.find(symbol);
if(it == location_of_c_symbol.end()) {
return -1;
......
......@@ -29,7 +29,7 @@
############################################################################ */
#include <iostream>
#include <regex>
#include <regex.h>
#ifdef _WIN32
#include "getopt.h"
......
......@@ -30,6 +30,8 @@
#include "profiler.h"
#if __GNUC__ >= 7
// These are static variables for the PPROFILER class
std::unordered_map<std::string,double> PPROFILER::ProfilerRoutineTimes;
std::unordered_map<std::string,LONGLONG> PPROFILER::ProfilerRoutineEntries;
......@@ -40,3 +42,5 @@ operator<<(std::ostream &os, PPROFILER const &m)
{
return os << m.Dump();
}
#endif
......@@ -30,6 +30,9 @@
#pragma once
#if __GNUC__ >= 7
#include <map>
#include <unordered_map>
#include <string>
......@@ -168,6 +171,8 @@ public:
};
#endif
#ifdef PROFILING
#define PROFILER PPROFILER Profiler(__func__);
#define CPROFILER PPROFILER Profiler(typeid(*this).name(),__func__);
......
......@@ -28,6 +28,7 @@
#
############################################################################ */
#include <sstream>
#include "utils.h"
#include "profiler.h"
......@@ -134,7 +135,8 @@ string
Upper(const string &s)
{
string retval;
for(char ch : s) {
for(size_t i=0; i<s.size(); i++) {
char ch = s[i];
retval += toupper(ch);
}
return retval;
......@@ -142,7 +144,8 @@ Upper(const string &s)
string
ZeroIsNull(const LONGLONG &v)
{
{
string retval;
stringstream ss;
if( v != 0 ) {
ss << v;
......
......@@ -30,12 +30,16 @@
#pragma once
#if __GNUC__ >= 7
#include <cstdint>
#endif
#include <string>
#include <vector>
typedef char *PCHAR;
#if __GNUC__ >= 7
typedef int8_t BYTE;
typedef uint8_t UBYTE;
......@@ -47,6 +51,22 @@ typedef uint32_t ULONG;
typedef int64_t LONGLONG;
typedef uint64_t ULONGLONG;
#else
typedef signed char BYTE;
typedef unsigned char UBYTE;
typedef signed short SHORT;
typedef unsigned short USHORT;
typedef signed int LONG;
typedef unsigned int ULONG;
typedef signed long long LONGLONG;
typedef unsigned long long ULONGLONG;
#endif
typedef std::vector<std::string>VSTRING;
......
......@@ -39,6 +39,21 @@ using namespace std;
#define AND &&
#define OR ||
#if __GNUC__ <= 4
int stoi(const string &s)
{
return atoi(s.c_str());
}
#endif
VAR_NODE::VAR_NODE()
{
CPROFILER;
......@@ -332,7 +347,8 @@ VARIABLE_TREE::ReadFromFile(std::ifstream &ifs)
for(ntoken=0; ntoken<tokens.size(); ntoken++) {
string token = tokens[ntoken];
string lc;
for(char s : token) {
for(size_t i=0; i<token.size(); i++) {
char s = token[i];
lc += tolower(s);
}
if(lc EQ "program-id" OR lc EQ "program-id.") {
......@@ -412,13 +428,17 @@ VARIABLE_TREE::ReadFromFile(std::ifstream &ifs)
// In PICTURE strings, so we need to keep them there. But if a ','
// appears at the end of the token before a REDEFINES token, we have to
// remove it.
vector<string>::const_iterator it = tokens.begin();
while(it != tokens.end()){
if( *it EQ "REDEFINES" ) {
break;
}
}
vector<string>::const_iterator it = find(tokens.begin(),
tokens.end(),
"REDEFINES");
if( it != tokens.end() ) {
// 'it' points to REDEFINES:
auto index = it - tokens.begin();
size_t index = it - tokens.begin();
// Get rid of the comma at the end of index-1:
size_t n = tokens[index-1].find_last_of(',');
......@@ -437,7 +457,13 @@ VARIABLE_TREE::ReadFromFile(std::ifstream &ifs)
// And now we can proceed
}
it = find(tokens.begin(),tokens.end(),"OCCURS");
it = tokens.begin();
while(it != tokens.end()){
if( *it EQ "OCCURS" ) {
break;
}
}
if( it != tokens.end() ) {
// 'it' points to OCCURS:
size_t index = it - tokens.begin();
......@@ -1040,7 +1066,10 @@ DiveForVariable( VAR_NODE *node,
return node;
}
VVAR_NODES children = node->GetChildren();
for(VAR_NODE *child : children) {
for(VVAR_NODES::const_iterator it=children.begin();
it!=children.end();
it++) {
VAR_NODE *child = *it;
VAR_NODE *maybe = DiveForVariable(child,
section,
program_id,
......@@ -1187,7 +1216,10 @@ VARIABLE_TREE::Consolidive(VAR_NODE *node,const DATA_DESCRIPTIONS &data_descript
// And our work here is done:
}
for( auto child : node->children ) {
for(VVAR_NODES::const_iterator it=node->children.begin();
it!=node->children.end();
it++) {
VAR_NODE *child = *it;
// Check our children
Consolidive(child,data_description,base_symbol);
......@@ -1251,7 +1283,11 @@ VARIABLE_TREE::DumpFlatList() const
cout << setw( 7) << "ascale";
cout << setw( 7) << "aflags";
cout << endl;
for( auto node : flat_list ) {
for(VVAR_NODES::const_iterator it=flat_list.begin();
it!=flat_list.end();
it++) {
VAR_NODE *node = *it;
cout << setw(20) << node->program;
cout << setw(20) << node->section;
cout << setw( 5) << node->size;
......@@ -1279,7 +1315,10 @@ VARIABLE_TREE::DumpFlatList() const
void
VARIABLE_TREE::FormatVariablesInfo(stringstream &ss) const
{
for( auto node : flat_list ) {
for(VVAR_NODES::const_iterator it=flat_list.begin();
it!=flat_list.end();
it++) {
VAR_NODE *node = *it;
ss << "D|";
ss << node->section.substr(0,2) << "|";
ss << ZeroIsNull(node->level) << "|" ;
......
......@@ -60,6 +60,7 @@ PROGRAM JIMBOB
WORKING-STORAGE SECTION
00022 GROUP 01 WS-JIM
00022 GROUP 01 WS-JIM
00010 ALPHABETIC 02 WS-FIRSTNAME A(10)
00001 ALPHABETIC 02 WS-MIDDLE-INITIAL A(1)
......@@ -75,14 +76,14 @@ WORKING-STORAGE SECTION
*/
constexpr int LEVEL_ROOT = -3;
constexpr int LEVEL_PROGRAM = -2;
constexpr int LEVEL_SECTION = -1;
constexpr int LEVEL_FILE = 0; // Special handling for the FILE type
constexpr int LEVEL_01 = 01; // Just to avoid magic numbers;
constexpr int LEVEL_66 = 66; // ibid.;
constexpr int LEVEL_77 = 77; // ibid.;
constexpr char SECTION_INPUT_OUTPUT[]= "INPUT-OUTPUT";
static const int LEVEL_ROOT = -3;
static const int LEVEL_PROGRAM = -2;
static const int LEVEL_SECTION = -1;
static const int LEVEL_FILE = 0; // Special handling for the FILE type
static const int LEVEL_01 = 01; // Just to avoid magic numbers;
static const int LEVEL_66 = 66; // ibid.;
static const int LEVEL_77 = 77; // ibid.;
static const char SECTION_INPUT_OUTPUT[]= "INPUT-OUTPUT";
typedef std::pair<std::string,std::string> PSS;
typedef std::map<PSS,std::string>MPSS;
......
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