Beispiel #1
0
 public function compile(IObject $aObject, ObjectContainer $aObjectContainer, TargetCodeOutputStream $aDev, CompilerManager $aCompilerManager)
 {
     Type::check("org\\jecat\\framework\\ui\\xhtml\\Node", $aObject);
     $sLang = strtolower($aObject->attributes()->string('lang'));
     if (in_array($sLang, array('text/php', 'php')) and $aTailTag = $aObject->tailTag()) {
         // 编译头标签
         $this->compileTag($aObject->headTag(), $aObjectContainer, $aDev, $aCompilerManager);
         // 设置代码"上色器"
         $sVarName = parent::assignVariableName();
         $aDev->write("\r\n");
         $aDev->write("\${$sVarName} = new \\org\\jecat\\framework\\ui\\xhtml\\compiler\\node\\CodeColor() ;\r\n");
         $aDev->write("\\org\\jecat\\framework\\io\\StdOutputFilterMgr::singleton()->add(array(\${$sVarName},'outputFilter')) ;\r\n");
         $aDev->write("");
         // 编译 node body
         $this->compileChildren($aObject, $aObjectContainer, $aDev, $aCompilerManager);
         // 输出代码
         $aDev->write("\r\n");
         $aDev->write("\\org\\jecat\\framework\\io\\StdOutputFilterMgr::singleton()->remove( array(\${$sVarName},'outputFilter') ) ;\r\n");
         $aDev->write("\${$sVarName}->output(\$aDevice) ;");
         $aDev->write("");
         // 编译尾标签
         $this->compileTag($aTailTag, $aObjectContainer, $aDev, $aCompilerManager);
     } else {
         parent::compile($aObject, $aObjectContainer, $aDev, $aCompilerManager);
     }
 }
 public function compile(IObject $aObject, ObjectContainer $aObjectContainer, TargetCodeOutputStream $aDev, CompilerManager $aCompilerManager)
 {
     Assert::type("org\\jecat\\framework\\ui\\xhtml\\Node", $aObject, 'aObject');
     $aAttrs = $aObject->attributes();
     if (!$aAttrs->has('id')) {
         throw new Exception("widget标签缺少必要属性:%s", 'id');
     }
     $sId = $aAttrs->get('id');
     $aDev->write("\$__ui_widget = \$aVariables->get('theView')->widget( {$sId} ) ;\r\n");
     $aDev->write("if(!\$__ui_widget){");
     $aDev->write("\tthrow new \\org\\jecat\\framework\\lang\\Exception('指定的widget id(%s)不存在,无法显示该widget的消息队列',array({$sId})) ; \r\n");
     $aDev->write("}else{");
     // 使用 <msgqueue> 节点内部的模板内容
     if ($aTemplate = $aObject->getChildNodeByTagName('template')) {
         $sOldMsgQueueVarVarName = '$' . parent::assignVariableName('_aOldMsgQueueVar');
         $aDev->write("\t{$sOldMsgQueueVarVarName}=\$aVariables->get('aMsgQueue') ;");
         $aDev->write("\t\$aVariables->set('aMsgQueue',\$__ui_widget->messageQueue()) ;");
         $this->compileChildren($aTemplate, $aObjectContainer, $aDev, $aCompilerManager);
         $aDev->write("\t\$aVariables->set('aMsgQueue',{$sOldMsgQueueVarVarName}) ;");
     } else {
         $aDev->write("\tif( \$__ui_widget->messageQueue()->count() ){ \r\n");
         $aDev->write("\t\t\$__ui_widget->messageQueue()->display(\$this,\$aDevice) ;\r\n");
         $aDev->write("\t}\r\n");
     }
     $aDev->write("}");
 }
