Main Page | Class Hierarchy | Alphabetical List | Data Structures | File List | Data Fields | Globals

rtreenamedcontextrule.cpp

Go to the documentation of this file.
00001 #include "rtreenamedcontextrule.h"
00002 #include "namedcontext.h"
00003 
00004 NamedContextRule::NamedContextRule(Constant *iname, RunRuleList &irunRuleList, List* iphpInPattern, List* iphpOutPattern, 
00005                                    Variable* inamePattern, Variable* iargumentsPattern, 
00006                                    Variable* icontextPattern) :
00007     name(iname->getValue()),
00008     runRuleList(irunRuleList), 
00009     phpInPattern(iphpInPattern), 
00010     phpOutPattern(iphpOutPattern), 
00011     namePattern(inamePattern), 
00012     argumentsPattern(iargumentsPattern), 
00013     contextPattern(icontextPattern) {
00014   delete iname;
00015 };
00016 
00017 NamedContextRule::~NamedContextRule(){
00018   delete phpInPattern;
00019   delete namePattern;
00020   delete argumentsPattern;
00021   delete contextPattern;
00022 };
00023 
00024 void NamedContextRule::runRules(NameSpace &subNameSpace, Node* phpContextMatched, StatementList* phpContextOut, 
00025                                 StatementList* tplContextOut, Node::Assignment& assign) const {
00026 
00027   RunRuleList::iterator ruleListIt = runRuleList.find(subNameSpace.getRuleRunTime());
00028   if (ruleListIt!=runRuleList.end()){
00029     NamedContext subcontext(name,ruleListIt->second,subNameSpace);
00030     subcontext.execute(phpContextMatched, phpContextOut, tplContextOut);
00031     if ((tplContextOut->getLength()) && (name != MAINCONTEXTNAME))
00032       throw "NamedContextRule::execute - template output is not empty";
00033     ruleListIt++;
00034   };
00035 }
00036 
00037 
00038 bool NamedContextRule::execute(RuleContext* context, List* phpIn, List* phpOut, List* tplOut, Node::Assignment& assign) const {
00039   if (phpInPattern->matchToBegining(phpIn,assign, context->getNameSpace())){
00040 
00041     Node* phpNameMatched = namePattern->copy();
00042     substituteNode(phpNameMatched, assign);
00043     Node* phpArgumentsMatched = argumentsPattern->copy();
00044     substituteNode(phpArgumentsMatched,assign);
00045     Node* phpContextMatched = contextPattern->copy();
00046     substituteNode(phpContextMatched,assign);
00047 
00048     NameSpace subNameSpace(context->getNameSpace());
00049     subNameSpace.processArguments(phpArgumentsMatched);
00050 
00051     StatementList *phpContextOut = new StatementList();
00052     StatementList *tplContextOut = new StatementList();
00053 
00054     runRules(subNameSpace, phpContextMatched, phpContextOut, tplContextOut, assign);
00055     
00056     assign[contextPattern->getId()] = phpContextOut;
00057     StatementList *phpOutMatched = dynamic_cast<StatementList*>(phpOutPattern->copy());
00058     phpOutMatched->substitute(assign);
00059     phpOut->append(phpOutMatched);
00060     tplOut->append(tplContextOut);
00061 
00062     for (int i=0 ; i<phpInPattern->getLength() ; i++){
00063       delete phpIn->front();
00064       phpIn->pop_front();
00065     };
00066 
00067     context->getNameSpace().importLocals(phpNameMatched->toString(), subNameSpace);
00068     return true;
00069   }
00070   return false;
00071 };
00072 
00073 ostream& NamedContextRule::print(ostream& os) const{
00074       os << "NamedContextRule - ";
00075       phpInPattern->print(os);
00076       //      tplOutPattern->print(os);
00077       return os;
00078 };
00079 
00080 Rule* NamedContextRule::copy(){
00081   throw "ERROR: NamedContextRule::copy called";
00082 };
00083 
00084 Rule* NamedContextRule::substitute(const Node::Assignment &assign){
00085   throw "ERROR: NamedContextRule::substitute called";
00086 };

Generated on Fri Nov 21 17:54:03 2003 for PHPX by doxygen 1.3.3