Skip to content

Commit

Permalink
Tcl: support eval/catch commands
Browse files Browse the repository at this point in the history
--HG--
extra : rebase_source : 5d7e3a2b3c549419c672cddd8d780542053d68bb
  • Loading branch information
wtschueller committed Jun 17, 2014
1 parent 3d05cb6 commit 9d24b48
Show file tree
Hide file tree
Showing 3 changed files with 327 additions and 2 deletions.
51 changes: 49 additions & 2 deletions src/tclscanner.l
Expand Up @@ -1816,6 +1816,42 @@ static tcl_scan *tcl_command_ARG(tcl_scan *myScan, unsigned int i, bool ignoreOu
return (myScan);
}

//! Handle internal tcl commands.
// "eval arg ?arg ...?"
static void tcl_command_EVAL()
{
D
tcl_codify_cmd("keyword", 0);
tcl_scan *myScan = tcl.scan.at(0);
QCString myString = "";
// we simply rescan the line without the eval
// we include leading whitespace because tcl_scan_start will examine
// the first char. If it finds a bracket it will assume one expression in brackets.
// Example: eval [list set] [list NotInvoked] [Invoked NotInvoked]
for (unsigned int i = 1; i < tcl.list_commandwords.count(); i++)
{
myString += (*tcl.list_commandwords.at(i)).utf8();
}
myScan = tcl_scan_start('?', myString,
myScan->ns, myScan->entry_cl, myScan->entry_fn);
}

//! Handle internal tcl commands.
// "catch script ?resultVarName? ?optionsVarName?"
static void tcl_command_CATCH()
{
D
tcl_codify_cmd("keyword", 0);
tcl_codify_cmd(NULL, 1);
tcl_scan *myScan = tcl.scan.at(0);
myScan = tcl_scan_start('?', *tcl.list_commandwords.at(2),
myScan->ns, myScan->entry_cl, myScan->entry_fn);
for (unsigned int i = 3; i < tcl.list_commandwords.count(); i++)
{
myScan = tcl_command_ARG(myScan, i, false);
}
}

