file: resolved_line.cc
/* This file contains the longer methods for the resolved_line class declared in resolved_line.h. The methods included are: private: //attempts to resolve a line in the unresolved multimap based on the string //to_be_resolved bool resolved_line::resolve_map_line(line& current) //attempts to get a new line from the preprocessor bool resolved_line::resolveline(line ¤t) //attempts to resolve a line based on the current contents of the resolved //map bool resolved_line::newline(line& current) public: bool resolved_line::next(line ¤t) //OVERLOAD CALL: next: resolved_line.cc(resolved_line), line.cpp(line), pre.cpp(preprocessor) //returns a good line or false if there are no more good lines resolved_line::~resolved_line() //does some error checking Revision History: first made: 3/4/96 by John Langford */ #include "resolved_line.h" /* bool resolved_line::resolve_map_line(line& current) Description: attempts to resolve a line in the unresolved multimap based on the String to_be_resolved Arguments: line& current - line to fill in with a resolved line Return Value: whether or not there was a line that could be resolved Inputs: None. Outputs: None. Error Handling: None. Algorithms: None. Data Structures: None. Last Modified: 3/4/97 */ bool resolved_line::resolve_map_line(line& current) { bool resline=false; while(!resline){ multimap<String,line,comp_String>::iterator linep //OVERLOAD CALL: comp_String: filtermain.cc(?), resolved_line.h(?) =unresolved.find(to_be_resolved); if (linep==unresolved.end()) //there are no lines remaing to be further resolved by this identifier return false; else {// a resolvable line exists map<String,String,comp_String>::iterator rep //OVERLOAD CALL: comp_String: filtermain.cc(?), resolved_line.h(?) =resolved.find(to_be_resolved); assert(rep!=resolved.end()); current=(*linep).second; current.fill(to_be_resolved,(*rep).second); resline=resolveline(current); unresolved.erase(linep); } } return true; } /* bool resolved_line::next(line& current) //OVERLOAD CALL: next: resolved_line.cc(resolved_line), line.cpp(line), pre.cpp(preprocessor) Description: attempts to resolve a line, either in the unresolved multimap (preferred) or from the preprocessor Arguments: line& current - line to fill in with a resolved line Return Value: whether or not there was a line that could be resolved Inputs: None. Outputs: None. Error Handling: None. Algorithms: None. Data Structures: None. Last Modified: 3/4/97 */ bool resolved_line::next(line ¤t) { if (resolving)//there are lines which can be resolved at this time resolving=resolve_map_line(current); if (!resolving)//Nothing could be resolved by resolve return newline(current); else return true;//an identifier was resolved allowing passing on of the line } /* bool resolved_line::resolveline(line ¤t) Description: attempts to resolve a line based on the contents of the resolved map. Arguments: line& current - line to fill in with a resolved line Return Value: whether or not the line was resolvable at this time Inputs: None. Outputs: None. Error Handling: none. Algorithms: None. Data Structures: None. Last Modified: 3/4/97 */ bool resolved_line::resolveline(line ¤t) { bool resolvable=true; String temp; if(current.next(temp)){ //OVERLOAD CALL: next: resolved_line.cc(resolved_line), line.cpp(line), pre.cpp(preprocessor) while(resolvable && temp.length()!=0) {//there are tokens to be resolved map<String,String,comp_String>::iterator i=resolved.find(temp); //OVERLOAD CALL: comp_String: filtermain.cc(?), resolved_line.h(?) if(i!=resolved.end()) //token can be resolved now current.fill(temp,(*i).second); else{ //token can't be resolved now const pair<const String,line> tmp(temp,current); unresolved.insert(tmp); resolvable=false;//can't return this line } } } return resolvable; } /* resolved_line::~resolved_line() Description: Checks the unresolved multimap to see if it is empty or not. Arguments: none Return Value: none. Inputs: None. Outputs: None. Error Handling: error class Algorithms: None. Data Structures: None. Last Modified: 3/4/97 */ resolved_line::~resolved_line() { for (multimap<String,line,comp_String>::iterator i=unresolved.begin(); //OVERLOAD CALL: comp_String: filtermain.cc(?), resolved_line.h(?) i!=unresolved.end();i++) { err(UNRESOLVABLE,(*i).second, (*i).first); } } /* bool resolved_line::newline(line& current) Description: Grabs lines from the preprocessor until it finds a line which can be fully resolved. Arguments: line& current - fully resolved line that will be filled in Return Value: bool - false if there are no more resolvable lines. Inputs: None. Outputs: None. Error Handling: error class Algorithms: None. Data Structures: None. Last Modified: 3/4/97 */ bool resolved_line::newline(line& current) { bool returnable=false; while(!returnable){ if (preproc.next(current)) //OVERLOAD CALL: next: resolved_line.cc(resolved_line), line.cpp(line), pre.cpp(preprocessor) { returnable=true;//asume we can return this line for now if(current.instruction())//an instruction to be compiled {//need to check if tokens must be resolved current.location(current_location); current_location++; returnable=resolveline(current); } else {//sigh. This is a bit ugly. current.location(-1); if(current.pseudoop()) { //this line contains a resolution of an //identifier if (current.org()) if(resolveline(current)) current_location=current.location(); else err(UNRESOLVABLE_ORG,current,String()); else {//EQU or label String arg2,arg1; if (!current.next(arg1)) //OVERLOAD CALL: next: resolved_line.cc(resolved_line), line.cpp(line), pre.cpp(preprocessor) err(BAD_ARGUMENT_1,current,arg1); if (current.equ()) if (!current.next(arg2)) //OVERLOAD CALL: next: resolved_line.cc(resolved_line), line.cpp(line), pre.cpp(preprocessor) err(BAD_ARGUMENT_2,current,arg2); else//it's a label { char buf[100]; sprintf(buf,"%i",current_location); arg2=buf; } map<String,String,comp_String>::iterator i; //OVERLOAD CALL: comp_String: filtermain.cc(?), resolved_line.h(?) if((i=resolved.find(arg1))!=resolved.end()) err(DOUBLE_IDENTIFICATION,current,arg1); else { const pair<const String,String> temp(arg1,arg2); resolved.insert(temp); resolving=true;//there may be previous lines that are now //resolvable, so set up for next call for the next line to_be_resolved=arg1; } } } } } else return false;//the preprocessor has run out of lines } return true;//we succeeded in fully resolving a line }
Back to Source File Index
C++ to HTML Conversion by ctoohtml