Beispiel #3
0
 public function createNodeCompiler()
 {
     // Node Compiler
     if (!($aNodeCompiler = NodeCompiler::singleton(false))) {
         $aNodeCompiler = NodeCompiler::singleton(true);
         //if
         $aNodeCompiler->addSubCompiler('if', __NAMESPACE__ . "\\compiler\\node\\IfCompiler");
         $aNodeCompiler->addSubCompiler('else', __NAMESPACE__ . "\\compiler\\node\\ElseCompiler");
         $aNodeCompiler->addSubCompiler('if:else', __NAMESPACE__ . "\\compiler\\node\\ElseCompiler");
         $aNodeCompiler->addSubCompiler('elseif', __NAMESPACE__ . "\\compiler\\node\\ElseIfCompiler");
         //for
         $aNodeCompiler->addSubCompiler('for', __NAMESPACE__ . "\\compiler\\node\\LoopCompiler");
         $aNodeCompiler->addSubCompiler('loop', __NAMESPACE__ . "\\compiler\\node\\LoopCompiler");
         //foreach
         $aNodeCompiler->addSubCompiler('foreach', __NAMESPACE__ . "\\compiler\\node\\ForeachCompiler");
         //loopelse
         $aNodeCompiler->addSubCompiler('foreach:else', __NAMESPACE__ . "\\compiler\\node\\LoopelseCompiler");
         $aNodeCompiler->addSubCompiler('while:else', __NAMESPACE__ . "\\compiler\\node\\LoopelseCompiler");
         $aNodeCompiler->addSubCompiler('dowhile:else', __NAMESPACE__ . "\\compiler\\node\\LoopelseCompiler");
         $aNodeCompiler->addSubCompiler('do:else', __NAMESPACE__ . "\\compiler\\node\\LoopelseCompiler");
         $aNodeCompiler->addSubCompiler('loop:else', __NAMESPACE__ . "\\compiler\\node\\LoopelseCompiler");
         //while
         $aNodeCompiler->addSubCompiler('while', __NAMESPACE__ . "\\compiler\\node\\WhileCompiler");
         $aNodeCompiler->addSubCompiler('dowhile', __NAMESPACE__ . "\\compiler\\node\\DoWhileCompiler");
         $aNodeCompiler->addSubCompiler('do', __NAMESPACE__ . "\\compiler\\node\\DoWhileCompiler");
         //ends
         $aNodeCompiler->addSubCompiler('struct:end', __NAMESPACE__ . "\\compiler\\node\\StructEndCompiler");
         $aNodeCompiler->addSubCompiler('if:end', __NAMESPACE__ . "\\compiler\\node\\StructEndCompiler");
         $aNodeCompiler->addSubCompiler('loop:end', __NAMESPACE__ . "\\compiler\\node\\LoopEndCompiler");
         $aNodeCompiler->addSubCompiler('while:end', __NAMESPACE__ . "\\compiler\\node\\LoopEndCompiler");
         $aNodeCompiler->addSubCompiler('dowhile:end', __NAMESPACE__ . "\\compiler\\node\\LoopEndCompiler");
         $aNodeCompiler->addSubCompiler('foreach:end', __NAMESPACE__ . "\\compiler\\node\\LoopEndCompiler");
         //others
         $aNodeCompiler->addSubCompiler('include', __NAMESPACE__ . "\\compiler\\node\\IncludeCompiler");
         $aNodeCompiler->addSubCompiler('function', __NAMESPACE__ . "\\compiler\\node\\FunctionCompiler");
         $aNodeCompiler->addSubCompiler('continue', __NAMESPACE__ . "\\compiler\\node\\ContinueCompiler");
         $aNodeCompiler->addSubCompiler('break', __NAMESPACE__ . "\\compiler\\node\\BreakCompiler");
         $aNodeCompiler->addSubCompiler('script', __NAMESPACE__ . "\\compiler\\node\\ScriptCompiler");
         $aNodeCompiler->addSubCompiler('resrc', __NAMESPACE__ . "\\compiler\\node\\LoadResourceCompiler");
         $aNodeCompiler->addSubCompiler('link', __NAMESPACE__ . "\\compiler\\node\\CssCompiler");
         $aNodeCompiler->addSubCompiler('css', __NAMESPACE__ . "\\compiler\\node\\CssCompiler");
         $aNodeCompiler->addSubCompiler('js', __NAMESPACE__ . "\\compiler\\node\\ScriptCompiler");
         $aNodeCompiler->addSubCompiler('subtemplate', __NAMESPACE__ . "\\compiler\\node\\SubTemplateDefineCompiler");
         $aNodeCompiler->addSubCompiler('subtemplate:define', __NAMESPACE__ . "\\compiler\\node\\SubTemplateDefineCompiler");
         $aNodeCompiler->addSubCompiler('subtemplate:call', __NAMESPACE__ . "\\compiler\\node\\SubTemplateCallCompiler");
         $aNodeCompiler->addSubCompiler('template', __NAMESPACE__ . "\\compiler\\node\\SubTemplateDefineCompiler");
         $aNodeCompiler->addSubCompiler('nl', __NAMESPACE__ . "\\compiler\\node\\NlCompiler");
         $aNodeCompiler->addSubCompiler('clear', __NAMESPACE__ . "\\compiler\\node\\ClearCompiler");
         $aNodeCompiler->addSubCompiler('code', __NAMESPACE__ . "\\compiler\\node\\CodeCompiler");
         $aNodeCompiler->addSubCompiler('render:js', __NAMESPACE__ . "\\compiler\\node\\RenderJsCompiler");
     }
     return $aNodeCompiler;
 }
 public function compile(IObject $aObject, ObjectContainer $aObjectContainer, TargetCodeOutputStream $aDev, CompilerManager $aCompilerManager)
 {
     Assert::type("org\\jecat\\framework\\ui\\xhtml\\Node", $aObject, 'aObject');
     // 使用 <msgqueue> 节点内部的模板内容
     if ($aTemplate = $aObject->getChildNodeByTagName('template')) {
         $sOldMsgQueueVarVarName = '$' . parent::assignVariableName('_aOldMsgQueueVar');
         $aDev->write("\t{$sOldMsgQueueVarVarName}=\$aVariables->get('aMsgQueue') ;");
         $aDev->write("\t\$aVariables->set('aMsgQueue',\$aVariables->get('theView')->messageQueue()) ;");
         $this->compileChildren($aTemplate, $aObjectContainer, $aDev, $aCompilerManager);
         $aDev->write("\t\$aVariables->set('aMsgQueue',{$sOldMsgQueueVarVarName}) ;");
     } else {
         $aDev->write("if( \$aVariables->get('theView')->messageQueue()->count() ){ \r\n");
         $aDev->write("\t\$aVariables->get('theView')->messageQueue()->display(\$this,\$aDevice) ;\r\n");
         $aDev->write("}\r\n");
     }
 }
Beispiel #5
0
 public function compile(IObject $aObject, ObjectContainer $aObjectContainer, TargetCodeOutputStream $aDev, CompilerManager $aCompilerManager)
 {
     Type::check("org\\jecat\\framework\\ui\\xhtml\\Node", $aObject);
     if (!$aObjectContainer->variableDeclares()->hasDeclared('aStackForLoopIsEnableToRun')) {
         $aObjectContainer->variableDeclares()->declareVarible('aStackForLoopIsEnableToRun', 'new \\org\\jecat\\framework\\util\\Stack()');
     }
     $sIdxUserName = $aObject->attributes()->has('idx') ? $aObject->attributes()->get('idx') : '';
     $sIdxAutoName = NodeCompiler::assignVariableName('$__dowhile_idx_');
     if (!empty($sIdxUserName)) {
         $aDev->write(" {$sIdxAutoName} = -1; \$aStackForLoopIsEnableToRun->put(false);");
     }
     $aDev->write(" do{ \$bLoopIsEnableToRun = & \$aStackForLoopIsEnableToRun->getRef();\r\n\t\t\t\$bLoopIsEnableToRun = true;");
     if (!empty($sIdxUserName)) {
         $aDev->write(" {$sIdxAutoName}++; \r\n\t\t\t\t\t\t\t\$aVariables[{$sIdxUserName}]={$sIdxAutoName}; ");
     }
     $this->compileChildren($aObject, $aObjectContainer, $aDev, $aCompilerManager);
     $aDev->write(" }while(");
     $aDev->write(ExpressionCompiler::compileExpression($aObject->attributes()->anonymous()->source(), $aObjectContainer->variableDeclares()));
     $aDev->write(");");
 }
