From: <ne...@us...> - 2012-07-09 17:01:11
|
Revision: 13284 http://swig.svn.sourceforge.net/swig/?rev=13284&view=rev Author: neha1 Date: 2012-07-09 17:01:05 +0000 (Mon, 09 Jul 2012) Log Message: ----------- Added option to generate debug information for code templates. From: Oliver Buchtala <oli...@go...> Modified Paths: -------------- branches/gsoc2012-javascript/Examples/Makefile.in branches/gsoc2012-javascript/Source/Modules/javascript.cxx branches/gsoc2012-javascript/Source/Modules/javascript_emitter.cxx branches/gsoc2012-javascript/Source/Modules/javascript_emitter.h Modified: branches/gsoc2012-javascript/Examples/Makefile.in =================================================================== --- branches/gsoc2012-javascript/Examples/Makefile.in 2012-07-09 16:59:44 UTC (rev 13283) +++ branches/gsoc2012-javascript/Examples/Makefile.in 2012-07-09 17:01:05 UTC (rev 13284) @@ -534,7 +534,7 @@ # ---------------------------------------------------------------- javascript: $(SRCS) - $(SWIG) -javascript -jsc $(SWIGOPT) $(INTERFACEPATH) + $(SWIG) -javascript -jsc -debug-templates $(SWIGOPT) $(INTERFACEPATH) $(CC) -c $(CCSHARED) $(CFLAGS) $(JSCFLAGS) $(SRCS) $(ISRCS) $(INCLUDES) $(JS_INCLUDE) $(JSLDSHARED) $(CCSHARED) $(CFLAGS) $(OBJS) $(IOBJS) $(JS_DLNK) $(LIBS) -o $(JS_LIBPREFIX)$(TARGET)$(JSSO) @@ -543,7 +543,7 @@ # ---------------------------------------------------------------- javascript_cpp: $(SRCS) - $(SWIG) -javascript -jsc -c++ $(SWIGOPT) $(INTERFACEPATH) + $(SWIG) -javascript -jsc -c++ -debug-templates $(SWIGOPT) $(INTERFACEPATH) $(CXX) -c $(CCSHARED) $(CFLAGS) $(JSCFLAGS) $(SRCS) $(CXXSRCS) $(ICXXSRCS) $(INCLUDES) $(JS_INCLUDE) $(JSCXXSHARED) $(CCSHARED) $(CFLAGS) $(OBJS) $(IOBJS) $(JS_DLNK) $(LIBS) $(CPP_DLLIBS) -o $(JS_LIBPREFIX)$(TARGET)$(JSSO) Modified: branches/gsoc2012-javascript/Source/Modules/javascript.cxx =================================================================== --- branches/gsoc2012-javascript/Source/Modules/javascript.cxx 2012-07-09 16:59:44 UTC (rev 13283) +++ branches/gsoc2012-javascript/Source/Modules/javascript.cxx 2012-07-09 17:01:05 UTC (rev 13284) @@ -196,6 +196,7 @@ int mode = -1; + bool debug_templates = false; for (int i = 1; i < argc; i++) { if (argv[i]) { if (strcmp(argv[i], "-v8") == 0) { @@ -210,6 +211,9 @@ Swig_mark_arg(i); mode = swig::JSEmitter::QtScript; SWIG_library_directory("javascript/qt"); + } else if (strcmp(argv[i], "-debug-templates") == 0) { + Swig_mark_arg(i); + debug_templates = true; } } } @@ -237,6 +241,9 @@ } } + if(debug_templates) { + emitter->enableDebug(); + } // Add a symbol to the parser for conditional compilation Preprocessor_define("SWIGJAVASCRIPT 1", 0); Modified: branches/gsoc2012-javascript/Source/Modules/javascript_emitter.cxx =================================================================== --- branches/gsoc2012-javascript/Source/Modules/javascript_emitter.cxx 2012-07-09 16:59:44 UTC (rev 13283) +++ branches/gsoc2012-javascript/Source/Modules/javascript_emitter.cxx 2012-07-09 17:01:05 UTC (rev 13284) @@ -7,7 +7,8 @@ * ----------------------------------------------------------------------------- */ swig::JSEmitter::JSEmitter() -: empty_string(NewString("")) { +: empty_string(NewString("")), + debug(false) { templates = NewHash(); } @@ -32,7 +33,7 @@ * swig::JSEmitter::GetTemplate() : Retrieves a registered a code template * ----------------------------------------------------------------------------- */ -const String *swig::JSEmitter::getTemplate(const String *name) { +swig::Template swig::JSEmitter::getTemplate(const String *name) { String *templ = Getattr(templates, name); if (!templ) { @@ -40,9 +41,16 @@ SWIG_exit(EXIT_FAILURE); } - return templ; + Template t(templ, name, debug); + + return t; } +void swig::JSEmitter::enableDebug() { + debug = true; +} + + /* ----------------------------------------------------------------------------- * swig::JSEmitter::typemapLookup() * @@ -209,14 +217,29 @@ } code = NewString(code_); + templateName = NewString(""); } +swig::Template::Template(const String *code_, const String *templateName_, bool debug_) { + + if (!code_) { + Printf(stdout, "Template code was null. Illegal input for template."); + SWIG_exit(EXIT_FAILURE); + } + + code = NewString(code_); + templateName = NewString(templateName_); + debug = debug_; +} + + /* ----------------------------------------------------------------------------- * swig::Template::~Template() : cleans up of Template. * ----------------------------------------------------------------------------- */ swig::Template::~Template() { Delete(code); + Delete(templateName); } /* ----------------------------------------------------------------------------- @@ -224,6 +247,20 @@ * ----------------------------------------------------------------------------- */ String *swig::Template::str() { + if (debug) { + String *pre_code = NewString(""); + String *post_code = NewString(""); + String *debug_code = NewString(""); + Printf(pre_code, "//begin fragment(\"%s\")\n", templateName); + Printf(post_code, "//end fragment(\"%s\")\n", templateName); + Printf(debug_code, "%s\n%s\n%s", pre_code, code, post_code); + + Delete(code); + Delete(pre_code); + Delete(post_code); + + code = debug_code; + } return code; } Modified: branches/gsoc2012-javascript/Source/Modules/javascript_emitter.h =================================================================== --- branches/gsoc2012-javascript/Source/Modules/javascript_emitter.h 2012-07-09 16:59:44 UTC (rev 13283) +++ branches/gsoc2012-javascript/Source/Modules/javascript_emitter.h 2012-07-09 17:01:05 UTC (rev 13284) @@ -13,6 +13,8 @@ public: Template(const String *code); + Template(const String *code, const String *templateName, bool debug); + ~Template(); String *str(); @@ -21,6 +23,8 @@ private: String *code; + String *templateName; + bool debug; }; class JSEmitter { @@ -126,7 +130,9 @@ /** * Retrieve the code template registered for a given name. */ - const String *getTemplate(const String *name); + Template getTemplate(const String *name); + + void enableDebug(); protected: @@ -145,6 +151,8 @@ Node *getBaseClass(Node *n); const String *typemapLookup(Node *n, const_String_or_char_ptr tmap_method, SwigType *type, int warning, Node *typemap_attributes = 0); + + void enableDebugTemplates(); protected: @@ -154,6 +162,8 @@ Hash *templates; Wrapper *current_wrapper; + + bool debug; }; } // namespace swig This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |