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

List:       kde-commits
Subject:    branches/work/~zecke/findbugs (silent)
From:       Holger Freyther <freyther () gmx ! net>
Date:       2007-01-07 0:07:15
Message-ID: 1168128435.011193.2525.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 620677 by zecke:

SVN_SILENT Add special Comment tokens to the KDevelop lexer
to avoid getting confuses by ';' inside a comment

NOTE: The KDevelop C++ parser can do out of bounds memory
access. I have sadly three more such accesses and I will
fix them in one go..


 M  +7 -0      parser/ast.h  
 M  +22 -1     parser/lexer.cpp  
 M  +3 -0      parser/parser.cpp  
 M  +4 -1      parser/tokens.cpp  
 M  +4 -1      parser/tokens.h  
 M  +2 -1      parser/visitor.cpp  
 M  +1 -0      parser/visitor.h  
 A             test/comment3.h   [License: no copyright]
 A             test/crashit (directory)  
 A             test/crashit/crash1.h   [License: no copyright]
 A             test/crashit/crash2.h   [License: no copyright]
 A             test/crashit/crash3.h   [License: no copyright]


--- branches/work/~zecke/findbugs/parser/ast.h #620676:620677
@@ -38,6 +38,7 @@
 struct CastExpressionAST;
 struct ClassMemberAccessAST;
 struct ClassSpecifierAST;
+struct CommentAST;
 struct CompoundStatementAST;
 struct ConditionAST;
 struct ConditionalExpressionAST;
@@ -189,6 +190,7 @@
       Kind_UsingDirective,                      // 71
       Kind_WhileStatement,                      // 72
       Kind_WinDeclSpec,                         // 73
+      Kind_Comment,                             // 74
 
       NODE_KIND_COUNT
     };
@@ -301,6 +303,11 @@
   ExpressionAST *expression;
 };
 
+struct CommentAST : public AST
+{
+  DECLARE_AST_NODE(Comment);
+};
+
 struct ConditionalExpressionAST: public ExpressionAST
 {
   DECLARE_AST_NODE(ConditionalExpression)
--- branches/work/~zecke/findbugs/parser/lexer.cpp #620676:620677
@@ -23,7 +23,6 @@
 
 #include <cctype>
 
-#include <kdebug.h>
 
 scan_fun_ptr Lexer::s_scan_keyword_table[] = {
   &Lexer::scanKeyword0, &Lexer::scanKeyword0,
@@ -501,6 +500,9 @@
   /*
     '/'		::= divide
     '/='	::= divide_equal
+    'slash**'      ::= doc_comment
+    'slash*'       ::= comment
+    'slashslash'   ::= c99_comment
   */
 
   ++cursor;
@@ -510,6 +512,25 @@
       ++cursor;
       (*session->token_stream)[index++].kind = Token_assign;
     }
+  else if (*cursor == '/' )
+   {
+      ++cursor;
+      (*session->token_stream)[index++].kind = Token_comment_c99;
+      /* suck stuff until \n or \r */
+      while (*cursor != '\n' && *cursor != '\r' ) ++cursor;
+   }
+  else if (*cursor == '*' && *(cursor + 1) == '*' )
+   {
+      cursor += 2;
+      (*session->token_stream )[index++].kind = Token_comment_doc;
+      while (*cursor != '*' && *(cursor + 1) != '*' && *(cursor + 2 ) != '/' ) ++cursor;
+   }
+  else if (*cursor == '*' )
+   {
+      ++cursor;
+      (*session->token_stream)[index++].kind = Token_comment;
+      while (*cursor != '*' && *(cursor + 1 ) != '/' ) ++cursor;
+   }
   else
     {
       (*session->token_stream)[index++].kind = '/';
--- branches/work/~zecke/findbugs/parser/parser.cpp #620676:620677
@@ -289,6 +289,9 @@
         case Token_using:
           return true;
 
+        case Token_comment:
+        case Token_comment_doc:
+        case Token_comment_c99:
         default:
           session->token_stream->nextToken();
         }
--- branches/work/~zecke/findbugs/parser/tokens.cpp #620676:620677
@@ -122,7 +122,10 @@
   "while",
   "whitespaces",
   "xor",
-  "xor_eq"
+  "xor_eq",
+  "comment",
+  "doc comment",
+  "C99 comment"
 };
 
 static char _S_printable[][2] = {
--- branches/work/~zecke/findbugs/parser/tokens.h #620676:620677
@@ -45,7 +45,7 @@
     Token_char,
     Token_char_literal,
     Token_class,
-    Token_comment,
+    Token_comment_old, // old, unused, left there to not mess with possible numbers
     Token_compl,
     Token_concat,
     Token_const,
@@ -128,6 +128,9 @@
     Token_whitespaces,
     Token_xor,
     Token_xor_eq,
+    Token_comment, // a C comment '/*'
+    Token_comment_doc, // a doc comment '/**'
+    Token_comment_c99, // this C99 or C++ comment
 
     TOKEN_KIND_COUNT
 };
--- branches/work/~zecke/findbugs/parser/visitor.cpp #620676:620677
@@ -92,7 +92,8 @@
   reinterpret_cast<Visitor::visitor_fun_ptr>(&Visitor::visitUsing),
   reinterpret_cast<Visitor::visitor_fun_ptr>(&Visitor::visitUsingDirective),
   reinterpret_cast<Visitor::visitor_fun_ptr>(&Visitor::visitWhileStatement),
-  reinterpret_cast<Visitor::visitor_fun_ptr>(&Visitor::visitWinDeclSpec)
+  reinterpret_cast<Visitor::visitor_fun_ptr>(&Visitor::visitWinDeclSpec),
+  reinterpret_cast<Visitor::visitor_fun_ptr>(&Visitor::visitComment ),
 };
 
 Visitor::Visitor()
--- branches/work/~zecke/findbugs/parser/visitor.h #620676:620677
@@ -106,6 +106,7 @@
   virtual void visitUsingDirective(UsingDirectiveAST *) {}
   virtual void visitWhileStatement(WhileStatementAST *) {}
   virtual void visitWinDeclSpec(WinDeclSpecAST *) {}
+  virtual void visitComment(CommentAST *) {}
 
 private:
   typedef void (Visitor::*visitor_fun_ptr)(AST *);
[prev in list] [next in list] [prev in thread] [next in thread] 

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