tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Eric Carmichael" <ecarm...@alumni.rice.edu>
Subject Re: cvs commit: jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler Generator.java Node.java SmapStratum.java SmapUtil.java
Date Sat, 20 Sep 2003 07:18:14 GMT
cal/cal1.jsp from the jsp-examples webapp starts like this:

<HTML>
<!-- 
  Copyright (c) 1999 The Apache Software Foundation. All rights 
  reserved.
-->
<HEAD><TITLE> 

Before this commit, cal1.jsp's SMAP started like this:

*L
1,2:41
3:42
4:42
5:42
6:43,2

Now it starts like this:

*L
1,2:41
6:43,2

I think the reason lines 3, 4, and 5 aren't being SMAPped is that you only add LineInfos inside
"if (breakAtLF || count < 0) {".  This adds LineInfos when the output line advances, but
not when the input line alone advances.  To SMAP template text fully, you have to add a LineInfo
every time the line number advances in the input file or the output file.

Eric


----- Original Message ----- 
From: <kinman@apache.org>
To: <jakarta-tomcat-jasper-cvs@apache.org>
Sent: Tuesday, September 16, 2003 10:46 AM
Subject: cvs commit: jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler Generator.java
Node.java SmapStratum.java SmapUtil.java


> kinman      2003/09/16 10:46:44
> 
>   Modified:    jasper2/src/share/org/apache/jasper/compiler Generator.java
>                         Node.java SmapStratum.java SmapUtil.java
>   Log:
>   - For template texts that generate multiple Java lines, addidtional mapping
>     informantion are kept in the TemplateText node, to aide SMAP generation.
>   
>   Revision  Changes    Path
>   1.208     +23 -14    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.207
>   retrieving revision 1.208
>   diff -u -r1.207 -r1.208
>   --- Generator.java 15 Sep 2003 13:43:54 -0000 1.207
>   +++ Generator.java 16 Sep 2003 17:46:43 -0000 1.208
>   @@ -1867,21 +1867,25 @@
>                    return;
>                }
>    
>   -            if (ctxt.getOptions().genStringAsCharArray()) {
>   -                if (textSize <= 3) {
>   -                   // Spcial case small text strings
>   -                   n.setBeginJavaLine(out.getJavaLine());
>   -                   out.printil("out.write(" + quote(text.charAt(0)) + ");");
>   -                   if (textSize > 1) {
>   -                       out.printil("out.write(" + quote(text.charAt(1)) + ");");
>   +            if (textSize <= 3) {
>   +               // Special case small text strings
>   +               n.setBeginJavaLine(out.getJavaLine());
>   +               int lineInc = 0;
>   +               for (int i = 0; i < textSize; i++) {
>   +                   char ch = text.charAt(i);
>   +                   out.printil("out.write(" + quote(ch) + ");");
>   +                   if (i > 0) {
>   +                       n.addSmap(lineInc);
>                       }
>   -                   if (textSize > 2) {
>   -                       out.printil("out.write(" + quote(text.charAt(2)) + ");");
>   +                   if (ch == '\n') {
>   +                       lineInc++;
>                       }
>   -                   n.setEndJavaLine(out.getJavaLine());
>   -                   return;
>                   }
>   +               n.setEndJavaLine(out.getJavaLine());
>   +               return;
>   +           }
>    
>   +            if (ctxt.getOptions().genStringAsCharArray()) {
>                   // Generate Strings as char arrays, for performance
>                    ServletWriter caOut;
>                    if (charArrayBuffer == null) {
>   @@ -1915,6 +1919,7 @@
>                StringBuffer sb = new StringBuffer("out.write(\"");
>                int initLength = sb.length();
>                int count = JspUtil.CHUNKSIZE;
>   +            int srcLine = 0; // relative to starting srouce line
>                for (int i = 0; i < text.length(); i++) {
>                    char ch = text.charAt(i);
>                    --count;
>   @@ -1930,6 +1935,7 @@
>                            break;
>                        case '\n' :
>                            sb.append('\\').append('n');
>   +                        srcLine++;
>    
>                            if (breakAtLF || count < 0) {
>                                // Generate an out.write() when see a '\n' in template
>   @@ -1940,6 +1946,9 @@
>                                }
>                                sb.setLength(initLength);
>                                count = JspUtil.CHUNKSIZE;
>   +
>   +                            // add a Smap for this line
>   +                            n.addSmap(srcLine);
>                            }
>                            break;
>                        case '\t' : // Not sure we need this
>   
>   
>   
>   1.77      +24 -4     jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/Node.java
>   
>   Index: Node.java
>   ===================================================================
>   RCS file: /home/cvs/jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/Node.java,v
>   retrieving revision 1.76
>   retrieving revision 1.77
>   diff -u -r1.76 -r1.77
>   --- Node.java 2 Sep 2003 21:39:59 -0000 1.76
>   +++ Node.java 16 Sep 2003 17:46:43 -0000 1.77
>   @@ -63,6 +63,7 @@
>    import java.util.Iterator;
>    import java.util.List;
>    import java.util.Vector;
>   +import java.util.ArrayList;
>    
>    import javax.servlet.jsp.tagext.BodyTag;
>    import javax.servlet.jsp.tagext.DynamicAttributes;
>   @@ -1921,6 +1922,8 @@
>         */
>        public static class TemplateText extends Node {
>    
>   +        private ArrayList extraSmap = null;
>   +
>    public TemplateText(String text, Mark start, Node parent) {
>        super(null, null, text, start, parent);
>    }
>   @@ -1957,13 +1960,30 @@
>    public boolean isAllSpace() {
>        boolean isAllSpace = true;
>        for (int i=0; i<text.length(); i++) {
>   - if (!Character.isSpace(text.charAt(i))) {
>   + if (!Character.isWhitespace(text.charAt(i))) {
>        isAllSpace = false;
>        break;
>    }
>        }
>        return isAllSpace;
>    }
>   +
>   +        /**
>   +         * Add a source to Java line mapping
>   +         * @param srcLine The postion of the source line, relative to the line
>   +         *        at the start of this node.  The corresponding java line is
>   +         *        assumed to be consecutive, i.e. one more than the last.
>   +         */
>   +        public void addSmap(int srcLine) {
>   +            if (extraSmap == null) {
>   +                extraSmap = new ArrayList();
>   +            }
>   +            extraSmap.add(new Integer(srcLine));
>   +        }
>   +
>   +        public ArrayList getExtraSmap() {
>   +            return extraSmap;
>   +        }
>        }
>    
>        /*********************************************************************
>   
>   
>   
>   1.11      +6 -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.10
>   retrieving revision 1.11
>   diff -u -r1.10 -r1.11
>   --- SmapStratum.java 31 Aug 2003 03:46:29 -0000 1.10
>   +++ SmapStratum.java 16 Sep 2003 17:46:43 -0000 1.11
>   @@ -210,6 +210,12 @@
>         */
>        public void optimizeLineSection() {
>    
>   +/* Some debugging code
>   +        for (int i = 0; i < lineData.size(); i++) {
>   +            LineInfo li = (LineInfo)lineData.get(i);
>   +            System.out.print(li.toString());
>   +        }
>   +*/
>            //Incorporate each LineInfo into the previous LineInfo's 
>            //outputLineIncrement, if possible
>            int i = 0;
>   
>   
>   
>   1.19      +8 -16     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.18
>   retrieving revision 1.19
>   diff -u -r1.18 -r1.19
>   --- SmapUtil.java 25 Aug 2003 03:58:48 -0000 1.18
>   +++ SmapUtil.java 16 Sep 2003 17:46:43 -0000 1.19
>   @@ -77,6 +77,7 @@
>     * @author Shawn Bayern
>     * @author Robert Field (inner SDEInstaller class)
>     * @author Mark Roth
>   + * @author Kin-man Chung
>     */
>    public class SmapUtil {
>    
>   @@ -613,25 +614,16 @@
>                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;
>   -                    }
>   +            // Output additional mappings in the text
>   +            java.util.ArrayList extraSmap = n.getExtraSmap();
>   +
>   +            if (extraSmap != null) {
>   +                for (int i = 0; i < extraSmap.size(); i++) {
>                        smap.addLineData(
>   -                        iInputStartLine,
>   +                        iInputStartLine+((Integer)extraSmap.get(i)).intValue(),
>                            fileName,
>                            1,
>   -                        iOutputStartLine,
>   +                        ++iOutputStartLine,
>                            1);
>                    }
>                }
>   
>   
>   
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tomcat-dev-help@jakarta.apache.org
> 
> 
Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message