aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArnold D. Robbins <arnold@skeeve.com>2012-06-25 21:28:29 +0300
committerArnold D. Robbins <arnold@skeeve.com>2012-06-25 21:28:29 +0300
commit93e689fa83ef9a78f2bdfa093af31fcecb429d58 (patch)
tree18521d2c5e2d9f186f2e95df3164e220d3b37aae
parent6139211362667682c3022a72321e0cd8945b6592 (diff)
downloadegawk-93e689fa83ef9a78f2bdfa093af31fcecb429d58.tar.gz
egawk-93e689fa83ef9a78f2bdfa093af31fcecb429d58.tar.bz2
egawk-93e689fa83ef9a78f2bdfa093af31fcecb429d58.zip
Fix lint checking for extension functions.
-rw-r--r--ChangeLog11
-rw-r--r--TODO.xgawk27
-rw-r--r--awk.h1
-rw-r--r--awkgram.c31
-rw-r--r--awkgram.y31
-rw-r--r--ext.c1
6 files changed, 71 insertions, 31 deletions
diff --git a/ChangeLog b/ChangeLog
index 0043aaf9..8b5e2415 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2012-06-25 Arnold D. Robbins <arnold@skeeve.com>
+
+ * TODO.xgawk: Updated.
+ * awk.h (track_ext_func): Declared.
+ * awkgram.y (enum defref): Add option for extension function.
+ (struct fdesc): Add member for extension function.
+ (func_use): Handle extension function, mark as extension and defined.
+ (track_ext_func): New function.
+ (check_funcs): Update logic for extension functions.
+ * ext.c (make_builtin): Call track_ext_func.
+
2012-06-24 Andrew J. Schorr <aschorr@telemetry-investments.com>
* TODO.xgawk: Most of IOBUF has been hidden.
diff --git a/TODO.xgawk b/TODO.xgawk
index 3ea20297..6e149290 100644
--- a/TODO.xgawk
+++ b/TODO.xgawk
@@ -56,25 +56,10 @@ hosting for these projects:
Low priority:
-- Fix extension/rwarray.c. It does not currently compile due to changes
- in the NODE structure relating to array support. The MPFR changes will
- also make this more complicated. John is best equipped to solve this
- problem.
-
- Enhance extension/fork.c waitpid to allow the caller to specify the options.
And add an optional array argument to wait and waitpid in which to return
exit status information.
-- Fix lint complaints about shared library functions being called without
- having been defined. For example, try:
- gawk --lint -lordchr 'BEGIN {print chr(65)}'
- gawk: warning: function `chr' called but never defined
- A
- In ext.c, make_builtin needs to call awkgram.y:func_use. If done naively,
- I think this would result in complaints about shared library functions
- defined but not used. So there should probably be an enhancement to func_use
- and ftable to indicate if it's a shared library function.
-
Possible future changes requiring (further) discussion:
@@ -159,3 +144,15 @@ Done:
unless called by the "extension" function that nobody uses.
- Hide private parts of IOBUF from extensions.
+
+- Fix extension/rwarray.c.
+
+- Fix lint complaints about shared library functions being called without
+ having been defined. For example, try:
+ gawk --lint -lordchr 'BEGIN {print chr(65)}'
+ gawk: warning: function `chr' called but never defined
+ A
+ In ext.c, make_builtin needs to call awkgram.y:func_use. If done naively,
+ I think this would result in complaints about shared library functions
+ defined but not used. So there should probably be an enhancement to func_use
+ and ftable to indicate if it's a shared library function.
diff --git a/awk.h b/awk.h
index a2e0e390..f08d7d9c 100644
--- a/awk.h
+++ b/awk.h
@@ -1406,6 +1406,7 @@ extern unsigned long (*hash)(const char *s, size_t len, unsigned long hsize, siz
/* awkgram.c */
extern NODE *variable(int location, char *name, NODETYPE type);
extern int parse_program(INSTRUCTION **pcode);
+extern void track_ext_func(const char *name);
extern void dump_funcs(void);
extern void dump_vars(const char *fname);
extern const char *getfname(NODE *(*)(int));
diff --git a/awkgram.c b/awkgram.c
index a454b0c9..104c5545 100644
--- a/awkgram.c
+++ b/awkgram.c
@@ -120,7 +120,7 @@ static int count_expressions(INSTRUCTION **list, bool isarg);
static INSTRUCTION *optimize_assignment(INSTRUCTION *exp);
static void add_lint(INSTRUCTION *list, LINTTYPE linttype);
-enum defref { FUNC_DEFINE, FUNC_USE };
+enum defref { FUNC_DEFINE, FUNC_USE, FUNC_EXT };
static void func_use(const char *name, enum defref how);
static void check_funcs(void);
@@ -6937,6 +6937,7 @@ static struct fdesc {
char *name;
short used;
short defined;
+ short extension;
struct fdesc *next;
} *ftable[HASHSIZE];
@@ -6956,7 +6957,10 @@ func_use(const char *name, enum defref how)
if (strcmp(fp->name, name) == 0) {
if (how == FUNC_DEFINE)
fp->defined++;
- else
+ else if (how == FUNC_EXT) {
+ fp->defined++;
+ fp->extension++;
+ } else
fp->used++;
return;
}
@@ -6970,12 +6974,23 @@ func_use(const char *name, enum defref how)
strcpy(fp->name, name);
if (how == FUNC_DEFINE)
fp->defined++;
- else
+ else if (how == FUNC_EXT) {
+ fp->defined++;
+ fp->extension++;
+ } else
fp->used++;
fp->next = ftable[ind];
ftable[ind] = fp;
}
+/* track_ext_func --- add an extension function to the table */
+
+void
+track_ext_func(const char *name)
+{
+ func_use(name, FUNC_EXT);
+}
+
/* check_funcs --- verify functions that are called but not defined */
static void
@@ -6989,19 +7004,19 @@ check_funcs()
for (i = 0; i < HASHSIZE; i++) {
for (fp = ftable[i]; fp != NULL; fp = fp->next) {
+ if (fp->defined == 0 && ! fp->extension) {
#ifdef REALLYMEAN
- /* making this the default breaks old code. sigh. */
- if (fp->defined == 0) {
+ /* making this the default breaks old code. sigh. */
error(
_("function `%s' called but never defined"), fp->name);
errcount++;
- }
#else
- if (do_lint && fp->defined == 0)
lintwarn(
_("function `%s' called but never defined"), fp->name);
#endif
- if (do_lint && fp->used == 0) {
+ }
+
+ if (do_lint && fp->used == 0 && ! fp->extension) {
lintwarn(_("function `%s' defined but never called directly"),
fp->name);
}
diff --git a/awkgram.y b/awkgram.y
index 7949829c..eed06934 100644
--- a/awkgram.y
+++ b/awkgram.y
@@ -76,7 +76,7 @@ static int count_expressions(INSTRUCTION **list, bool isarg);
static INSTRUCTION *optimize_assignment(INSTRUCTION *exp);
static void add_lint(INSTRUCTION *list, LINTTYPE linttype);
-enum defref { FUNC_DEFINE, FUNC_USE };
+enum defref { FUNC_DEFINE, FUNC_USE, FUNC_EXT };
static void func_use(const char *name, enum defref how);
static void check_funcs(void);
@@ -4217,6 +4217,7 @@ static struct fdesc {
char *name;
short used;
short defined;
+ short extension;
struct fdesc *next;
} *ftable[HASHSIZE];
@@ -4236,7 +4237,10 @@ func_use(const char *name, enum defref how)
if (strcmp(fp->name, name) == 0) {
if (how == FUNC_DEFINE)
fp->defined++;
- else
+ else if (how == FUNC_EXT) {
+ fp->defined++;
+ fp->extension++;
+ } else
fp->used++;
return;
}
@@ -4250,12 +4254,23 @@ func_use(const char *name, enum defref how)
strcpy(fp->name, name);
if (how == FUNC_DEFINE)
fp->defined++;
- else
+ else if (how == FUNC_EXT) {
+ fp->defined++;
+ fp->extension++;
+ } else
fp->used++;
fp->next = ftable[ind];
ftable[ind] = fp;
}
+/* track_ext_func --- add an extension function to the table */
+
+void
+track_ext_func(const char *name)
+{
+ func_use(name, FUNC_EXT);
+}
+
/* check_funcs --- verify functions that are called but not defined */
static void
@@ -4269,19 +4284,19 @@ check_funcs()
for (i = 0; i < HASHSIZE; i++) {
for (fp = ftable[i]; fp != NULL; fp = fp->next) {
+ if (fp->defined == 0 && ! fp->extension) {
#ifdef REALLYMEAN
- /* making this the default breaks old code. sigh. */
- if (fp->defined == 0) {
+ /* making this the default breaks old code. sigh. */
error(
_("function `%s' called but never defined"), fp->name);
errcount++;
- }
#else
- if (do_lint && fp->defined == 0)
lintwarn(
_("function `%s' called but never defined"), fp->name);
#endif
- if (do_lint && fp->used == 0) {
+ }
+
+ if (do_lint && fp->used == 0 && ! fp->extension) {
lintwarn(_("function `%s' defined but never called directly"),
fp->name);
}
diff --git a/ext.c b/ext.c
index 14d55c5f..af6542d4 100644
--- a/ext.c
+++ b/ext.c
@@ -123,6 +123,7 @@ make_builtin(const awk_ext_func_t *funcinfo)
symbol = install_symbol(estrdup(name, strlen(name)), Node_ext_func);
symbol->code_ptr = b;
+ track_ext_func(name);
return true;
}