[patch] misc cosmetic trivia and a question

Bernhard Fischer <[email protected]> Sun, 6 May 2007 22:29:02 +0200
Newsgroups gmane.comp.documentation.synopsis
Message-ID <[email protected]>
Hi,

Attached some misc trivial fallouts.

today  Bernhard  <..>
	* Cpp/ParserImpl.cc (parse): Document a bit and try to remove
	even  predefined macros.
	* Python/Object.hh (narrow): Add question.
	* Lexer.cc (process_directive): Raise a runtime-error as
	suggested in a comment.
	* SymbolTable/Scope.cc: include typeinfo needed for typeid.
	* Lexer.hh (is_letter, is_hexdigit): Silence warning about
	missing parenthesis.


Re: Cpp/ParserImpl.cc: consider echo '#include <features.h>' > i.c
$ synopsis -p C -D_GNU_SOURCE -D_LARGEFILE64_SOURCE -o /dev/null i.c
/usr/include/features.h(155): warning: #undef may not be used on this
predefined name: _LARGEFILE64_SOURCE
Traceback (most recent call last):
  File "/opt/synopsis-trunk/bin/synopsis", line 224, in ?
    main()
  File "/opt/synopsis-trunk/bin/synopsis", line 219, in main
    processor.process(AST.AST())
  File
"/opt/synopsis-trunk/lib/python2.4/site-packages/Synopsis/Processor.py",
line 160, in process
    return self.processors[0].process(ast, **my_kwds)
  File
"/opt/synopsis-trunk/lib/python2.4/site-packages/Synopsis/Parsers/C/Parser.py",
line 58, in process
    profile = self.profile)
  File
"/opt/synopsis-trunk/lib/python2.4/site-packages/Synopsis/Parsers/Cpp/__init__.py",
line 42, in process
    self.verbose, self.debug, self.profile)
TypeError: __init__() takes exactly 2 arguments (1 given)

(getting some meaningful backtrace out of this error is another problem
that is not of interrest for now).

I think that specifying remove_macro_definition(mymacro,true) should not
raise this warning. The default (false, don't remove even predefined
macros) sounds like the warning is in order. Thoughts?

_______________________________________________
Synopsis-devel mailing list
[email protected]
http://lists.fresco.org/cgi-bin/listinfo/synopsis-devel
synopsis-0.9.1-fallout-20070506-2200.diff (text/x-diff, 3.1 KB)
Index: synopsis-trunk/Synopsis/Parsers/Cpp/ParserImpl.cc
===================================================================
--- synopsis-trunk/Synopsis/Parsers/Cpp/ParserImpl.cc	(revision 1817)
+++ synopsis-trunk/Synopsis/Parsers/Cpp/ParserImpl.cc	(working copy)
@@ -150,9 +150,9 @@ PyObject *parse(PyObject *self, PyObject
 	  ctx.add_sysinclude_path(*i + 2);
 	}
 	else if (*(*i + 1) == 'D')
-	  ctx.add_macro_definition(*i + 2, true);
+	  ctx.add_macro_definition(*i + 2, /*is_predefined=*/true);
 	else if (*(*i + 1) == 'U')
-	  ctx.remove_macro_definition(*i + 2);
+	  ctx.remove_macro_definition(*i + 2, /*even_predefined=*/true);
 	else if (*(*i + 1) == 'i')
 	  includes.push_back(*i + 2);
       }
Index: synopsis-trunk/src/Synopsis/Python/Object.hh
===================================================================
--- synopsis-trunk/src/Synopsis/Python/Object.hh	(revision 1817)
+++ synopsis-trunk/src/Synopsis/Python/Object.hh	(working copy)
@@ -435,7 +435,7 @@ inline long Object::narrow(Object o) thr
 template <>
 inline bool Object::narrow(Object o) throw(Object::TypeError)
 {
-#if 0 //PYTHON_HAS_BOOL
+#if 0 //PYTHON_HAS_BOOL why not use this nowadays? 
   if (!PyBool_Check(o.my_impl)) throw TypeError("object not a boolean");
 #else
   if (!PyInt_Check(o.my_impl)) throw TypeError("object not an integer");
Index: synopsis-trunk/src/Synopsis/Lexer.cc
===================================================================
--- synopsis-trunk/src/Synopsis/Lexer.cc	(revision 1817)
+++ synopsis-trunk/src/Synopsis/Lexer.cc	(working copy)
@@ -299,7 +299,8 @@ void Lexer::process_directive()
       return;
     }
   }
-  else ; // FIXME: issue a parse error: no directive found.
+  else // issue a parse error: no directive found.
+   throw std::runtime_error("unclassifiable directive");
   while(c != '\n' && c != '\0') c = buffer_->get();
 }
 
Index: synopsis-trunk/src/Synopsis/SymbolTable/Scope.cc
===================================================================
--- synopsis-trunk/src/Synopsis/SymbolTable/Scope.cc	(revision 1817)
+++ synopsis-trunk/src/Synopsis/SymbolTable/Scope.cc	(working copy)
@@ -10,6 +10,7 @@
 #include <Synopsis/SymbolTable/Symbol.hh>
 #include <Synopsis/Trace.hh>
 #include <functional>
+#include <typeinfo>
 
 using namespace Synopsis;
 using namespace PTree;
Index: synopsis-trunk/src/Synopsis/Lexer.hh
===================================================================
--- synopsis-trunk/src/Synopsis/Lexer.hh	(revision 1817)
+++ synopsis-trunk/src/Synopsis/Lexer.hh	(working copy)
@@ -133,7 +133,7 @@ inline bool is_blank(char c)
 
 inline bool is_letter(char c)
 {
-  return 'A' <= c && c <= 'Z' || 'a' <= c && c <= 'z' || c == '_' || c == '$';
+  return ('A' <= c && c <= 'Z') || ('a' <= c && c <= 'z') || c == '_' || c == '$';
 }
 
 inline bool is_digit(char c){ return '0' <= c && c <= '9';}
@@ -144,7 +144,7 @@ inline bool is_eletter(char c){ return c
 
 inline bool is_hexdigit(char c)
 {
-  return is_digit(c) || 'A' <= c && c <= 'F' || 'a' <= c && c <= 'f';
+  return is_digit(c) || ('A' <= c && c <= 'F') || ('a' <= c && c <= 'f');
 }
 
 inline bool is_int_suffix(char c)