From 470143192d0c8cf90ad84a66226d48060cc713db Mon Sep 17 00:00:00 2001 From: wtschueller Date: Sat, 12 Jul 2014 20:34:46 +0200 Subject: [PATCH] Tcl: correct namespace resolution in case of INLINE_SOURCES = YES --- src/tclscanner.l | 20 +++++++- testing/062/namespacen1.xml | 42 +++++++++++++++++ testing/062/namespacen2.xml | 42 +++++++++++++++++ testing/062/namespacen3.xml | 42 +++++++++++++++++ testing/062_namespace_resolution.tcl | 68 ++++++++++++++++++++++++++++ 5 files changed, 213 insertions(+), 1 deletion(-) create mode 100644 testing/062/namespacen1.xml create mode 100644 testing/062/namespacen2.xml create mode 100644 testing/062/namespacen3.xml create mode 100644 testing/062_namespace_resolution.tcl diff --git a/src/tclscanner.l b/src/tclscanner.l index 24c0a7bcec1..e93152bd928 100644 --- a/src/tclscanner.l +++ b/src/tclscanner.l @@ -534,6 +534,24 @@ static void tcl_name(const QCString &ns0, const QCString &name0, QCString &ns, Q } } +//! Check name. Strip namespace qualifiers from name0 if inside inlined code segment. +// @return 'ns' and 'name' of given current 'ns0' and 'name0' +static void tcl_name_SnippetAware(const QCString &ns0, const QCString &name0, QCString &ns, QCString &name) +{ + // If we are inside an inlined code snippet then ns0 + // already containes the complete namespace path. + // Any namespace qualifiers in name0 are redundant. + int i = name0.findRev("::"); + if (i>=0 && tcl.memberdef) + { + tcl_name(ns0, name0.mid(i+2), ns, name); + } + else + { + tcl_name(ns0, name0, ns, name); + } +} + // Check and return namespace entry. // @return namespace entry Entry* tcl_entry_namespace(const QCString ns) @@ -2099,7 +2117,7 @@ D tcl_codify_cmd(NULL,3); tcl_codify_cmd(NULL,4); tcl_codify_cmd(NULL,5); - tcl_name(myScan->ns,(*tcl.list_commandwords.at(2)).utf8(),myNs,myName); + tcl_name_SnippetAware(myScan->ns,(*tcl.list_commandwords.at(2)).utf8(),myNs,myName); if (myNs.length()) { myEntryNs = tcl_entry_namespace(myNs); diff --git a/testing/062/namespacen1.xml b/testing/062/namespacen1.xml new file mode 100644 index 00000000000..0ef31ffe0ca --- /dev/null +++ b/testing/062/namespacen1.xml @@ -0,0 +1,42 @@ + + + + n1 + n1::n1 + + + + n1::p1 + args + p1 + + + + + + + + p2 + + + + n1::p2 + args + p2 + + + + + + + + p1 + + + + + + + + + diff --git a/testing/062/namespacen2.xml b/testing/062/namespacen2.xml new file mode 100644 index 00000000000..39c21d24629 --- /dev/null +++ b/testing/062/namespacen2.xml @@ -0,0 +1,42 @@ + + + + n2 + n2::n2 + + + + n2::p1 + args + p1 + + + + + + + + p2 + + + + n2::p2 + args + p2 + + + + + + + + p1 + + + + + + + + + diff --git a/testing/062/namespacen3.xml b/testing/062/namespacen3.xml new file mode 100644 index 00000000000..25c803c55d5 --- /dev/null +++ b/testing/062/namespacen3.xml @@ -0,0 +1,42 @@ + + + + n3 + n3::n3 + + + + n3::p1 + args + p1 + + + + + + + + p2 + + + + n3::p2 + args + p2 + + + + + + + + p1 + + + + + + + + + diff --git a/testing/062_namespace_resolution.tcl b/testing/062_namespace_resolution.tcl new file mode 100644 index 00000000000..dcc67014f85 --- /dev/null +++ b/testing/062_namespace_resolution.tcl @@ -0,0 +1,68 @@ +#// objective: tests correct namespace resolution, only references/referencedby relations are relevant +#// check: namespacen1.xml +#// check: namespacen2.xml +#// check: namespacen3.xml +#// config: REFERENCED_BY_RELATION = yes +#// config: REFERENCES_RELATION = yes +#// config: EXTRACT_ALL = yes +#// config: INLINE_SOURCES = yes + +# now: combine namespace eval and qualified names +namespace eval n1 { + proc p1 args { + array set info [info frame 0]; puts -nonewline ->$info(proc) + p2 + return + } + proc p2 args { + array set info [info frame 0]; puts -nonewline ->$info(proc) + return + } + namespace eval n1 { + proc p1 args { + array set info [info frame 0]; puts -nonewline ->$info(proc) + return + } + } +} +# same thing, but fully qualified proc names +namespace eval ::n2 {} +namespace eval ::n2::n2 {} +proc ::n2::p1 args { + array set info [info frame 0]; puts -nonewline ->$info(proc) + p2 + return +} +proc ::n2::p2 args { + array set info [info frame 0]; puts -nonewline ->$info(proc) + return +} +proc ::n2::n2::p2 args { + array set info [info frame 0]; puts -nonewline ->$info(proc) + return +} +# same thing, without leading :: +namespace eval n3 {} +namespace eval n3::n3 {} +proc n3::p1 args { + array set info [info frame 0]; puts -nonewline ->$info(proc) + p2 + return +} +proc n3::p2 args { + array set info [info frame 0]; puts -nonewline ->$info(proc) + return +} +proc n3::n3::p2 args { + array set info [info frame 0]; puts -nonewline ->$info(proc) + return +} +# now, check with tcl what is called +n1::p1 +puts "" +n2::p1 +puts "" +n3::p1 +puts "" +exit +