Beispiel #6
0
 public function compile(IObject $aObject, TargetCodeOutputStream $aDev, CompilerManager $aCompilerManager)
 {
     $sSource = $aObject->source();
     //如果开头是变量
     if (substr($sSource, 0, 1) === '$') {
         //分辨是定义还是调用
         if ($nEqual = stripos($sSource, '=') and strlen(substr($sSource, $nEqual)) > 0) {
             //这是定义
             $sObjName = '$' . substr($sSource, 1, $nEqual - 1);
             $arrStrings = $this->getElementsBySource(substr($sSource, $nEqual + 1));
             $sArrName = '$' . NodeCompiler::assignVariableName('arrChangByLoopIndex');
             $aDev->write("{$sArrName} = " . var_export($arrStrings, true) . ";\n\t\t\t\t\t\t\t\tif(!isset({$sObjName}))\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t{$sObjName} = new org\\jecat\\framework\\ui\\xhtml\\compiler\\macro\\Cycle({$sArrName});\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\$aVariables->set( '" . substr($sObjName, 1) . "' , {$sObjName} ) ;\n\t\t\t\t\t\t\t\t");
         } else {
             //这是调用
             $sObjName = '$' . substr($sSource, 1);
             $aDev->write("\n\t\t\t\t\t\t\t\tif(isset({$sObjName}))\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t{$sObjName}->printArr(\$aDevice);\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t");
         }
     } else {
         $sArrName = '$' . NodeCompiler::assignVariableName('arrChangByLoopIndex');
         $sObjName = '$' . NodeCompiler::assignVariableName('aStrChangByLoopIndex');
         $aDev->write("{$sArrName} = " . var_export($this->getElementsBySource($sSource), true) . ";\n\t\t\t\tif(!isset({$sObjName}))\n\t\t\t\t{\n\t\t\t\t\t{$sObjName} = new org\\jecat\\framework\\ui\\xhtml\\compiler\\macro\\Cycle({$sArrName});\n\t\t\t\t}\n\t\t\t\t{$sObjName}->printArr(\$aDevice);\n\t\t\t\t\$aVariables->set( '" . substr($sObjName, 1) . "' ,{$sObjName} ) ;\n\t\t\t");
     }
 }
Beispiel #7
0
 public function compile(IObject $aObject, ObjectContainer $aObjectContainer, TargetCodeOutputStream $aDev, CompilerManager $aCompilerManager)
 {
     Type::check("org\\jecat\\framework\\ui\\xhtml\\Node", $aObject);
     $aAttrs = $aObject->attributes();
     $sType = strtolower($aAttrs->string('type'));
     if (in_array($sType, array('text/php', 'php'))) {
         foreach ($aObject->iterator() as $aChild) {
             if ($aChild instanceof AttributeValue) {
                 continue;
             }
             $aDev->write(ExpressionCompiler::compileExpression($aChild->source(), $aObjectContainer->variableDeclares(), false, true));
         }
     } else {
         if ($aAttrs->has('src') and !$aAttrs->bool('ignore')) {
             $sSrc = $aAttrs->get('src');
             $aDev->preprocessStream()->write("\\org\\jecat\\framework\\resrc\\HtmlResourcePool::singleton()->addRequire({$sSrc},\\org\\jecat\\framework\\resrc\\HtmlResourcePool::RESRC_JS) ;");
             // 清除后文中的空白字符
             ClearCompiler::clearAfterWhitespace($aObject);
         } else {
             parent::compile($aObject, $aObjectContainer, $aDev, $aCompilerManager);
         }
     }
 }
Beispiel #8
0
 public function compile(IObject $aObject, ObjectContainer $aObjectContainer, TargetCodeOutputStream $aDev, CompilerManager $aCompilerManager)
 {
     Assert::type("org\\jecat\\framework\\ui\\xhtml\\Node", $aObject, 'aObject');
     if (!$aObjectContainer->variableDeclares()->hasDeclared('aStackForLoopIsEnableToRun')) {
         $aObjectContainer->variableDeclares()->declareVarible('aStackForLoopIsEnableToRun', 'new \\org\\jecat\\framework\\util\\Stack()');
     }
     $aAttrs = $aObject->attributes();
     $sStartValue = $aAttrs->has("start") ? $aAttrs->expression("start") : '0';
     $sEndValue = $aAttrs->expression("end");
     $sStepValue = $aAttrs->has("step") ? $aAttrs->expression("step") : '1';
     $sVarAutoName = NodeCompiler::assignVariableName('$__loop_var_');
     $sIdxAutoName = NodeCompiler::assignVariableName('$__loop_idx_');
     $sEndName = NodeCompiler::assignVariableName('$__loop_end_');
     $sStepName = NodeCompiler::assignVariableName('$__loop_step_');
     $aDev->write("\t\t{$sEndName}  = {$sEndValue} ; \n\t\t\t\t\t\t\t\t{$sStepName}  = {$sStepValue}  ;\n\t\t\t\t\t\t\t\t{$sIdxAutoName} = 0;\n\t\t\t\t\t\t\t\t\$aStackForLoopIsEnableToRun->put(false);\n\t\t\t\t\t\t\t\tfor( {$sVarAutoName} = {$sStartValue} ; {$sVarAutoName} <= {$sEndName} ; {$sVarAutoName} += {$sStepName} ){\n\t\t\t\t\t\t\t\t\$bLoopIsEnableToRun = & \$aStackForLoopIsEnableToRun->getRef();\n\t\t\t\t\t\t\t\t\$bLoopIsEnableToRun = true;  \n\t\t\t\t\t\t");
     if ($aAttrs->has("var")) {
         $sVarUserName = $aAttrs->string("var");
         $aDev->write("\t\t\t\$aVariables->{$sVarUserName} = {$sVarAutoName} ;");
     }
     if ($aAttrs->has("idx")) {
         $sIdxUserName = $aAttrs->string("idx");
         $aDev->write("\t\t\t\$aVariables->{$sIdxUserName} = {$sIdxAutoName} ;\n\t\t\t\t\t\t\t\t\t\t{$sIdxAutoName}++;");
     }
     // 		$aDev->write ( "\$bLoopIsEnableToRun = & \$aStackForLoopIsEnableToRun->getRef();
     // 			\$bLoopIsEnableToRun = true;" );
     if (!$aObject->headTag()->isSingle()) {
         $this->compileChildren($aObject, $aObjectContainer, $aDev, $aCompilerManager);
         $aDev->write('} ');
     }
 }
