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