fixed 2 more warnings under Clang and converted mode to 4 bools.
This commit is contained in:
61
yab2cpp.cpp
61
yab2cpp.cpp
@@ -67,10 +67,14 @@ const string CODETYPES[]={
|
|||||||
};
|
};
|
||||||
|
|
||||||
enum COMPILE_ERRORS errorLevel=E_OK;
|
enum COMPILE_ERRORS errorLevel=E_OK;
|
||||||
unsigned int mode=0;
|
|
||||||
unsigned int indentLevel=0;
|
unsigned int indentLevel=0;
|
||||||
bool scopeGlobal=true;
|
bool scopeGlobal=true;
|
||||||
|
|
||||||
|
bool COMPILE=false;
|
||||||
|
bool DUMP=false;
|
||||||
|
bool DEBUG=false;
|
||||||
|
bool TRACE=false;
|
||||||
|
|
||||||
ifstream src;
|
ifstream src;
|
||||||
ofstream output_cpp;
|
ofstream output_cpp;
|
||||||
ofstream funcs_h;
|
ofstream funcs_h;
|
||||||
@@ -92,7 +96,7 @@ int main(int argc, char *argv[])
|
|||||||
switch (argc)
|
switch (argc)
|
||||||
{
|
{
|
||||||
case 1:
|
case 1:
|
||||||
mode=COMPILE;
|
COMPILE=true;
|
||||||
cout << "\nCompile initiated." << endl;
|
cout << "\nCompile initiated." << endl;
|
||||||
compile();
|
compile();
|
||||||
break;
|
break;
|
||||||
@@ -103,7 +107,7 @@ int main(int argc, char *argv[])
|
|||||||
{
|
{
|
||||||
case 'd':
|
case 'd':
|
||||||
cout << "\nIdentifier dump initiated." << endl;
|
cout << "\nIdentifier dump initiated." << endl;
|
||||||
mode=DUMP;
|
DUMP=true;
|
||||||
compile();
|
compile();
|
||||||
break;
|
break;
|
||||||
case 'v':
|
case 'v':
|
||||||
@@ -112,17 +116,28 @@ int main(int argc, char *argv[])
|
|||||||
break;
|
break;
|
||||||
case 'V':
|
case 'V':
|
||||||
cout << "\nVerbose compile initiated." << endl;
|
cout << "\nVerbose compile initiated." << endl;
|
||||||
mode=DUMP|COMPILE;
|
DUMP=true;
|
||||||
|
COMPILE=true;
|
||||||
compile();
|
compile();
|
||||||
break;
|
break;
|
||||||
case 'D':
|
case 'D':
|
||||||
cout << "\nCompiler debug and dump mode initiated." << endl;
|
cout << "\nCompiler debug and dump mode initiated." << endl;
|
||||||
mode=DUMP|DEBUG;
|
DUMP=true;
|
||||||
|
DEBUG=true;
|
||||||
compile();
|
compile();
|
||||||
break;
|
break;
|
||||||
case 'G':
|
case 'G':
|
||||||
cout << "\nDebug, dump and compile initiated." << endl;
|
cout << "\nDebug, dump and compile initiated." << endl;
|
||||||
mode=DUMP|DEBUG|COMPILE;
|
DUMP=true;
|
||||||
|
DEBUG=true;
|
||||||
|
COMPILE=true;
|
||||||
|
compile();
|
||||||
|
break;
|
||||||
|
case 't':
|
||||||
|
cout << "\nDebug, dump and trace initiated." << endl;
|
||||||
|
DEBUG=true;
|
||||||
|
DUMP=true;
|
||||||
|
TRACE=true;
|
||||||
compile();
|
compile();
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
@@ -141,20 +156,21 @@ int main(int argc, char *argv[])
|
|||||||
/* print the help text to stdout */
|
/* print the help text to stdout */
|
||||||
void helpText(const string commandname)
|
void helpText(const string commandname)
|
||||||
{
|
{
|
||||||
cout << commandname << "[-d|D|V|v|G] < filename.mb\n" <<
|
cout << commandname << "[-d|D|V|v|G|t] < filename.mb\n" <<
|
||||||
"Compiles filename.mb by default unless a flag is specified.\n" <<
|
"Compiles filename.mb by default unless a flag is specified.\n" <<
|
||||||
"\n The optional flags are as follows:\n" <<
|
"\n The optional flags are as follows:\n" <<
|
||||||
"-d is a dump of build to the parse.log file.\n" <<
|
"-d is a dump of build to the parse.log file.\n" <<
|
||||||
"-D is a dump of identifiers and logged build.\n" <<
|
"-D is a dump of identifiers and logged build.\n" <<
|
||||||
"-V is for a verbose build where the compiler logs and compiles.\n" <<
|
"-V is for a verbose build where the compiler logs and compiles.\n" <<
|
||||||
"-v prints the version and exits.\n\n" <<
|
"-v prints the version and exits.\n" <<
|
||||||
|
"-t activates dump, debug and trace\n" <<
|
||||||
"-G activates dump, debug and compile all at once.\n" << endl;
|
"-G activates dump, debug and compile all at once.\n" << endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* open files and initialize them*/
|
/* open files and initialize them*/
|
||||||
void setUp()
|
void setUp()
|
||||||
{
|
{
|
||||||
if (mode & COMPILE)
|
if (COMPILE)
|
||||||
{
|
{
|
||||||
/* compile mode */
|
/* compile mode */
|
||||||
output_cpp.open("output/output.cpp");
|
output_cpp.open("output/output.cpp");
|
||||||
@@ -165,12 +181,12 @@ void setUp()
|
|||||||
<< "#include \"heap.h\"\n#include \"functions.h\"\n"
|
<< "#include \"heap.h\"\n#include \"functions.h\"\n"
|
||||||
<< "unsigned int state=start;\nint run(){\nwhile (state>=start){\n"
|
<< "unsigned int state=start;\nint run(){\nwhile (state>=start){\n"
|
||||||
<< "switch(state){\ncase start:" << endl;
|
<< "switch(state){\ncase start:" << endl;
|
||||||
if (mode & DEBUG)
|
if (DUMP)
|
||||||
{
|
{
|
||||||
varNames.open("varnames.txt");
|
varNames.open("varnames.txt");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (mode & DUMP)
|
if (DEBUG)
|
||||||
{
|
{
|
||||||
/* dump identifier mode */
|
/* dump identifier mode */
|
||||||
logfile.open("parse.log");
|
logfile.open("parse.log");
|
||||||
@@ -184,18 +200,23 @@ void setUp()
|
|||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void indent()
|
||||||
|
{
|
||||||
|
unsigned int count=indentLevel;
|
||||||
|
while (count > 0)
|
||||||
|
{
|
||||||
|
logfile << '\t';
|
||||||
|
--count;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/* write a note in the logfile */
|
/* write a note in the logfile */
|
||||||
void logger(string s)
|
void logger(string s)
|
||||||
{
|
{
|
||||||
unsigned int count;
|
if (DEBUG)
|
||||||
if (mode & DEBUG)
|
|
||||||
{
|
{
|
||||||
count=indentLevel;
|
indent();
|
||||||
while (count > 0)
|
|
||||||
{
|
|
||||||
logfile << '\t';
|
|
||||||
--count;
|
|
||||||
}
|
|
||||||
logfile << s << endl;
|
logfile << s << endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -205,7 +226,7 @@ void shutDown()
|
|||||||
{
|
{
|
||||||
if (errorLevel != E_OK) cerr << "\nERROR: " << COMPILE_ERROR_NAMES[errorLevel] << "\n\n" << endl;
|
if (errorLevel != E_OK) cerr << "\nERROR: " << COMPILE_ERROR_NAMES[errorLevel] << "\n\n" << endl;
|
||||||
logger("Dumping stack.");
|
logger("Dumping stack.");
|
||||||
if (mode & DUMP && (logfile))
|
if (DUMP && (logfile))
|
||||||
{
|
{
|
||||||
fn::dumpCallStack();
|
fn::dumpCallStack();
|
||||||
}
|
}
|
||||||
|
|||||||
38
yab2cpp.h
38
yab2cpp.h
@@ -32,6 +32,8 @@ extern ofstream varNames;
|
|||||||
extern unordered_map<string, shared_ptr<variable> >globals;
|
extern unordered_map<string, shared_ptr<variable> >globals;
|
||||||
extern unordered_map<string, shared_ptr<variable> >locals;
|
extern unordered_map<string, shared_ptr<variable> >locals;
|
||||||
extern unordered_map<string, shared_ptr<variable> >statics;
|
extern unordered_map<string, shared_ptr<variable> >statics;
|
||||||
|
extern const string CODETYPES[];
|
||||||
|
extern const string TYPENAMES[];
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** list of all compiler errors
|
** list of all compiler errors
|
||||||
@@ -55,15 +57,14 @@ enum COMPILE_ERRORS {
|
|||||||
};
|
};
|
||||||
|
|
||||||
extern enum COMPILE_ERRORS errorLevel;
|
extern enum COMPILE_ERRORS errorLevel;
|
||||||
extern unsigned int mode;
|
|
||||||
extern unsigned int indentLevel;
|
extern unsigned int indentLevel;
|
||||||
extern bool scopeGlobal;
|
extern bool scopeGlobal;
|
||||||
|
|
||||||
/* flags used internally by the compiler
|
/* flags used internally by the compiler */
|
||||||
(must be powers of 2) */
|
extern bool COMPILE;
|
||||||
#define COMPILE 1
|
extern bool DUMP;
|
||||||
#define DUMP 2
|
extern bool DEBUG;
|
||||||
#define DEBUG 4
|
extern bool TRACE;
|
||||||
|
|
||||||
/* list of all variable and constant types */
|
/* list of all variable and constant types */
|
||||||
enum TYPES
|
enum TYPES
|
||||||
@@ -81,6 +82,7 @@ enum TYPES
|
|||||||
T_STRINGCALL_ARRAY,
|
T_STRINGCALL_ARRAY,
|
||||||
T_VOIDCALL
|
T_VOIDCALL
|
||||||
};
|
};
|
||||||
|
|
||||||
/* list of all kinds of other code structures */
|
/* list of all kinds of other code structures */
|
||||||
enum CODES
|
enum CODES
|
||||||
{
|
{
|
||||||
@@ -154,6 +156,7 @@ enum OPERATORS
|
|||||||
|
|
||||||
/* global prototype */
|
/* global prototype */
|
||||||
[[noreturn]] void error(enum COMPILE_ERRORS err);
|
[[noreturn]] void error(enum COMPILE_ERRORS err);
|
||||||
|
void indent();
|
||||||
void logger(string s);
|
void logger(string s);
|
||||||
|
|
||||||
/* internal states used by the parser */
|
/* internal states used by the parser */
|
||||||
@@ -253,12 +256,8 @@ class codeType
|
|||||||
public:
|
public:
|
||||||
enum CODES getType() const {return this->type;}
|
enum CODES getType() const {return this->type;}
|
||||||
|
|
||||||
virtual void close()=0;
|
|
||||||
virtual void generateBreak()=0;
|
|
||||||
|
|
||||||
explicit codeType(enum CODES t);
|
explicit codeType(enum CODES t);
|
||||||
virtual ~codeType()
|
virtual ~codeType();
|
||||||
{}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class label
|
class label
|
||||||
@@ -304,11 +303,11 @@ class ifStatement:public codeType
|
|||||||
shared_ptr<label>chain;
|
shared_ptr<label>chain;
|
||||||
public:
|
public:
|
||||||
void generateContinue();
|
void generateContinue();
|
||||||
virtual void generateBreak() override;
|
virtual void generateBreak();
|
||||||
/* enable else or elsif condition */
|
/* enable else or elsif condition */
|
||||||
void alternative(shared_ptr<expression>e=NULL);
|
void alternative(shared_ptr<expression>e=NULL);
|
||||||
/* end if */
|
/* end if */
|
||||||
virtual void close() override;
|
virtual void close();
|
||||||
|
|
||||||
explicit ifStatement(shared_ptr<expression>e);
|
explicit ifStatement(shared_ptr<expression>e);
|
||||||
virtual ~ifStatement()
|
virtual ~ifStatement()
|
||||||
@@ -321,7 +320,7 @@ class repeatLoop:public codeType
|
|||||||
shared_ptr<label>loopStart;
|
shared_ptr<label>loopStart;
|
||||||
shared_ptr<label>loopEnd;
|
shared_ptr<label>loopEnd;
|
||||||
public:
|
public:
|
||||||
virtual void generateBreak() override;
|
virtual void generateBreak();
|
||||||
virtual void close(shared_ptr<expression>e);
|
virtual void close(shared_ptr<expression>e);
|
||||||
|
|
||||||
explicit repeatLoop();
|
explicit repeatLoop();
|
||||||
@@ -334,8 +333,8 @@ class doLoop:public codeType
|
|||||||
shared_ptr<label>loopStart;
|
shared_ptr<label>loopStart;
|
||||||
shared_ptr<label>loopEnd;
|
shared_ptr<label>loopEnd;
|
||||||
public:
|
public:
|
||||||
virtual void generateBreak() override;
|
virtual void generateBreak();
|
||||||
virtual void close() override;
|
virtual void close();
|
||||||
|
|
||||||
explicit doLoop();
|
explicit doLoop();
|
||||||
virtual ~doLoop()
|
virtual ~doLoop()
|
||||||
@@ -349,8 +348,8 @@ class whileLoop:public codeType
|
|||||||
shared_ptr<label>loopEnd;
|
shared_ptr<label>loopEnd;
|
||||||
shared_ptr<expression>cond;
|
shared_ptr<expression>cond;
|
||||||
public:
|
public:
|
||||||
virtual void generateBreak() override;
|
virtual void generateBreak();
|
||||||
virtual void close() override;
|
virtual void close();
|
||||||
|
|
||||||
explicit whileLoop(shared_ptr<expression>e);
|
explicit whileLoop(shared_ptr<expression>e);
|
||||||
virtual ~whileLoop()
|
virtual ~whileLoop()
|
||||||
@@ -374,7 +373,8 @@ class arrayType:public variable
|
|||||||
{
|
{
|
||||||
list<unsigned int> dimensions;
|
list<unsigned int> dimensions;
|
||||||
public:
|
public:
|
||||||
virtual string &boxName(list<unsigned int>indexes);
|
virtual string boxName(list<unsigned int>indexes);
|
||||||
|
virtual string boxName(){error(E_TYPE_MISMATCH);}
|
||||||
|
|
||||||
explicit arrayType(string &name, enum TYPES t, list<unsigned int>dim);
|
explicit arrayType(string &name, enum TYPES t, list<unsigned int>dim);
|
||||||
/*:variable(scope, name, t);*/
|
/*:variable(scope, name, t);*/
|
||||||
|
|||||||
@@ -16,6 +16,22 @@ unsigned int label::nextID;
|
|||||||
codeType::codeType(enum CODES t)
|
codeType::codeType(enum CODES t)
|
||||||
{
|
{
|
||||||
this->type=t;
|
this->type=t;
|
||||||
|
if (TRACE)
|
||||||
|
{
|
||||||
|
indent();
|
||||||
|
logfile << "Entering " << CODETYPES[t];
|
||||||
|
}
|
||||||
|
++indentLevel;
|
||||||
|
}
|
||||||
|
|
||||||
|
codeType::~codeType()
|
||||||
|
{
|
||||||
|
--indentLevel;
|
||||||
|
if (TRACE)
|
||||||
|
{
|
||||||
|
indent();
|
||||||
|
logfile << "Leaving " << CODETYPES[this->getType()];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* label definitions and helper routines */
|
/* label definitions and helper routines */
|
||||||
|
|||||||
Reference in New Issue
Block a user