From 1d3829a47e0d43ecb72c56d64a8b7a3ffe61a92f Mon Sep 17 00:00:00 2001 From: "Samuel D. Crow" Date: Tue, 23 Mar 2021 16:25:37 -0500 Subject: [PATCH] fixed 2 more warnings under Clang and converted mode to 4 bools. --- yab2cpp.cpp | 61 +++++++++++++++++++++++++++++-------------- yab2cpp.h | 38 +++++++++++++-------------- yabCodeStructures.cpp | 16 ++++++++++++ 3 files changed, 76 insertions(+), 39 deletions(-) diff --git a/yab2cpp.cpp b/yab2cpp.cpp index aeace66..319c9fb 100644 --- a/yab2cpp.cpp +++ b/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(); } diff --git a/yab2cpp.h b/yab2cpp.h index 2632442..9c7b93e 100644 --- a/yab2cpp.h +++ b/yab2cpp.h @@ -32,6 +32,8 @@ extern ofstream varNames; extern unordered_map >globals; extern unordered_map >locals; extern unordered_map >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