tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From r...@apache.org
Subject cvs commit: jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler Generator.java JspUtil.java SmapStratum.java SmapUtil.java
Date Sat, 09 Aug 2003 19:19:37 GMT
remm        2003/08/09 12:19:37

  Modified:    jasper2/src/share/org/apache/jasper/compiler Generator.java
                        JspUtil.java SmapStratum.java SmapUtil.java
  Log:
  - Bug 2006: Invalid SMAP line entries when running with mappedfile=true.
  - Submitted by Eric Carmichael (like the previous patch).
  
  Revision  Changes    Path
  1.194     +5 -7      jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/Generator.java
  
  Index: Generator.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/Generator.java,v
  retrieving revision 1.193
  retrieving revision 1.194
  diff -u -r1.193 -r1.194
  --- Generator.java	3 Aug 2003 09:07:47 -0000	1.193
  +++ Generator.java	9 Aug 2003 19:19:37 -0000	1.194
  @@ -1700,8 +1700,6 @@
   	    }
   	}
   
  -	private static final int CHUNKSIZE = 1024;
  -
   	public void visit(Node.TemplateText n) throws JasperException {
   
   	    String text = n.getText();
  @@ -1711,7 +1709,7 @@
   	    out.printin();
   	    StringBuffer sb = new StringBuffer("out.write(\"");
   	    int initLength = sb.length();
  -	    int count = CHUNKSIZE;
  +	    int count = JspUtil.CHUNKSIZE;
   	    for (int i = 0 ; i < text.length() ; i++) {
   		char ch = text.charAt(i);
   		--count;
  @@ -1736,7 +1734,7 @@
                               out.printin();
                           }
   			sb.setLength(initLength);
  -			count = CHUNKSIZE;
  +			count = JspUtil.CHUNKSIZE;
   		    }
   		    break;
   		case '\t':	// Not sure we need this
  
  
  
  1.42      +5 -3      jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/JspUtil.java
  
  Index: JspUtil.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/JspUtil.java,v
  retrieving revision 1.41
  retrieving revision 1.42
  diff -u -r1.41 -r1.42
  --- JspUtil.java	8 Aug 2003 10:22:23 -0000	1.41
  +++ JspUtil.java	9 Aug 2003 19:19:37 -0000	1.42
  @@ -117,6 +117,8 @@
           "this", "throws", "transient", "try", "void",
           "volatile", "while" };
   
  +    public static final int CHUNKSIZE = 1024;
  +        
       public static char[] removeQuotes(char []chars) {
           CharArrayWriter caw = new CharArrayWriter();
           for (int i = 0; i < chars.length; i++) {
  
  
  
  1.6       +38 -0     jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/SmapStratum.java
  
  Index: SmapStratum.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/SmapStratum.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- SmapStratum.java	31 Jul 2003 16:56:20 -0000	1.5
  +++ SmapStratum.java	9 Aug 2003 19:19:37 -0000	1.6
  @@ -205,6 +205,44 @@
       }
    
       /**
  +     * Combines consecutive LineInfos wherever possible
  +     */
  +    public void optimizeLineSection() {
  +        
  +        //Incorporate each LineInfo into the previous LineInfo's 
  +        //outputLineIncrement, if possible
  +        int i=0;
  +        while (i < lineData.size()-1) {
  +            LineInfo li = (LineInfo)lineData.get(i);
  +            LineInfo liNext = (LineInfo)lineData.get(i+1);
  +            if (liNext.inputStartLine == li.inputStartLine
  +             && liNext.inputLineCount==1
  +              && li.inputLineCount==1) {
  +                li.setOutputLineIncrement(liNext.outputStartLine - li.outputStartLine +
liNext.outputLineIncrement);
  +                lineData.remove(i+1);
  +            } else {
  +                i++; 
  +            }
  +        }
  +        
  +        //Incorporate each LineInfo into the previous LineInfo's
  +        //inputLineCount, if possible
  +        i=0;
  +        while (i < lineData.size()-1) {
  +            LineInfo li = (LineInfo)lineData.get(i);
  +            LineInfo liNext = (LineInfo)lineData.get(i+1);
  +            if (liNext.inputStartLine == li.inputStartLine + li.inputLineCount
  +             && liNext.outputLineIncrement == li.outputLineIncrement
  +              && liNext.outputStartLine == li.outputStartLine + li.inputLineCount*li.outputLineIncrement)
{
  +                  li.setInputLineCount(li.inputLineCount + liNext.inputLineCount);
  +                  lineData.remove(i+1);
  +             } else {
  +                 i++;
  +             }
  +        }
  +    }
  +    
  +    /**
        * Adds complete information about a simple line mapping.  Specify
        * all the fields in this method; the back-end machinery takes care
        * of printing only those that are necessary in the final SMAP.
  
  
  
  1.16      +36 -13    jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/SmapUtil.java
  
  Index: SmapUtil.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/SmapUtil.java,v
  retrieving revision 1.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- SmapUtil.java	31 Jul 2003 16:56:20 -0000	1.15
  +++ SmapUtil.java	9 Aug 2003 19:19:37 -0000	1.16
  @@ -120,7 +120,7 @@
   
           g.setOutputFileName(unqualify(ctxt.getServletJavaFileName()));
           // Map out Node.Nodes
  -        evaluateNodes(pageNodes, s);
  +        evaluateNodes(pageNodes, s, ctxt.getOptions().getMappedFile());
           g.addStratum(s, true);
   
           if (ctxt.getOptions().isSmapDumped()) {
  @@ -482,19 +482,22 @@
           }
       }
   
  -    public static void evaluateNodes(Node.Nodes nodes, SmapStratum s) {
  +    public static void evaluateNodes(Node.Nodes nodes, SmapStratum s, boolean breakAtLF)
{
           try {
  -            nodes.visit(new SmapGenVisitor(s));
  +            nodes.visit(new SmapGenVisitor(s, breakAtLF));
           } catch (JasperException ex) {
   	}
  +        s.optimizeLineSection();
       }
   
       static class SmapGenVisitor extends Node.Visitor {
   
           private SmapStratum smap;
  +        private boolean breakAtLF;
   
  -        SmapGenVisitor(SmapStratum s) {
  +        SmapGenVisitor(SmapStratum s, boolean breakAtLF) {
               this.smap = s;
  +            this.breakAtLF = breakAtLF;
           }
   
           public void visit(Node.Declaration n) throws JasperException {
  @@ -579,16 +582,36 @@
           }
   
           public void visit(Node.TemplateText n) throws JasperException {
  -            // Skip smap there the text is all noise
  -            String text = n.getText();
  -            int i = 0;
  -            while (i < text.length()) {
  -                if (text.charAt(i) > ' ')
  -                    break;
  -                i++;
  +            Mark mark = n.getStart();
  +            if (mark == null) {
  +                return;
               }
  -            if (i < text.length()) {
  -                doSmap(n);
  +
  +            //Add the file information
  +            String fileName = mark.getFile();
  +            smap.addFile(unqualify(fileName), fileName);
  +            
  +            //Add a LineInfo that corresponds to the beginning of this node
  +            int iInputStartLine = mark.getLineNumber();
  +            int iOutputStartLine = n.getBeginJavaLine();
  +            smap.addLineData(iInputStartLine, fileName, 1, iOutputStartLine, 1);
  +            
  +            //Walk through the node text the same way Generator.java's 
  +            //visit(Node.TemplateText n) does.  Every time the 
  +            //line number advances in the input file or the output file, 
  +            //add a LineInfo with the new line numbers.
  +            String text = n.getText();
  +            int count = JspUtil.CHUNKSIZE;
  +            for (int i = 0 ; i < text.length()-1 ; i++) {
  +                --count;
  +                if (text.charAt(i) == '\n') {
  +                    iInputStartLine++;
  +                    if (breakAtLF || count < 0) {
  +                        iOutputStartLine++;
  +                        count = JspUtil.CHUNKSIZE;
  +                    }
  +                    smap.addLineData(iInputStartLine, fileName, 1, iOutputStartLine, 1);
  +                }
               }
           }
   
  
  
  

Mime
View raw message