//! Handle internal tcl commands.
// "if expr1 ?then? body1 elseif expr2 ?then? body2 elseif ... ?else? ?bodyN?"
static void tcl_command_IF(QStringList type)
Expand Down Expand Up @@ -2458,9 +2494,20 @@ tcl_inf("->\n");
}
/*
* Start of internal tcl keywords
* Ready: if, for, foreach, while
* TODO: switch, eval, ?
* Ready: eval, catch, if, for, foreach, while
*/
if (myStr=="eval")
{
if (tcl.list_commandwords.count() < 3) {myLine=__LINE__;goto command_warn;}
tcl_command_EVAL();
goto command_end;
}
if (myStr=="catch")
{
if (tcl.list_commandwords.count() < 3) {myLine=__LINE__;goto command_warn;}
tcl_command_CATCH();
goto command_end;
}
if (myStr=="for")
{
if (tcl.list_commandwords.count() != 9) {myLine=__LINE__;goto command_warn;}
Expand Down
191 changes: 191 additions & 0 deletions testing/059/059__command__catch_8tcl.xml
@@ -0,0 +1,191 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<doxygen xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="compound.xsd" version="">
<compounddef id="059__command__catch_8tcl" kind="file">
<compoundname>059_command_catch.tcl</compoundname>
<sectiondef kind="func">
<memberdef kind="function" id="059__command__catch_8tcl_1aa889853547f65a22ae133cd57ff89601" prot="public" static="no" const="no" explicit="no" inline="no" virt="non-virtual">
<type/>
<definition>Invoked</definition>
<argsstring>args</argsstring>
<name>Invoked</name>
<briefdescription>
<para>should be reference by every proc below </para>
</briefdescription>
<detaileddescription>
</detaileddescription>
<inbodydescription>
</inbodydescription>
<location file="059_command_catch.tcl" bodystart="10" bodyend="13"/>
<referencedby refid="059__command__catch_8tcl_1ab08ae027fc5777bc4f0629f1b60b35db" compoundref="059__command__catch_8tcl" startline="22" endline="25">a</referencedby>
<referencedby refid="059__command__catch_8tcl_1a68bdb74c144118d936931c46f75d4b3e" compoundref="059__command__catch_8tcl" startline="29" endline="32">b</referencedby>
<referencedby refid="059__command__catch_8tcl_1ab14f56bc3bd7680490ece4ad7815465f" compoundref="059__command__catch_8tcl" startline="33" endline="36">c</referencedby>
<referencedby refid="059__command__catch_8tcl_1af43f4b1f0064a33b2d662af9f06d3a00" compoundref="059__command__catch_8tcl" startline="37" endline="40">d</referencedby>
<referencedby refid="059__command__catch_8tcl_1aff65a51a703804e0ad1adbcfd76c86f8" compoundref="059__command__catch_8tcl" startline="41" endline="44">e</referencedby>
<referencedby refid="059__command__catch_8tcl_1af6830d2c644b45088ea8f1f74a46b778" compoundref="059__command__catch_8tcl" startline="45" endline="48">f</referencedby>
<referencedby refid="059__command__catch_8tcl_1af08b4b5bfa9edf0b0a7dee1c2b2c29e0" compoundref="059__command__catch_8tcl" startline="49" endline="54">g</referencedby>
<referencedby refid="059__command__catch_8tcl_1af96fd0966e32a310a0778d2e5c357700" compoundref="059__command__catch_8tcl" startline="56" endline="59">h</referencedby>
<referencedby refid="059__command__catch_8tcl_1a8c90afd4641b25be86bd09983c3cbee0" compoundref="059__command__catch_8tcl" startline="60" endline="63">i</referencedby>
<referencedby refid="059__command__catch_8tcl_1a2aaa92757686acea102cba3475f0c13b" compoundref="059__command__catch_8tcl" startline="75" endline="78">j</referencedby>
</memberdef>
<memberdef kind="function" id="059__command__catch_8tcl_1a3f55465410c57ed00ab28827a741b1c3" prot="public" static="no" const="no" explicit="no" inline="no" virt="non-virtual">
<type/>
<definition>NotInvoked</definition>
<argsstring>args</argsstring>
<name>NotInvoked</name>
<briefdescription>
<para>must not be reference by every proc below </para>
</briefdescription>
<detaileddescription>
</detaileddescription>
<inbodydescription>
</inbodydescription>
<location file="059_command_catch.tcl" bodystart="16" bodyend="19"/>
</memberdef>
<memberdef kind="function" id="059__command__catch_8tcl_1ab08ae027fc5777bc4f0629f1b60b35db" prot="public" static="no" const="no" explicit="no" inline="no" virt="non-virtual">
<type/>
<definition>a</definition>
<argsstring>args</argsstring>
<name>a</name>
<briefdescription>
</briefdescription>
<detaileddescription>
</detaileddescription>
<inbodydescription>
</inbodydescription>
<location file="059_command_catch.tcl" bodystart="22" bodyend="25"/>
<references refid="059__command__catch_8tcl_1aa889853547f65a22ae133cd57ff89601" compoundref="059__command__catch_8tcl" startline="10" endline="13">Invoked</references>
</memberdef>
<memberdef kind="function" id="059__command__catch_8tcl_1a68bdb74c144118d936931c46f75d4b3e" prot="public" static="no" const="no" explicit="no" inline="no" virt="non-virtual">
<type/>
<definition>b</definition>
<argsstring>args</argsstring>
<name>b</name>
<briefdescription>
</briefdescription>
<detaileddescription>
</detaileddescription>
<inbodydescription>
</inbodydescription>
<location file="059_command_catch.tcl" bodystart="29" bodyend="32"/>
<references refid="059__command__catch_8tcl_1aa889853547f65a22ae133cd57ff89601" compoundref="059__command__catch_8tcl" startline="10" endline="13">Invoked</references>
</memberdef>
<memberdef kind="function" id="059__command__catch_8tcl_1ab14f56bc3bd7680490ece4ad7815465f" prot="public" static="no" const="no" explicit="no" inline="no" virt="non-virtual">
<type/>
<definition>c</definition>
<argsstring>args</argsstring>
<name>c</name>
<briefdescription>
</briefdescription>
<detaileddescription>
</detaileddescription>
<inbodydescription>
</inbodydescription>
<location file="059_command_catch.tcl" bodystart="33" bodyend="36"/>
<references refid="059__command__catch_8tcl_1aa889853547f65a22ae133cd57ff89601" compoundref="059__command__catch_8tcl" startline="10" endline="13">Invoked</references>
</memberdef>
<memberdef kind="function" id="059__command__catch_8tcl_1af43f4b1f0064a33b2d662af9f06d3a00" prot="public" static="no" const="no" explicit="no" inline="no" virt="non-virtual">
<type/>
<definition>d</definition>
<argsstring>args</argsstring>
<name>d</name>
<briefdescription>
</briefdescription>
<detaileddescription>
</detaileddescription>
<inbodydescription>
</inbodydescription>
<location file="059_command_catch.tcl" bodystart="37" bodyend="40"/>
<references refid="059__command__catch_8tcl_1aa889853547f65a22ae133cd57ff89601" compoundref="059__command__catch_8tcl" startline="10" endline="13">Invoked</references>
</memberdef>
<memberdef kind="function" id="059__command__catch_8tcl_1aff65a51a703804e0ad1adbcfd76c86f8" prot="public" static="no" const="no" explicit="no" inline="no" virt="non-virtual">
<type/>
<definition>e</definition>
<argsstring>args</argsstring>
<name>e</name>
<briefdescription>
</briefdescription>
<detaileddescription>
</detaileddescription>
<inbodydescription>
</inbodydescription>
<location file="059_command_catch.tcl" bodystart="41" bodyend="44"/>
<references refid="059__command__catch_8tcl_1aa889853547f65a22ae133cd57ff89601" compoundref="059__command__catch_8tcl" startline="10" endline="13">Invoked</references>
</memberdef>
<memberdef kind="function" id="059__command__catch_8tcl_1af6830d2c644b45088ea8f1f74a46b778" prot="public" static="no" const="no" explicit="no" inline="no" virt="non-virtual">
<type/>
<definition>f</definition>
<argsstring>args</argsstring>
<name>f</name>
<briefdescription>
</briefdescription>
<detaileddescription>
</detaileddescription>
<inbodydescription>
</inbodydescription>
<location file="059_command_catch.tcl" bodystart="45" bodyend="48"/>
<references refid="059__command__catch_8tcl_1aa889853547f65a22ae133cd57ff89601" compoundref="059__command__catch_8tcl" startline="10" endline="13">Invoked</references>
</memberdef>
<memberdef kind="function" id="059__command__catch_8tcl_1af08b4b5bfa9edf0b0a7dee1c2b2c29e0" prot="public" static="no" const="no" explicit="no" inline="no" virt="non-virtual">
<type/>
<definition>g</definition>
<argsstring>args</argsstring>
<name>g</name>
<briefdescription>
</briefdescription>
<detaileddescription>
</detaileddescription>
<inbodydescription>
</inbodydescription>
<location file="059_command_catch.tcl" bodystart="49" bodyend="54"/>
<references refid="059__command__catch_8tcl_1aa889853547f65a22ae133cd57ff89601" compoundref="059__command__catch_8tcl" startline="10" endline="13">Invoked</references>
</memberdef>
<memberdef kind="function" id="059__command__catch_8tcl_1af96fd0966e32a310a0778d2e5c357700" prot="public" static="no" const="no" explicit="no" inline="no" virt="non-virtual">
<type/>
<definition>h</definition>
<argsstring>args</argsstring>
<name>h</name>
<briefdescription>
</briefdescription>
<detaileddescription>
</detaileddescription>
<inbodydescription>
</inbodydescription>
<location file="059_command_catch.tcl" bodystart="56" bodyend="59"/>
<references refid="059__command__catch_8tcl_1aa889853547f65a22ae133cd57ff89601" compoundref="059__command__catch_8tcl" startline="10" endline="13">Invoked</references>
</memberdef>
<memberdef kind="function" id="059__command__catch_8tcl_1a8c90afd4641b25be86bd09983c3cbee0" prot="public" static="no" const="no" explicit="no" inline="no" virt="non-virtual">
<type/>
<definition>i</definition>
<argsstring>args</argsstring>
<name>i</name>
<briefdescription>
</briefdescription>
<detaileddescription>
</detaileddescription>
<inbodydescription>
</inbodydescription>
<location file="059_command_catch.tcl" bodystart="60" bodyend="63"/>
<references refid="059__command__catch_8tcl_1aa889853547f65a22ae133cd57ff89601" compoundref="059__command__catch_8tcl" startline="10" endline="13">Invoked</references>
</memberdef>
<memberdef kind="function" id="059__command__catch_8tcl_1a2aaa92757686acea102cba3475f0c13b" prot="public" static="no" const="no" explicit="no" inline="no" virt="non-virtual">
<type/>
<definition>j</definition>
<argsstring>args</argsstring>
<name>j</name>
<briefdescription>
</briefdescription>
<detaileddescription>
</detaileddescription>
<inbodydescription>
</inbodydescription>
<location file="059_command_catch.tcl" bodystart="75" bodyend="78"/>
<references refid="059__command__catch_8tcl_1aa889853547f65a22ae133cd57ff89601" compoundref="059__command__catch_8tcl" startline="10" endline="13">Invoked</references>
</memberdef>
</sectiondef>
<briefdescription>
</briefdescription>
<detaileddescription>
</detaileddescription>
<location file="059_command_catch.tcl"/>
</compounddef>
</doxygen>
87 changes: 87 additions & 0 deletions testing/059_command_catch.tcl
@@ -0,0 +1,87 @@
#// objective: tests processing of catch/eval, only references/referencedby relations are relevant
#// check: 059__command__catch_8tcl.xml
#// config: REFERENCED_BY_RELATION = yes
#// config: REFERENCES_RELATION = yes
#// config: EXTRACT_ALL = yes
#// config: INLINE_SOURCES = no

##
# \brief should be reference by every proc below
proc Invoked args {
puts "Procedure \"Invoked\" is invoked indeed. Ok."
return $args
}
##
# \brief must not be reference by every proc below
proc NotInvoked args {
puts "Procedure \"NotInvoked\" is invoked. Not Ok!"
return $args
}
#
# check if call references work at all
proc a args {
Invoked NotInvoked
return
}
#
# catch command
# Tcl8.5: catch script ?resultVarName? ?optionsVarName?
proc b args {
catch Invoked
return
}
proc c args {
catch Invoked NotInvoked
return
}
proc d args {
catch Invoked NotInvoked NotInvoked
return
}
proc e args {
set r [catch Invoked NotInvoked NotInvoked]
return
}
proc f args {
set r [catch {Invoked} NotInvoked NotInvoked]
return
}
proc g args {
set r [catch {
set x [Invoked]
} NotInvoked NotInvoked]
return
}
# eval arg ?arg ...?
proc h args {
eval Invoked NotInvoked
return
}
proc i args {
eval set NotInvoked [Invoked NotInvoked]
return
}
# This is a striped down example. Original:
#
# jpeg.tcl --
#
# Querying and modifying JPEG image files.
#
# Copyright (c) 2004 Aaron Faupell <afaupell@users.sourceforge.net>
#
# ...
# eval [list addComment $file] [lreplace $com 0 0 $comment]
# ...
proc j args {
eval [list set] [list NotInvoked] [Invoked NotInvoked]
return
}
#
# call all single letter procs
# let tcl check what is called and what is not called
foreach p [info procs ?] {
puts "Check procedure \"$p\""
$p
}
exit

0 comments on commit 9d24b48

Please sign in to comment.