kdevelop-pg needs a way to define an export macro

Andreas Pakulat apaku at gmx.de
Mon Jul 9 22:15:45 UTC 2007


On 07.07.07 23:38:43, Andreas Pakulat wrote:
> Hi,
> 
> There's a problem with using kdevelop-pg in that it doesn't allow to use
> the generated classes in shared libraries. And static libraries are not
> allowed and seemingly don't work in KDE4.
> 
> So I added KDEVPG_EXPORT macro's to the generated classes (which needs
> to be redefined in the using library to the proper export macro),
> however that doesn't allow to access the token stream class from
> outside. I tried to do that there as well, but as one can't tell it
> which header to include for the real EXPORT macro this doesn't work
> (unless you copy it, which I think should be avoided if possible).
> 
> So what other options do people(Jakob, Alex) see? 

Actually it seems this is not needed that much. Anyway, as I wanted a
way to declare a separate namespace (not using namespace for the
filename prefix) I played around with the export macro as well. Attached
is a diff that adds

--exportmacro=FOO
--exportheader=fooexport.h

options to the kdev-pg executable and generates proper files for this.
Just in case somebody needs this...

Andreas

-- 
Are you sure the back door is locked?
-------------- next part --------------
Index: kdev-pg-visitor-gen.cpp
===================================================================
--- kdev-pg-visitor-gen.cpp	(Revision 685856)
+++ kdev-pg-visitor-gen.cpp	(Arbeitskopie)
@@ -24,7 +24,10 @@
 
 void generate_visitor::operator()()
 {
-  out << "class visitor {" << std::endl
+  out << "class ";
+  if( _G_system.exportmacro && _G_system.exportheader )
+    out << _G_system.exportmacro;
+  out << " visitor {" << std::endl
       << "typedef void (visitor::*parser_fun_t)(ast_node *);" << std::endl
       << "static parser_fun_t _S_parser_table[];" << std::endl
       << std::endl
Index: kdev-pg.h
===================================================================
--- kdev-pg.h	(Revision 685856)
+++ kdev-pg.h	(Arbeitskopie)
@@ -85,7 +85,8 @@
   typedef std::map<model::node*, follow_dep> follow_deps;
 
   world()
-    : token_stream("kdev_pg_token_stream"), language(0), ns(0), decl(0), bits(0), 
+    : token_stream("kdev_pg_token_stream"), language(0), ns(0), decl(0), bits(0),
+      exportmacro(0),exportheader(0),
       generate_ast(true), gen_serialize_visitor(false), 
       gen_debug_visitor(false), need_state_management(false), 
       adapt_to_kdevelop(false), start(0), _M_zero(0)
@@ -97,6 +98,8 @@
   char const *ns;
   char const *decl;
   char const *bits;
+  char const *exportmacro;
+  char const *exportheader;
   bool generate_ast;
   bool gen_serialize_visitor;
   bool gen_debug_visitor;
Index: kdev-pg-serialize-visitor-gen.cpp
===================================================================
--- kdev-pg-serialize-visitor-gen.cpp	(Revision 685856)
+++ kdev-pg-serialize-visitor-gen.cpp	(Arbeitskopie)
@@ -25,7 +25,10 @@
 
 void generate_serialize_visitor::operator()()
 {
-  out << "class serialize: public default_visitor {" << std::endl
+  out << "class ";
+  if( _G_system.exportmacro && _G_system.exportheader )
+    out << _G_system.exportmacro;
+  out << " serialize: public default_visitor {" << std::endl
       << "public:" << std::endl;
 
   out << "static void read(kdev_pg_memory_pool *p," << std::endl
Index: kdev-pg-code-gen.cpp
===================================================================
--- kdev-pg-code-gen.cpp	(Revision 685856)
+++ kdev-pg-code-gen.cpp	(Arbeitskopie)
@@ -753,7 +753,10 @@
 
 void generate_parser_decls::operator()()
 {
-  out << "class parser {"
+  out << "class ";
+  if( _G_system.exportmacro && _G_system.exportheader )
+    out << _G_system.exportmacro;
+  out << " parser {"
       << "public:" << std::endl
       << "typedef " << _G_system.token_stream << " token_stream_type;" << std::endl
       << "typedef " << _G_system.token_stream << "::token_type token_type;" << std::endl
Index: kdev-pg-main.cpp
===================================================================
--- kdev-pg-main.cpp	(Revision 685856)
+++ kdev-pg-main.cpp	(Arbeitskopie)
@@ -114,6 +114,14 @@
         {
           _G_system.ns = arg + 12;
 	}
+      else if (!strncmp(arg,"--exportmacro=",14))
+        {
+          _G_system.exportmacro = arg + 14;
+	}
+      else if (!strncmp(arg,"--exportheader=",15))
+        {
+          _G_system.exportheader = arg + 15;
+	}
       else if (!strcmp("--no-ast", arg))
         {
           _G_system.generate_ast = false;
Index: kdev-pg-default-visitor-gen.cpp
===================================================================
--- kdev-pg-default-visitor-gen.cpp	(Revision 685856)
+++ kdev-pg-default-visitor-gen.cpp	(Arbeitskopie)
@@ -24,7 +24,10 @@
 
 void generate_default_visitor::operator()()
 {
-  out << "class default_visitor: public visitor {" << std::endl
+  out << "class ";
+  if( _G_system.exportmacro && _G_system.exportheader )
+    out << _G_system.exportmacro;
+  out << " default_visitor: public visitor {" << std::endl
       << "public:" << std::endl;
 
   std::for_each(_G_system.symbols.begin(), _G_system.symbols.end(),
Index: kdev-pg-generate.cpp
===================================================================
--- kdev-pg-generate.cpp	(Revision 685856)
+++ kdev-pg-generate.cpp	(Arbeitskopie)
@@ -55,6 +55,11 @@
       << "#include <kdev-pg-list.h>" << std::endl
       << std::endl;
 
+    if (_G_system.exportheader && _G_system.exportmacro)
+    {
+      s << "#include \"" << _G_system.exportheader << "\"" << std::endl;
+    }
+
     if (_G_system.adapt_to_kdevelop)
       {
         // Replace kdevast.h with something more current,
@@ -110,6 +115,11 @@
 
     s << std::endl;
 
+    if (_G_system.exportheader && _G_system.exportmacro)
+    {
+      s << "#include \"" << _G_system.exportheader << "\"" << std::endl;
+    }
+
     if (_G_system.decl && !_G_system.generate_ast)
       s << _G_system.decl << std::endl;
 
@@ -147,9 +157,14 @@
       << std::endl
 
       << "#include \"" << _G_system.language << "_ast.h\"" << std::endl
-      << std::endl
+      << std::endl;
 
-      << "namespace " << _G_system.ns << "{" << std::endl
+    if (_G_system.exportheader && _G_system.exportmacro)
+    {
+      s << "#include \"" << _G_system.exportheader << "\"" << std::endl;
+    }
+
+    s << "namespace " << _G_system.ns << "{" << std::endl
       << std::endl;
 
     __visitor();
@@ -183,9 +198,14 @@
       << std::endl
 
       << "#include \"" << _G_system.language << "_visitor.h\"" << std::endl
-      << std::endl
+      << std::endl;
+ 
+    if (_G_system.exportheader && _G_system.exportmacro)
+    {
+      s << "#include \"" << _G_system.exportheader << "\"" << std::endl;
+    }
 
-      << "namespace " << _G_system.ns << "{" << std::endl
+    s << "namespace " << _G_system.ns << "{" << std::endl
       << std::endl;
 
     __default_visitor();
@@ -223,9 +243,14 @@
 
       << "#include <iostream>" << std::endl
       << "#include <fstream>" << std::endl
-      << std::endl
+      << std::endl;
 
-      << "namespace " << _G_system.ns << "{" << std::endl
+    if (_G_system.exportheader && _G_system.exportmacro)
+    {
+      s << "#include \"" << _G_system.exportheader << "\"" << std::endl;
+    }
+
+    s << "namespace " << _G_system.ns << "{" << std::endl
       << std::endl;
 
     __serialize_visitor();
Index: kdev-pg-ast-gen.cpp
===================================================================
--- kdev-pg-ast-gen.cpp	(Revision 676720)
+++ kdev-pg-ast-gen.cpp	(Arbeitskopie)
@@ -29,7 +29,10 @@
        it != _G_system.symbols.end(); ++it)
     {
       model::symbol_item *sym = (*it).second;
-      out << "struct " << sym->_M_name << "_ast;" << std::endl;
+      out << "struct ";
+      if( _G_system.exportmacro && _G_system.exportheader )
+        out << _G_system.exportmacro;
+      out << " " << sym->_M_name << "_ast;" << std::endl;
     }
 
   out << std::endl;
@@ -43,7 +46,10 @@
 
   out << std::endl;
 
-  out << "struct ast_node";
+  out << "struct ";
+  if( _G_system.exportmacro && _G_system.exportheader )
+    out << _G_system.exportmacro;
+  out << " ast_node";
 
   if (_G_system.adapt_to_kdevelop)
     out << ": public KDevelop::AST";
@@ -78,7 +84,10 @@
   _M_in_cons = false;
 
   model::symbol_item *sym = __it.second;
-  out << "struct " << sym->_M_name << "_ast: public ast_node"
+  out << "struct ";
+  if( _G_system.exportmacro && _G_system.exportheader )
+    out << _G_system.exportmacro;
+  out << " " << sym->_M_name << "_ast: public ast_node"
       << "{" << std::endl
       << "enum { KIND = Kind_" << sym->_M_name << "};" << std::endl << std::endl;
 


More information about the KDevelop-devel mailing list