file: direct.cpp
/* direct.cpp This file includes all the support for the directive's //OVERLOAD CALL: directive: direct.h(?), direct.h(?), direct.h(?), direct.h(?), direct.h(?), direct.h(?) */ #include "pre.h" #include "direct.h" //////////////////////////////////////////// /* name initialize_directive Description: initializes the directive map. //OVERLOAD CALL: directive: direct.h(?), direct.h(?), direct.h(?), direct.h(?), direct.h(?), direct.h(?) */ void preprocessor::initialize_directive() { // direct is a member of preprocessor // map<String, directive*, strless> direct; //OVERLOAD CALL: directive: direct.h(?), direct.h(?), direct.h(?), direct.h(?), direct.h(?), direct.h(?) //instances of the classes, each class corresponds to a directive. //OVERLOAD CALL: directive: direct.h(?), direct.h(?), direct.h(?), direct.h(?), direct.h(?), direct.h(?) include *inc = new include; define *def = new define; ifdef *ifd = new ifdef; ifndef *ifn = new ifndef; _else *els = new _else; endif *end = new endif; //typedef pair<const String, directive*> directive_pair; //OVERLOAD CALL: directive: direct.h(?), direct.h(?), direct.h(?), direct.h(?), direct.h(?), direct.h(?) //insert the pairs into the map. direct.insert(directive_pair(inc->name(), inc)); direct.insert(directive_pair(def->name(), def)); direct.insert(directive_pair(ifn->name(), ifn)); direct.insert(directive_pair(ifd->name(), ifd)); direct.insert(directive_pair(els->name(), els)); direct.insert(directive_pair(end->name(), end)); } ////////////////////////////////////////////// void include::operator() (preprocessor *p) { String file_name; ifstream* file = new ifstream; file_name = p->arg()[1]; file->open(file_name, ios::in); p->unfinished_files().push_back(file); } ////////////////////////////////////////////// void define::operator() (preprocessor *p) { String val; val=p->arg()[1]; p->defined().insert(val); } ////////////////////////////////////////////// void ifdef::operator() (preprocessor *p) { String val= p->arg()[1]; if (p->defined().find(val)==p->defined().end()) //not defined p->compilable(false); else p->compilable(true); p->depth()++; p->else_legal().push_back(true); } ////////////////////////////////////////////// void ifndef::operator() (preprocessor *p) { //exact same as ifdef, except for the compilable flag. String s= (String) "ifdef"; //call the ifdef class (*(*p->direct.find(s)).second) (p); p->compilable(!p->compilable()); //sets compilable to !compilable } ////////////////////////////////////////////// void _else::operator() (preprocessor *p) { //switch compilable, deal with else_legal if (p->else_legal().back()==false) //throw an error, shouldn't be used here. //pretend like the else never happened ; else { p->else_legal().pop_back(); p->else_legal().push_back(false); //now illegal to call else p->compilable(!p->compilable()); //sets compilable to !compilable } } ////////////////////////////////////////////// void endif::operator() (preprocessor *p) { //decrement the depth, pop else_legal, set compile=true if (p->depth()>0) { p->depth()--; p->else_legal().pop_back(); p->compilable(true); } else //problem, no corresponding if statement. //throw an error and ignore thie endif ; } //////////////////////////////////////////////
Back to Source File Index
C++ to HTML Conversion by ctoohtml