Beispiel #9
0
 public function compile(IObject $aObject, ObjectContainer $aObjectContainer, TargetCodeOutputStream $aDev, CompilerManager $aCompilerManager)
 {
     if (!$aObjectContainer->variableDeclares()->hasDeclared('aStackForLoopIsEnableToRun')) {
         $aObjectContainer->variableDeclares()->declareVarible('aStackForLoopIsEnableToRun', 'new \\org\\jecat\\framework\\util\\Stack()');
     }
     Type::check("org\\jecat\\framework\\ui\\xhtml\\Node", $aObject);
     $aAttrs = $aObject->attributes();
     if ($aAttrs->has('for')) {
         $sForUserExp = $aAttrs->expression('for');
     } else {
         throw new Exception("foreach tag can not run without 'for' attribute");
     }
     $sKeyUserName = $aAttrs->has('key') ? $aAttrs->get('key') : '';
     $sItemUserName = $aAttrs->has('item') ? $aAttrs->get('item') : '';
     $bItemRef = $aAttrs->has('item.ref') ? $aAttrs->bool('item.ref') : false;
     $sIdxUserName = $aAttrs->has('idx') ? $aAttrs->get('idx') : '';
     $sForAutoName = NodeCompiler::assignVariableName('$__foreach_Arr_');
     $sItemAutoName = NodeCompiler::assignVariableName('$__foreach_item_');
     $sKeyAutoName = NodeCompiler::assignVariableName('$__foreach_key_');
     $sIdxAutoName = NodeCompiler::assignVariableName('$__foreach_idx_');
     $sItemRef = $bItemRef ? '&' : '';
     $aDev->write("\r\n// foreach start ");
     $aDev->write("{$sForAutoName} = {$sForUserExp};\r\n\$aStackForLoopIsEnableToRun->put(false);\r\n{$sIdxAutoName} = -1;\r\nforeach({$sForAutoName} as {$sKeyAutoName}=>{$sItemRef}{$sItemAutoName}){");
     $aDev->write("\$bLoopIsEnableToRun = & \$aStackForLoopIsEnableToRun->getRef();\r\n\t\$bLoopIsEnableToRun = true;\r\n\t{$sIdxAutoName}++;");
     if (!empty($sKeyUserName)) {
         $aDev->write("\t\t\$aVariables[{$sKeyUserName}]={$sKeyAutoName}; ");
     }
     if (!empty($sItemUserName)) {
         $aDev->write("\t\t\$aVariables[{$sItemUserName}]={$sItemAutoName}; ");
     }
     if (!empty($sIdxUserName)) {
         $aDev->write("\t\t\$aVariables[{$sIdxUserName}]={$sIdxAutoName}; ");
     }
     //是否是单行标签?
     if (!$aObject->headTag()->isSingle()) {
         //循环体,可能会包含foreach:else标签
         $this->compileChildren($aObject, $aObjectContainer, $aDev, $aCompilerManager);
         $aDev->write("}\r\n");
         // end if   (如果foreach的内容包含foreach:else标签,则此处为foreach:else的end)
     }
 }
Beispiel #10
0
 protected function getVarName()
 {
     $sWidgetVarName = '$' . parent::assignVariableName('_aWidget');
     return $sWidgetVarName;
 }