improved the naming rule
This commit is contained in:
parent
3c63104bf7
commit
14b0bca55c
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: awk.c 207 2009-06-22 13:01:28Z hyunghwan.chung $
|
||||
* $Id: awk.c 217 2009-06-28 13:41:47Z hyunghwan.chung $
|
||||
*
|
||||
Copyright 2006-2009 Chung, Hyung-Hwan.
|
||||
|
||||
@ -345,6 +345,7 @@ struct opttab_t
|
||||
{ QSE_T("pablock"), QSE_AWK_PABLOCK, QSE_T("enable pattern-action loop") },
|
||||
{ QSE_T("rexbound"), QSE_AWK_REXBOUND, QSE_T("enable {n,m} in a regular expression") },
|
||||
{ QSE_T("ncmponstr"), QSE_AWK_NCMPONSTR, QSE_T("perform numeric comparsion on numeric strings") },
|
||||
{ QSE_T("strictnaming"), QSE_AWK_STRICTNAMING, QSE_T("enable the strict naming rule") },
|
||||
{ QSE_NULL, 0 }
|
||||
};
|
||||
|
||||
@ -390,6 +391,7 @@ static int comparg (int argc, qse_char_t* argv[], struct arg_t* arg)
|
||||
{ QSE_T(":pablock"), QSE_T('\0') },
|
||||
{ QSE_T(":rexbound"), QSE_T('\0') },
|
||||
{ QSE_T(":ncmponstr"), QSE_T('\0') },
|
||||
{ QSE_T(":strictnaming"), QSE_T('\0') },
|
||||
|
||||
{ QSE_T(":call"), QSE_T('c') },
|
||||
{ QSE_T(":file"), QSE_T('f') },
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: awk.h 214 2009-06-27 02:50:54Z hyunghwan.chung $
|
||||
* $Id: awk.h 217 2009-06-28 13:41:47Z hyunghwan.chung $
|
||||
*
|
||||
Copyright 2006-2009 Chung, Hyung-Hwan.
|
||||
|
||||
@ -487,25 +487,25 @@ enum qse_awk_option_t
|
||||
* " a b c " is split to [a], [b], [c] if #QSE_AWK_STRIPSPACES is on.
|
||||
* Otherwise, it is split to [], [a], [b], [c], [].
|
||||
*/
|
||||
QSE_AWK_STRIPSPACES = (1 << 11),
|
||||
QSE_AWK_STRIPSPACES = (1 << 10),
|
||||
|
||||
/** enables @b nextofile */
|
||||
QSE_AWK_NEXTOFILE = (1 << 12),
|
||||
QSE_AWK_NEXTOFILE = (1 << 11),
|
||||
|
||||
/** enables @b reset */
|
||||
QSE_AWK_RESET = (1 << 13),
|
||||
QSE_AWK_RESET = (1 << 12),
|
||||
|
||||
/** CR + LF by default */
|
||||
QSE_AWK_CRLF = (1 << 14),
|
||||
QSE_AWK_CRLF = (1 << 13),
|
||||
|
||||
/** allows the assignment of a map value to a variable */
|
||||
QSE_AWK_MAPTOVAR = (1 << 15),
|
||||
QSE_AWK_MAPTOVAR = (1 << 14),
|
||||
|
||||
/** allows @b BEGIN, @b END, pattern-action blocks */
|
||||
QSE_AWK_PABLOCK = (1 << 16),
|
||||
QSE_AWK_PABLOCK = (1 << 15),
|
||||
|
||||
/** allows {n,m} in a regular expression. */
|
||||
QSE_AWK_REXBOUND = (1 << 17),
|
||||
QSE_AWK_REXBOUND = (1 << 16),
|
||||
|
||||
/**
|
||||
* performs numeric comparison when a string convertable
|
||||
@ -515,14 +515,22 @@ enum qse_awk_option_t
|
||||
* - 9 is greater if #QSE_AWK_NCMPONSTR is off;
|
||||
* - "10.9" is greater if #QSE_AWK_NCMPONSTR is on
|
||||
*/
|
||||
QSE_AWK_NCMPONSTR = (1 << 18),
|
||||
QSE_AWK_NCMPONSTR = (1 << 17),
|
||||
|
||||
/**
|
||||
* strict naming rule
|
||||
* - a parameter can not be the same as the owning function name.
|
||||
* - a local variable can not be the same as the owning function name.
|
||||
*/
|
||||
QSE_AWK_STRICTNAMING = (1 << 18),
|
||||
|
||||
/**
|
||||
* makes #qse_awk_t to behave as compatibly as classical AWK
|
||||
* implementations
|
||||
*/
|
||||
QSE_AWK_CLASSIC = QSE_AWK_IMPLICIT | QSE_AWK_RIO |
|
||||
QSE_AWK_NEWLINE | QSE_AWK_PABLOCK
|
||||
QSE_AWK_NEWLINE | QSE_AWK_PABLOCK |
|
||||
QSE_AWK_STRICTNAMING
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: parse.c 216 2009-06-27 12:42:53Z hyunghwan.chung $
|
||||
* $Id: parse.c 217 2009-06-28 13:41:47Z hyunghwan.chung $
|
||||
*
|
||||
Copyright 2006-2009 Chung, Hyung-Hwan.
|
||||
|
||||
@ -947,8 +947,9 @@ static qse_awk_nde_t* parse_function (qse_awk_t* awk)
|
||||
|
||||
/* check if a parameter conflicts with the function
|
||||
* name or other parameters */
|
||||
if (qse_strxncmp (
|
||||
param, param_len, name_dup, name_len) == 0 ||
|
||||
if (((awk->option & QSE_AWK_STRICTNAMING) &&
|
||||
qse_strxncmp (
|
||||
param, param_len, name_dup, name_len) == 0) ||
|
||||
qse_lda_search (awk->parse.params,
|
||||
0, param, param_len) != QSE_LDA_NIL)
|
||||
{
|
||||
@ -1732,7 +1733,7 @@ static qse_awk_t* collect_locals (
|
||||
lcl.len = QSE_STR_LEN(awk->token.name);
|
||||
|
||||
/* check if it conflict with a builtin function name
|
||||
* function f() { lcl length; } */
|
||||
* function f() { local length; } */
|
||||
if (qse_awk_getfnc (awk, lcl.ptr, lcl.len) != QSE_NULL)
|
||||
{
|
||||
SETERRARG (
|
||||
@ -1743,8 +1744,11 @@ static qse_awk_t* collect_locals (
|
||||
|
||||
if (istop)
|
||||
{
|
||||
/* check if it conflicts with a paremeter name */
|
||||
n = qse_lda_search (awk->parse.params, 0, lcl.ptr, lcl.len);
|
||||
/* check if it conflicts with a parameter name.
|
||||
* the first level declaration is treated as the same
|
||||
* scope as the parameter list */
|
||||
n = qse_lda_search (
|
||||
awk->parse.params, 0, lcl.ptr, lcl.len);
|
||||
if (n != QSE_LDA_NIL)
|
||||
{
|
||||
SETERRARG (
|
||||
@ -1754,6 +1758,25 @@ static qse_awk_t* collect_locals (
|
||||
}
|
||||
}
|
||||
|
||||
if (awk->option & QSE_AWK_STRICTNAMING)
|
||||
{
|
||||
/* check if it conflicts with the owning function */
|
||||
if (awk->tree.cur_fun.ptr != QSE_NULL)
|
||||
{
|
||||
if (qse_strxncmp (
|
||||
lcl.ptr, lcl.len,
|
||||
awk->tree.cur_fun.ptr,
|
||||
awk->tree.cur_fun.len) == 0)
|
||||
{
|
||||
SETERRARG (
|
||||
awk, QSE_AWK_EFUNRED,
|
||||
awk->token.line,
|
||||
lcl.ptr, lcl.len);
|
||||
return QSE_NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* check if it conflicts with other local variable names */
|
||||
n = qse_lda_search (
|
||||
awk->parse.lcls,
|
||||
@ -1771,9 +1794,10 @@ static qse_awk_t* collect_locals (
|
||||
n = find_global (awk, lcl.ptr, lcl.len);
|
||||
if (n != QSE_LDA_NIL)
|
||||
{
|
||||
if (n < awk->tree.ngbls_base)
|
||||
if (n < awk->tree.ngbls_base)
|
||||
{
|
||||
/* conflicting with a static global variable */
|
||||
/* it is a conflict only if it is one of a
|
||||
* static global variable */
|
||||
SETERRARG (
|
||||
awk, QSE_AWK_EDUPLCL, awk->token.line,
|
||||
lcl.ptr, lcl.len);
|
||||
|
@ -1,7 +1,12 @@
|
||||
function a (a) { print a; }
|
||||
function x (y) { print y; }
|
||||
function a (x) { print x; }
|
||||
|
||||
BEGIN {
|
||||
local a;
|
||||
a = 20;
|
||||
a (1000);
|
||||
a (1000);
|
||||
{
|
||||
local a;
|
||||
print a;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user