Commit f724f972 authored by rdubner's avatar rdubner

Expand LINKAGE finding in cobst

parent 4b046cb0
......@@ -48,7 +48,8 @@
using namespace std;
void scan_test(const string &filename)
void
scan_test(const string &filename)
{
PROFILER;
ifstream ifs;
......@@ -83,10 +84,11 @@ void scan_test(const string &filename)
fclose(f);
}
void CreateFullCSV(PARAMETERS &params,
const COB_LABELS &cob_labels,
const DATA_DESCRIPTIONS &data_description
)
void
CreateFullCSV(PARAMETERS &params,
const COB_LABELS &cob_labels,
const DATA_DESCRIPTIONS &data_description
)
{
/* During development, I created this all-encompassing output file that
includes everything I had found up to the point where I started
......@@ -439,7 +441,8 @@ CreateCSV(PARAMETERS &params,
csv.Generate(params.csv);
}
static string ZeroIsNull(const LONGLONG &v)
static string
ZeroIsNull(const LONGLONG &v)
{
stringstream ss;
if( v != 0 ) {
......@@ -622,7 +625,8 @@ CreateSymc(PARAMETERS &params,
return;
}
int main(int argc, char *argv[])
int
main(int argc, char *argv[])
{
PROFILER;
......
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LocalDebuggerCommandArguments>c:\temp\NC401M</LocalDebuggerCommandArguments>
<LocalDebuggerCommandArguments>c:\temp\bob01</LocalDebuggerCommandArguments>
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LocalDebuggerCommandArguments>c:\temp\NC401M</LocalDebuggerCommandArguments>
<LocalDebuggerCommandArguments>c:\temp\bob01</LocalDebuggerCommandArguments>
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<LocalDebuggerCommandArguments>c:\temp\NC401M</LocalDebuggerCommandArguments>
<LocalDebuggerCommandArguments>c:\temp\bob01</LocalDebuggerCommandArguments>
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<LocalDebuggerCommandArguments>c:\temp\NC401M</LocalDebuggerCommandArguments>
<LocalDebuggerCommandArguments>c:\temp\bob01</LocalDebuggerCommandArguments>
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
</PropertyGroup>
</Project>
\ No newline at end of file
......@@ -63,7 +63,8 @@ private:
std::vector<CSV_COLUMN> columns;
std::unordered_map<int,size_t> id_to_column;
std::string Linify(const std::string &s)
std::string
Linify(const std::string &s)
{
#if 0 // This code was for quotes and commas
std::string retval = "\"";
......@@ -78,7 +79,8 @@ private:
return s;
}
bool IsConsistent()
bool
IsConsistent()
{
bool okay = true;
size_t rows = 0;
......@@ -103,7 +105,8 @@ private:
}
public:
void AddColumn(int id, std::string header)
void
AddColumn(int id, std::string header)
{
if(id_to_column.find(id) != id_to_column.end()) {
std::cerr << "You are trying to reuse a column identifier in CSV_GENERATOR::AddColumn().\n";
......@@ -115,7 +118,8 @@ public:
id_to_column[id] = columns.size()-1;
}
void AddData(int id, std::string data)
void
AddData(int id, std::string data)
{
if(id_to_column.find(id) == id_to_column.end()) {
std::cerr << "You are trying to use unknown ID " << id << " in CSV_GENERATOR::AddData()" << std::endl;
......@@ -124,7 +128,8 @@ public:
columns[id_to_column[id]].data.push_back(data);
}
void Generate(std::ofstream &ofs)
void
Generate(std::ofstream &ofs)
{
IsConsistent();
const int ncolumns = static_cast<int>(columns.size());
......@@ -152,7 +157,8 @@ public:
}
}
void Normalize()
void
Normalize()
{
const int ncolumns = static_cast<int>(columns.size());
size_t max_entries = 0;
......@@ -167,7 +173,8 @@ public:
}
}
void Generate(const std::string &filename)
void
Generate(const std::string &filename)
{
IsConsistent();
......
......@@ -59,7 +59,8 @@ char const * optarg; /* argument associated with option */
#undef EMSG
#define EMSG ""
int getopt(int nargc, char * const * nargv, const char * ostr)
int
getopt(int nargc, char * const * nargv, const char * ostr)
{
static char *progname = *nargv;
static char const * place = EMSG; /* option letter processing */
......@@ -126,7 +127,8 @@ int getopt(int nargc, char * const * nargv, const char * ostr)
#include <ctype.h>
#include "getopt.h"
void testopt(int argc, char **argv)
void
testopt(int argc, char **argv)
{
int aflag = 0;
int bflag = 0;
......@@ -173,7 +175,8 @@ void testopt(int argc, char **argv)
printf("\n");
}
int main()
int
main()
{
char *test1[] = {"x"};
char *test2[] = {"x","-a","-b"};
......
......@@ -44,7 +44,8 @@ using namespace std;
#define AND &&
#define OR ||
string GetCommentText(const string &s)
string
GetCommentText(const string &s)
{
PROFILER;
string retval;
......@@ -65,7 +66,8 @@ string GetCommentText(const string &s)
return retval;
}
void GAS_SYMBOLS::GetSymbolsFromFile(const string &source, const string &scope, ifstream &ifs)
void
GAS_SYMBOLS::GetSymbolsFromFile(const string &source, const string &scope, ifstream &ifs)
{
CPROFILER;
ifs.clear();
......@@ -155,7 +157,8 @@ void GAS_SYMBOLS::GetSymbolsFromFile(const string &source, const string &scope,
}
}
void GAS_SYMBOLS::UpdateBaseOffset(string symbol, string base, string offset)
void
GAS_SYMBOLS::UpdateBaseOffset(string symbol, string base, string offset)
{
unordered_map<string,size_t>::iterator it = gas_undecorated_symbol_location.find(symbol);
if(it != gas_undecorated_symbol_location.end()) {
......@@ -165,7 +168,8 @@ void GAS_SYMBOLS::UpdateBaseOffset(string symbol, string base, string offset)
}
}
void COB_LABELS::GetSymbolsFromFile(const string &source, const string &scope, ifstream &ifs, GAS_SYMBOLS &gas_symbol_table)
void
COB_LABELS::GetSymbolsFromFile(const string &source, const string &scope, ifstream &ifs, GAS_SYMBOLS &gas_symbol_table)
{
CPROFILER;
ifs.clear();
......@@ -273,7 +277,7 @@ void COB_LABELS::GetSymbolsFromFile(const string &source, const string &scope, i
string current_c_source_line = "000";
string current_cbl_source = "dummy.cbl";
set<string>linkage_weve_seen;
set<pair<string,string>>linkage_weve_seen;
for(;;) {
getline(ifs,input);
if(ifs.eof()) {
......@@ -487,8 +491,11 @@ void COB_LABELS::GetSymbolsFromFile(const string &source, const string &scope, i
smatch sm;
static const regex linkage(".*\\(([^,]+),[^']+[']([^']+).*$");
if(regex_match(input,sm,linkage)) {
if( linkage_weve_seen.find(sm[1]) EQ linkage_weve_seen.end() ) {
linkage_weve_seen.insert(sm[1]);
pair<string,string> cobol_c;
cobol_c.first = sm[1];
cobol_c.second = sm[2];
if( linkage_weve_seen.find(cobol_c) EQ linkage_weve_seen.end() ) {
linkage_weve_seen.insert(cobol_c);
COB_LABEL cs;
cs.source_file = current_cbl_source;
cs.line_number = current_line_number;
......@@ -509,6 +516,40 @@ void COB_LABELS::GetSymbolsFromFile(const string &source, const string &scope, i
// contain COB_SET_DATA
to_be_continued = true;
}
if( tokens.size() >= 3 AND tokens[2] EQ "cob_check_numeric" ) {
// Typical line:
//
// 351:bob01.c **** cob_check_numeric (COB_SET_DATA (f_18, b_18), "aaaa");
//
// We want to associate the aaaa with b_18
//
smatch sm;
static const regex linkage(".*\\(COB_SET_DATA [^,]+, ([^)]+)[^\"]+\"([^\"]+).*$");
if(regex_match(input,sm,linkage)) {
pair<string,string> cobol_c;
cobol_c.first = sm[1];
cobol_c.second = sm[2];
if( linkage_weve_seen.find(cobol_c) EQ linkage_weve_seen.end() ) {
linkage_weve_seen.insert(cobol_c);
COB_LABEL cs;
cs.source_file = current_cbl_source;
cs.line_number = current_line_number;
cs.sentence_number = current_sentence_number;
if(program_id_stack.size() >= 1) {
cs.program = program_id_stack.back();
}
cs.entry = sm[2];
cs.section = "Linkage";
cs.paragraph = current_paragraph;
// Linkage isn't in .text, but rather .data.rel.local
cs.gas_section = ".data.rel.local";
cs.gas_symbol = sm[1];
symbols.push_back(cs);
}
}
continue;
}
size_t ncob = 0;
while((ncob = input.find("COB_SET_DATA",ncob)) != string::npos) {
// We know we'll get at least one hit, so we can do the expensive regex_match with confidence:
......@@ -641,9 +682,11 @@ void COB_LABELS::GetSymbolsFromFile(const string &source, const string &scope, i
}
}
}
return;
}
void COB_LABELS::GetProgramIdLineNumbers(const std::string &source, const std::string &scope, std::ifstream &ifs, GAS_SYMBOLS &gas_symbol_table)
void
COB_LABELS::GetProgramIdLineNumbers(const std::string &source, const std::string &scope, std::ifstream &ifs, GAS_SYMBOLS &gas_symbol_table)
{
CPROFILER;
ifs.clear();
......@@ -725,7 +768,8 @@ void COB_LABELS::GetProgramIdLineNumbers(const std::string &source, const std::s
}
}
void COB_LABELS::MergeGasSymbols(const GAS_SYMBOLS &gas_symbol_table)
void
COB_LABELS::MergeGasSymbols(const GAS_SYMBOLS &gas_symbol_table)
{
CPROFILER;
for(VCOB_LABEL::iterator it=symbols.begin(); it!=symbols.end(); it++) {
......@@ -741,7 +785,8 @@ void COB_LABELS::MergeGasSymbols(const GAS_SYMBOLS &gas_symbol_table)
}
}
void DATA_DESCRIPTIONS::ProcessDataStorage(ifstream &ifs,const string &source)
void
DATA_DESCRIPTIONS::ProcessDataStorage(ifstream &ifs,const string &source)
{
ifs.clear();
ifs.seekg(0);
......@@ -1017,7 +1062,8 @@ void DATA_DESCRIPTIONS::ProcessDataStorage(ifstream &ifs,const string &source)
}
}
void DATA_DESCRIPTIONS::AppendLinkageInformation(const COB_LABELS &cob_labels)
void
DATA_DESCRIPTIONS::AppendLinkageInformation(const COB_LABELS &cob_labels)
{
for( int i=0; i<cob_labels.size(); i++ ) {
COB_LABEL cl = cob_labels[i];
......@@ -1036,7 +1082,8 @@ void DATA_DESCRIPTIONS::AppendLinkageInformation(const COB_LABELS &cob_labels)
}
void DATA_DESCRIPTIONS::MergeGasSymbols(const GAS_SYMBOLS &gas_symbol_table)
void
DATA_DESCRIPTIONS::MergeGasSymbols(const GAS_SYMBOLS &gas_symbol_table)
{
CPROFILER;
// First pass: Match symbols based on gas_name
......@@ -1061,7 +1108,8 @@ void DATA_DESCRIPTIONS::MergeGasSymbols(const GAS_SYMBOLS &gas_symbol_table)
}
}
void DATA_DESCRIPTIONS::ScanAllDotHFiles(const string &path,const string &fname)
void
DATA_DESCRIPTIONS::ScanAllDotHFiles(const string &path,const string &fname)
{
vector<string>AllDotHFiles = DirectoryScan(path,fname,"*.h");
for(vector<string>::const_iterator filename = AllDotHFiles.begin(); filename != AllDotHFiles.end(); filename++) {
......
......@@ -75,14 +75,16 @@ protected:
std::unordered_map<std::string,size_t>gas_undecorated_symbol_location;
std::unordered_map<std::string,size_t> reverse_gas_symbol_location;
std::string SectionValueCombiner(const std::string &section,LONGLONG value) const
std::string
SectionValueCombiner(const std::string &section,LONGLONG value) const
{
std::stringstream ss;
ss<<value;
return section + ":" + ss.str();
}
void SectionValueSplitter(const std::string &combined,std::string &section, LONGLONG &value)
void
SectionValueSplitter(const std::string &combined,std::string &section, LONGLONG &value)
{
section.clear();
value = 0;
......@@ -96,7 +98,8 @@ protected:
public:
void GetSymbolsFromFile(const std::string &source, const std::string &scope, std::ifstream &ifs);
GAS_SYMBOL FindGasSymbol(const std::string &sym) const
GAS_SYMBOL
FindGasSymbol(const std::string &sym) const
{
GAS_SYMBOL retval;
if(!sym.empty()) {
......@@ -108,7 +111,8 @@ public:
return retval;
}
GAS_SYMBOL FindGasValue(const std::string &section,LONGLONG value) const
GAS_SYMBOL
FindGasValue(const std::string &section,LONGLONG value) const
{
GAS_SYMBOL retval;
const std::string sectionvalue = SectionValueCombiner(section,value);
......@@ -123,12 +127,14 @@ public:
void UpdateBaseOffset(std::string symbol, std::string base, std::string offset);
int size() const
int
size() const
{
return static_cast<int>(symbols.size());
}
const GAS_SYMBOL & operator[](int n) const
const GAS_SYMBOL &
operator[](int n) const
{
return symbols[n];
}
......@@ -168,12 +174,14 @@ public:
void GetSymbolsFromFile(const std::string &source, const std::string &scope, std::ifstream &ifs, GAS_SYMBOLS &gas_symbol_table);
void MergeGasSymbols(const GAS_SYMBOLS &gas_symbol_table);
int size() const
int
size() const
{
return static_cast<int>(symbols.size());
}
const COB_LABEL & operator[](int n) const
const COB_LABEL &
operator[](int n) const
{
return symbols[n];
}
......@@ -240,17 +248,20 @@ public:
void MergeGasSymbols(const GAS_SYMBOLS &gas_symbol_table);
int size() const
int
size() const
{
return static_cast<int>(symbols.size());
}
const DATA_DESCRIPTION & operator[](int n) const
const DATA_DESCRIPTION &
operator[](int n) const
{
return symbols[n];
}
int IndexOfSymbol(const std::string &symbol) const
int
IndexOfSymbol(const std::string &symbol) const
{
std::unordered_map<std::string,size_t>::const_iterator it =
location_of_gas_symbol.find(symbol);
......@@ -260,7 +271,8 @@ public:
return static_cast<int>(it->second);
}
std::string WeveSeen(const std::string &b_sym) const
std::string
WeveSeen(const std::string &b_sym) const
{
std::string retval;
std::unordered_map<std::string,std::string>::const_iterator it
......
......@@ -48,7 +48,8 @@
using namespace std;
void FILENAME::Decode(const string &filename_)
void
FILENAME::Decode(const string &filename_)
{
drive.clear();
path.clear();
......@@ -148,7 +149,8 @@ void FILENAME::Decode(const string &filename_)
}
#ifdef _DEBUG
void DecodeTest()
void
DecodeTest()
{
vector<string>tests = {
"",
......@@ -193,7 +195,8 @@ void DecodeTest()
}
#endif
static void Usage()
static void
Usage()
{
cerr << "cobst: Cobol Symbol Table generator version: " << VERSION << endl;
cerr << "cobst [-v] [-q] FileName.CBL\n";
......@@ -203,7 +206,8 @@ static void Usage()
cerr << "-v generates the one-line version announcement and exits\n";
}
void OpenOrFail(std::ifstream &ifs,const std::string &fname,std::ios_base::openmode mode/* = std::ifstream::in*/)
void
OpenOrFail(std::ifstream &ifs,const std::string &fname,std::ios_base::openmode mode/* = std::ifstream::in*/)
{
ifs.open(fname,mode);
if(!ifs.is_open()) {
......@@ -213,7 +217,8 @@ void OpenOrFail(std::ifstream &ifs,const std::string &fname,std::ios_base::openm
}
}
void OpenOrFail(std::ofstream &ofs,const std::string &fname,std::ios_base::openmode mode/* = std::ofstream::out*/)
void
OpenOrFail(std::ofstream &ofs,const std::string &fname,std::ios_base::openmode mode/* = std::ofstream::out*/)
{
ofs.open(fname,mode);
if(!ofs.is_open()) {
......@@ -223,7 +228,8 @@ void OpenOrFail(std::ofstream &ofs,const std::string &fname,std::ios_base::openm
}
}
PARAMETERS GetParameters(int argc, char *argv[])
PARAMETERS
GetParameters(int argc, char *argv[])
{
if(argc < 2) {
Usage();
......@@ -278,7 +284,8 @@ PARAMETERS GetParameters(int argc, char *argv[])
return retval;
}
vector<string>DirectoryScan(const string &path,const string &fname,const string &wildcard)
vector<string>
DirectoryScan(const string &path,const string &fname,const string &wildcard)
{
vector<string>retval;
#ifdef _WIN32
......
......@@ -33,7 +33,7 @@
#include <string>
#include <fstream>
#define VERSION "1.3.1"
#define VERSION "1.3.2"
class FILENAME
{
......@@ -45,14 +45,16 @@ private:
public:
void Decode(const std::string &filename);
std::string Stem() const
std::string
Stem() const
{
std::string retval = drive;
retval += path;
retval += fname;
return retval;
}
void SetExtension(const std::string &ex)
void
SetExtension(const std::string &ex)
{
if(ex.size() >= 1 && ex[0] != '.') {
ext = '.';
......@@ -61,16 +63,19 @@ public:
ext = ex;
}
}
std::string GetFname() const
std::string
GetFname() const
{
return fname;
}
std::string GetExt() const
std::string
GetExt() const
{
return ext;
}
std::string GetFandExt() const
std::string
GetFandExt() const
{
std::string retval;
retval = fname + ext;
......@@ -78,17 +83,20 @@ public:
return retval;
}
std::string WholePath() const
std::string
WholePath() const
{
return drive + path + fname + ext;
}
std::string PathToRoot() const
std::string
PathToRoot() const
{
return drive + path + fname;
}
std::string Path() const
std::string
Path() const
{
return drive + path;
}
......
......@@ -35,7 +35,8 @@ std::unordered_map<std::string,double> PPROFILER::ProfilerRoutineTimes;
std::unordered_map<std::string,LONGLONG> PPROFILER::ProfilerRoutineEntries;
std::vector<double> PPROFILER::AccumulatedTimes;
std::ostream &operator<<(std::ostream &os, PPROFILER const &m)
std::ostream &
operator<<(std::ostream &os, PPROFILER const &m)
{
return os << m.Dump();
}
......@@ -93,7 +93,8 @@ public:
}
}
void LapTime()
void
LapTime()
{
std::chrono::steady_clock::time_point lt1 = std::chrono::steady_clock::now();
std::chrono::duration<double> lap_time = std::chrono::duration_cast<std::chrono::duration<double>>(lt1-lap_timer);
......@@ -110,7 +111,8 @@ public:
lap_time_overhead += overhead.count();
}
void Freeze()
void
Freeze()
{
oh_3 = time_out = std::chrono::steady_clock::now();
std::chrono::duration<double> time_span = std::chrono::duration_cast<std::chrono::duration<double>>(time_out - time_in);
......@@ -133,7 +135,8 @@ public:
friend std::ostream &operator<<(std::ostream &os, PPROFILER const &m);
std::string Dump() const
std::string
Dump() const
{
std::stringstream ss;
......
......@@ -37,7 +37,8 @@
using namespace std;
string Trim(const string &s)
string
Trim(const string &s)
{
PROFILER;
string retval=s;
......@@ -56,7 +57,8 @@ string Trim(const string &s)
return retval;
}
string RTrim(const string &s)
string
RTrim(const string &s)
{
PROFILER;
string retval=s;
......@@ -69,7 +71,8 @@ string RTrim(const string &s)
return retval;
}
string StripQuotes(const string &s)
string
StripQuotes(const string &s)
{
PROFILER;
string retval=s;
......@@ -82,7 +85,8 @@ string StripQuotes(const string &s)
return retval;
}
vector<string> Split(const string &s,const string &delimiters)
vector<string>
Split(const string &s,const string &delimiters)
{
PROFILER;
vector<string>retval;
......@@ -111,7 +115,8 @@ next_c:
return retval;
}
string Replace(const string &s,const char was, const char is)
string
Replace(const string &s,const char was, const char is)
{
string retval;
......@@ -125,7 +130,8 @@ string Replace(const string &s,const char was, const char is)
return retval;
}
string Upper(const string &s)
string
Upper(const string &s)
{
string retval;
for(char ch : s) {
......
......@@ -54,7 +54,8 @@ VAR_NODE::VAR_NODE()
attr_flags = 0;
}
void VAR_NODE::AddChild(VAR_NODE *new_node)
void
VAR_NODE::AddChild(VAR_NODE *new_node)
{
CPROFILER;
......@@ -113,7 +114,8 @@ VARIABLE_TREE::~VARIABLE_TREE()
ChopDownTheTree();
}
void VARIABLE_TREE::ChopDownTheTree(VAR_NODE *node)
void
VARIABLE_TREE::ChopDownTheTree(VAR_NODE *node)
{
CPROFILER;
if(node) {
......@@ -127,13 +129,15 @@ void VARIABLE_TREE::ChopDownTheTree(VAR_NODE *node)
}
}
void VARIABLE_TREE::ChopDownTheTree()
void
VARIABLE_TREE::ChopDownTheTree()
{
CPROFILER;
ChopDownTheTree(root);
}
void VARIABLE_TREE::FindParentOf(VVAR_NODES &parents,int level)
void
VARIABLE_TREE::FindParentOf(VVAR_NODES &parents,int level)