[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    KDE/kdelibs/kjs
From:       Maks Orlovich <maksim () kde ! org>
Date:       2008-11-17 14:27:27
Message-ID: 1226932047.146481.10830.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 885599 by orlovich:

Backend for auto-reindent for debugging. Not hooked up yet 
as I need to clear up some things wrt to line numbers 
and on the GUI end


 M  +1 -1      nodes.cpp  
 M  +8 -3      nodes.h  
 M  +31 -1     nodes2string.cpp  


--- trunk/KDE/kdelibs/kjs/nodes.cpp #885598:885599
@@ -259,7 +259,7 @@
     m_line = -1;
 }
 
-void StatementNode::setLoc(int firstLine, int lastLine)
+void StatementNode::setLoc(int firstLine, int lastLine) const
 {
     m_line = firstLine;
     m_lastLine = lastLine;
--- trunk/KDE/kdelibs/kjs/nodes.h #885598:885599
@@ -89,6 +89,11 @@
     virtual NodeType type() const { return UnknownNodeType; }
 
     UString toString() const;
+    
+    // This updates line numbers to the pretty-printed version, and 
+    // returns it out.
+    UString reindent(int baseLine = 0) const;
+    
     virtual void streamTo(SourceStream&) const = 0;
     int lineNo() const { return m_line; }
 
@@ -152,7 +157,7 @@
 
     virtual OpValue generateEvalCode(CompileState* comp);
   protected:
-    int m_line;
+    mutable int m_line;
   private:
     virtual void processVarDecl (ExecState* state);
     virtual void processFuncDecl(ExecState* state);
@@ -194,7 +199,7 @@
   class StatementNode : public Node {
   public:
     StatementNode();
-    void setLoc(int line0, int line1);
+    void setLoc(int line0, int line1) const;
     int firstLine() const { return lineNo(); }
     int lastLine() const { return m_lastLine; }
     void hitStatement(ExecState*);
@@ -204,7 +209,7 @@
     virtual void generateExecCode(CompileState*);
   private:
     void generateDebugInfo(CompileState* comp);
-    int m_lastLine;
+    mutable int m_lastLine;
   };
 
   inline void StatementNode::generateDebugInfoIfNeeded(CompileState* comp)
--- trunk/KDE/kdelibs/kjs/nodes2string.cpp #885598:885599
@@ -60,7 +60,7 @@
 
     static const int kBufSize = 2048;
     typedef unsigned short UTF16;
-    SourceStream () : indent(0), bufUsed(0) {}
+    SourceStream () : indent(0), bufUsed(0), reindentLine(0), reindenting(false) {}
     const UString& toString() { flush(); return str; }
     SourceStream& operator<<(const Identifier& s) NOINLINE;
     SourceStream& operator<<(const UString& s) NOINLINE;
@@ -68,6 +68,7 @@
     SourceStream& operator<<(char s) NOINLINE;
     SourceStream& operator<<(eEndl) NOINLINE;
     SourceStream& operator<<(const Node* n) NOINLINE;
+    SourceStream& operator<<(const StatementNode* n) NOINLINE;
     SourceStream& operator<<(Operator op) NOINLINE;
     inline SourceStream& operator<<(eIndent)    { indent += 2; return *this; }
     inline SourceStream& operator<<(eUnindent)  { indent -= 2; return *this; }
@@ -77,6 +78,8 @@
     SourceStream& append(const UString& inStr, bool quote) NOINLINE;
     template <typename T>
     inline SourceStream& operator<<(const RefPtr<T>& n) { return this->operator<<(n.get()); }
+    
+    void setReindenting(int baseLine) { reindenting = true; reindentLine = baseLine; }
   private:
     UString str;
     int indent;
@@ -85,6 +88,9 @@
     void flush() NOINLINE;
     void put(UTF16 ch) { buffer[bufUsed++] = ch; }
     void put(char ch) { buffer[bufUsed++] = static_cast<unsigned char>(ch); }
+    
+    int  reindentLine;
+    bool reindenting;
   };
 }
 
@@ -139,6 +145,19 @@
   return append(s.ustring(), kDontQuote);
 }
 
+SourceStream& SourceStream::operator<<(const StatementNode *n)
+{
+  if (n) {
+    // Update debug info with new line numbers if needed.
+    int firstLine = reindentLine;
+    n->streamTo(*this);
+    if (reindenting)
+      n->setLoc(firstLine, reindentLine - 1);
+  }
+  return *this;
+}
+
+
 SourceStream& SourceStream::operator<<(const Node *n)
 {
   if (n)
@@ -151,6 +170,7 @@
   if (bufUsed > kBufSize - 1 - indent)
     flush();
   put('\n');
+  ++reindentLine;
 
   if (indent > 0)
   {
@@ -257,6 +277,16 @@
   return str.toString();
 }
 
+UString Node::reindent(int baseLine) const
+{
+  SourceStream str;
+  str.setReindenting(baseLine);
+  
+  streamTo(str);
+
+  return str.toString();
+}
+
 void NullNode::streamTo(SourceStream &s) const { s << "null"; }
 
 void BooleanNode::streamTo(SourceStream &s) const
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic