From 3c63104bf7f28b6d566ec5eda33a04f955c32514 Mon Sep 17 00:00:00 2001 From: hyung-hwan Date: Sun, 28 Jun 2009 06:42:53 +0000 Subject: [PATCH] fixed a bug of not checking a function name against named variables --- qse/lib/awk/parse.c | 14 ++++++++++++-- qse/regress/awk/lang-002.awk | 4 ++-- qse/regress/awk/lang-003.awk | 6 +++--- qse/regress/awk/lang-004.awk | 4 ++-- 4 files changed, 19 insertions(+), 9 deletions(-) diff --git a/qse/lib/awk/parse.c b/qse/lib/awk/parse.c index a8f12c23..409a3ca9 100644 --- a/qse/lib/awk/parse.c +++ b/qse/lib/awk/parse.c @@ -1,5 +1,5 @@ /* - * $Id: parse.c 215 2009-06-27 05:52:54Z hyunghwan.chung $ + * $Id: parse.c 216 2009-06-27 12:42:53Z hyunghwan.chung $ * Copyright 2006-2009 Chung, Hyung-Hwan. @@ -845,7 +845,8 @@ static qse_awk_nde_t* parse_function (qse_awk_t* awk) return QSE_NULL; } - if (qse_map_search (awk->tree.funs, name, name_len) != QSE_NULL) + /* check if it has already been defined as a function */ + if (qse_map_search (awk->tree.funs, name, name_len) != QSE_NULL) { /* the function is defined previously */ SETERRARG ( @@ -854,6 +855,15 @@ static qse_awk_nde_t* parse_function (qse_awk_t* awk) return QSE_NULL; } + /* check if it conflicts with a named variable */ + if (qse_map_search (awk->parse.named, name, name_len) != QSE_NULL) + { + SETERRARG ( + awk, QSE_AWK_EVARRED, awk->token.line, + name, name_len); + return QSE_NULL; + } + /* check if it coincides to be a global variable name */ g = find_global (awk, name, name_len); if (g != QSE_LDA_NIL) diff --git a/qse/regress/awk/lang-002.awk b/qse/regress/awk/lang-002.awk index 55bc7ad9..c548b89e 100644 --- a/qse/regress/awk/lang-002.awk +++ b/qse/regress/awk/lang-002.awk @@ -1,6 +1,6 @@ -function f(f) +function f(x) { - print f; + print x; f("my hello"); } diff --git a/qse/regress/awk/lang-003.awk b/qse/regress/awk/lang-003.awk index 36b4ea59..f536bc7e 100644 --- a/qse/regress/awk/lang-003.awk +++ b/qse/regress/awk/lang-003.awk @@ -1,3 +1,3 @@ -# should print 50 -function fn(f) { f = 20; } -BEGIN { f = 50; fn(100); print f; } +# should print 50 +function fn(f) { f = 20; } +BEGIN { f = 50; fn(100); print f; } diff --git a/qse/regress/awk/lang-004.awk b/qse/regress/awk/lang-004.awk index 93591f81..e5031a8c 100644 --- a/qse/regress/awk/lang-004.awk +++ b/qse/regress/awk/lang-004.awk @@ -1,3 +1,3 @@ # A function and a named variable cannot have the same name. -function a () { } -BEGIN { a = 20; } +function a () { } +BEGIN { a = 20; }