Package railo.transformer.bytecode

Examples of railo.transformer.bytecode.BodyBase


   
    comments(data);
 
    // body
    if(tlt.getHasBody()){
      Body body=new BodyBase();
      boolean wasSemiColon=statement(data,body,script.getContext());
      if(!wasSemiColon || !tlt.isBodyFree() || body.hasStatements())
        tag.setBody(body);
     
     
     
    }
View Full Code Here


  private final TryCatchFinally tryStatement(ExprData data) throws TemplateException {
    if(!data.cfml.forwardIfCurrent("try",'{') && !data.cfml.forwardIfCurrent("try ") && !data.cfml.forwardIfCurrent("try",'/'))
      return null;
    data.cfml.previous();

    Body body=new BodyBase();
    TryCatchFinally tryCatchFinally=new TryCatchFinally(body,data.cfml.getPosition(),null);
   
    statement(data,body,CTX_TRY);
    comments(data);
   
    // catches
    short catchCount=0;
    while(data.cfml.forwardIfCurrent("catch",'(')) {
      catchCount++;
      comments(data);
     
      // type
      int pos=data.cfml.getPos();
      Position line=data.cfml.getPosition();
      Expression name = null,type = null;
     
      StringBuffer sbType=new StringBuffer();
            String id;
            while(true) {
              id=identifier(data,false);
                if(id==null)break;
                sbType.append(id);
                data.cfml.removeSpace();
                if(!data.cfml.forwardIfCurrent('.'))break;
                sbType.append('.');
                data.cfml.removeSpace();
            }
       
           
      if(sbType.length()==0) {
          type=string(data);
          if(type==null)         
              throw new TemplateException(data.cfml,"a catch statement must begin with the throwing type (query, application ...).");
      }
      else {
        type=LitString.toExprString(sbType.toString());
      }
           
           
      //name = expression();
      comments(data);
     
      // name
      if(!data.cfml.isCurrent(')')) {
        name=expression(data);
      }
      else {
        data.cfml.setPos(pos);
        name=expression(data);
        type = LitString.toExprString( "any" );
      }
      comments(data);

            Body b=new BodyBase();
      try {
        tryCatchFinally.addCatch(type,name,b,line);
      }
      catch (BytecodeException e) {
        throw new TemplateException(data.cfml,e.getMessage());
View Full Code Here

   * @see railo.transformer.bytecode.statement.tag.TagBase#_writeOut(org.objectweb.asm.commons.GeneratorAdapter)
   */
  public void _writeOut(BytecodeContext bc) throws BytecodeException {
    GeneratorAdapter adapter = bc.getAdapter();
    adapter.visitLabel(begin);
    Body tryBody=new BodyBase();
    List<Tag> catches=new ArrayList<Tag>();
    Tag tmpFinal=null;

    tryBody.setParent(getBody().getParent());
   
    List<Statement> statements = getBody().getStatements();
    Statement stat;
    Tag tag;
    {
    Iterator<Statement> it = statements.iterator();
    while(it.hasNext()) {
      stat= it.next();
      if(stat instanceof Tag) {
        tag=(Tag) stat;
        if(tag.getTagLibTag().getTagClassName().equals("railo.runtime.tag.Catch"))  {
          catches.add(tag);
          continue;
        }
        else if(tag.getTagLibTag().getTagClassName().equals("railo.runtime.tag.Finally"))  {
          tmpFinal=tag;
          continue;
        }
      }
      tryBody.addStatement(stat);
    };
    }
    final Tag _finally=tmpFinal;
   
    // has no try body, if there is no try body, no catches are executed, only finally
    if(!tryBody.hasStatements()) {
     
      if(_finally!=null && _finally.getBody()!=null)_finally.getBody().writeOut(bc);
      return;
    }
    TryCatchFinallyVisitor tcfv=new TryCatchFinallyVisitor(new OnFinally() {
     
      public void writeOut(BytecodeContext bc) throws BytecodeException {
        /*GeneratorAdapter ga = bc.getAdapter();
        if(fcf!=null && fcf.getAfterFinalGOTOLabel()!=null)
          ASMUtil.visitLabel(ga,fcf.getFinalEntryLabel());
        */
        if(_finally!=null) {
         
          ExpressionUtil.visitLine(bc, _finally.getStart());
          _finally.getBody().writeOut(bc);
         
        }
        /*if(fcf!=null){
          Label l=fcf.getAfterFinalGOTOLabel();
          if(l!=null)ga.visitJumpInsn(Opcodes.GOTO, l);
        }*/
      }
    },getFlowControlFinal());
   
   
    // Try
    tcfv.visitTryBegin(bc);
      tryBody.writeOut(bc);
    int e=tcfv.visitTryEndCatchBeging(bc);
      // if(e instanceof railo.runtime.exp.Abort) throw e;
      Label abortEnd=new Label();
      adapter.loadLocal(e);
      // Abort.isAbort(t);
View Full Code Here

  public void _writeOut(BytecodeContext bc) throws BytecodeException {
    _writeOut(bc,Function.PAGE_TYPE_REGULAR);
  }

  public void _writeOut(BytecodeContext bc, int type) throws BytecodeException {
    Body functionBody = new BodyBase();
    Function func = createFunction(bc.getPage(),functionBody);
    func.setParent(getParent());

    List<Statement> statements = getBody().getStatements();
    Statement stat;
    Tag tag;
   
    // supress WS between cffunction and the last cfargument
    Tag last=null;
    if(bc.getSupressWSbeforeArg()){
      // check if there is a cfargument at all
      Iterator<Statement> it = statements.iterator();
      while (it.hasNext()) {
        stat = it.next();
        if (stat instanceof Tag) {
          tag = (Tag) stat;
          if (tag.getTagLibTag().getTagClassName().equals("railo.runtime.tag.Argument")) {
            last=tag;
          }
        }
      }
     
      // check if there are only literal WS printouts
      if(last!=null) {
        it = statements.iterator();
        while (it.hasNext()) {
          stat = it.next();
          if(stat==last) break;
         
          if(stat instanceof PrintOut){
            PrintOut po=(PrintOut) stat;
            Expression expr = po.getExpr();
            if(!(expr instanceof LitString) || !StringUtil.isWhiteSpace(((LitString)expr).getString())) {
              last=null;
              break;
            }
          }
        }
      }
    }
   
   
   
    Iterator<Statement> it = statements.iterator();
    boolean beforeLastArgument=last!=null;
    while (it.hasNext()) {
      stat = it.next();
      if(beforeLastArgument) {
        if(stat==last) {
          beforeLastArgument=false;
        }
        else if(stat instanceof PrintOut){
          PrintOut po=(PrintOut) stat;
          Expression expr = po.getExpr();
          if(expr instanceof LitString) {
            LitString ls=(LitString) expr;
            if(StringUtil.isWhiteSpace(ls.getString())) continue;
          }
        }
       
      }
      if (stat instanceof Tag) {
        tag = (Tag) stat;
        if (tag.getTagLibTag().getTagClassName().equals(
            "railo.runtime.tag.Argument")) {
          addArgument(func, tag);
          continue;
        }
      }
      functionBody.addStatement(stat);
    }
    func._writeOut(bc,type);

  }
View Full Code Here

//    TODO muss erlaubt sein
    if(data.cfml.forwardIfCurrent('>'))  {
      hasBody=tagLibTag.getHasBody();
    }
    else if(data.cfml.forwardIfCurrent('/','>')) {
      if(tagLibTag.getHasBody())tag.setBody(new BodyBase());
    }
    else {
      throw createTemplateException(data.cfml, "tag ["+tagLibTag.getFullName()+"] is not closed",tagLibTag);
    }
   

    // Body
    if(hasBody)  {

       
      // get Body
      if(tagLibTag.isTagDependent()) {
        // get TagDependentBodyTransformer
        TagDependentBodyTransformer tdbt=null;
        try {
          tdbt=tagLibTag.getBodyTransformer();
        } catch (TagLibException e) {
          throw new TemplateException(data.cfml,e);
        }
        if(tdbt==null) throw createTemplateException(data.cfml,"Tag dependent body Transformer is invalid for Tag ["+tagLibTag.getFullName()+"]",tagLibTag);
        tdbt.transform(data.page,this,data.ep,data.flibs,tag,tagLibTag,data.scriptTags,data.cfml,data.settings);
       
        //  get TagLib of end Tag
        if(!data.cfml.forwardIfCurrent("</")) {
          // MUST this is a patch, do a more proper implementation
          TemplateException te = new TemplateException(data.cfml,"invalid construct");
          if(tdbt instanceof CFMLScriptTransformer && ASMUtil.containsComponent(tag.getBody())) {
            throw new CFMLScriptTransformer.ComponentTemplateException(te);
          }
          throw te;
        }
       
        TagLib tagLibEnd=nameSpace(data);
        // same NameSpace
        if(!(tagLibEnd!=null && tagLibEnd.getNameSpaceAndSeparator().equals(tagLib.getNameSpaceAndSeparator())))
          throw new TemplateException(data.cfml,"invalid construct");
        // get end Tag
        String strNameEnd=identifier(data.cfml,true).toLowerCase();

        // not the same name Tag
        if(!strName.equals(strNameEnd)) {
          data.cfml.setPos(start);
          throw new TemplateException(data.cfml,"Start and End Tag has not the same Name ["+tagLib.getNameSpaceAndSeparator()+strName+"-"+tagLibEnd.getNameSpaceAndSeparator()+strNameEnd+"]");       
         }
         data.cfml.removeSpace();
         if(!data.cfml.forwardIfCurrent('>'))
           throw new TemplateException(data.cfml,"End Tag ["+tagLibEnd.getNameSpaceAndSeparator()+strNameEnd+"] not closed");
      }
      else {
        // get body of Tag
        BodyBase body=new BodyBase();
        body.setParent(tag);
        //tag.setBody(body);
          //parseExpression=(tagLibTag.getParseBody())?true:parseExpression;
        if(tagLibTag.getParseBody())parseExpression=true;
       
        while(true)  {
         
          // Load Expession Transformer from TagLib
          ExprTransformer transfomer=null;
          if(parseExpression) {
            try {
              transfomer = tagLibTag.getTagLib().getExprTransfomer();
            } catch (TagLibException e) {
              throw new TemplateException(data.cfml,e);
            }
          }
         

          // call body
         
            body(data,body,parseExpression,transfomer);
          
           
            // no End Tag
          if(data.cfml.isAfterLast()) {
             
            if(tagLibTag.isBodyReq()) {
                data.cfml.setPos(start);
              throw createTemplateException(data.cfml,"No matching end tag found for tag ["+tagLibTag.getFullName()+"]",tagLibTag);
            }
            body.moveStatmentsTo(parent);
            return executeEvaluator(data,tagLibTag, tag);
          }
         
          // Invalid Construct
          int posBeforeEndTag=data.cfml.getPos();
          if(!data.cfml.forwardIfCurrent('<','/'))
            throw createTemplateException(data.cfml,"Missing end tag for ["+tagLibTag.getFullName()+"]",tagLibTag);
         
          // get TagLib of end Tag
          int _start = data.cfml.getPos();
          TagLib tagLibEnd=nameSpace(data);
         
          // same NameSpace
          if(tagLibEnd!=null)  {
              String strNameEnd="";
              //railo.print.ln(data.cfml.getLine()+" - "+data.cfml.getColumn()+" - "+tagLibEnd.getNameSpaceAndSeperator()+".equals("+tagLib.getNameSpaceAndSeperator()+")");
              if(tagLibEnd.getNameSpaceAndSeparator().equals(tagLib.getNameSpaceAndSeparator())) {
                 
                // get end Tag
              strNameEnd=identifier(data.cfml,true).toLowerCase();
              // not the same name Tag
             
              // new part
              data.cfml.removeSpace();
              if(strName.equals(strNameEnd)) {
                  if(!data.cfml.forwardIfCurrent('>'))
                  throw new TemplateException(data.cfml,"End Tag ["+tagLibEnd.getNameSpaceAndSeparator()+strNameEnd+"] not closed");
                break;
              }
             
              }
              // new part
              if(tagLibTag.isBodyReq()) {
              TagLibTag endTag = tagLibEnd.getTag(strNameEnd);
              if(endTag!=null && !endTag.getHasBody())
                throw new TemplateException(data.cfml,
                    "End Tag ["+
                    tagLibEnd.getNameSpaceAndSeparator()+strNameEnd+"] is not allowed, for this tag only a Start Tag is allowed");
              data.cfml.setPos(start);
              if(tagLibEnd.getIgnoreUnknowTags() && (tagLibEnd.getTag(strNameEnd))==null){
                data.cfml.setPos(_start);
              }
              else throw new TemplateException(data.cfml,
                  "Start and End Tag has not the same Name ["+
                  tagLib.getNameSpaceAndSeparator()+strName+"-"+tagLibEnd.getNameSpaceAndSeparator()+strNameEnd+"]");
            }
              else {
              body.moveStatmentsTo(parent);
              data.cfml.setPos(posBeforeEndTag);
              return executeEvaluator(data,tagLibTag, tag);
              }
              /// new part 
          }
          body.addPrintOut("</",null,null);
         
        }
        tag.setBody(body);
       
      }
View Full Code Here

  /**
   * @see railo.transformer.bytecode.statement.tag.TagBase#getBody()
   */
  public Body getBody() {
    return new BodyBase();
  }
View Full Code Here

TOP

Related Classes of railo.transformer.bytecode.BodyBase

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.