aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArnold D. Robbins <arnold@skeeve.com>2017-05-20 22:28:59 +0300
committerArnold D. Robbins <arnold@skeeve.com>2017-05-20 22:28:59 +0300
commit0f9d4355a03d000938d87d71ba62f0ac2717334a (patch)
treec275e9f3dbef7112211e036fc42535c93651c386
parent5dad1227c5c8a14641aaeb78cdd423d584890c24 (diff)
downloadegawk-0f9d4355a03d000938d87d71ba62f0ac2717334a.tar.gz
egawk-0f9d4355a03d000938d87d71ba62f0ac2717334a.tar.bz2
egawk-0f9d4355a03d000938d87d71ba62f0ac2717334a.zip
Make lint checking for "no effect" case smarter about line numbers.
-rw-r--r--ChangeLog5
-rw-r--r--awkgram.c18
-rw-r--r--awkgram.y18
-rw-r--r--test/ChangeLog4
-rw-r--r--test/noeffect.awk1
-rw-r--r--test/noeffect.ok1
6 files changed, 39 insertions, 8 deletions
diff --git a/ChangeLog b/ChangeLog
index 59fb425d..3f186326 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2017-05-20 Arnold D. Robbins <arnold@skeeve.com>
+
+ * awkgram.y (add_lint): Make ``no effect'' check smarter about
+ reporting line numbers.
+
2017-05-01 Arnold D. Robbins <arnold@skeeve.com>
* awkgram.y (nextc): Fix to change of 2017-04-24 such that
diff --git a/awkgram.c b/awkgram.c
index 1d06c4d9..4325e77d 100644
--- a/awkgram.c
+++ b/awkgram.c
@@ -8324,12 +8324,22 @@ add_lint(INSTRUCTION *list, LINTTYPE linttype)
case LINT_no_effect:
if (list->lasti->opcode == Op_pop && list->nexti != list->lasti) {
- for (ip = list->nexti; ip->nexti != list->lasti; ip = ip->nexti)
- ;
+ int line = 0;
+
+ // Get down to the last instruction (FIXME: why?)
+ for (ip = list->nexti; ip->nexti != list->lasti; ip = ip->nexti) {
+ // along the way track line numbers, we will use the line
+ // closest to the opcode if that opcode doesn't have one
+ if (ip->source_line != 0)
+ line = ip->source_line;
+ }
if (do_lint) { /* compile-time warning */
- if (isnoeffect(ip->opcode))
- lintwarn_ln(ip->source_line, ("statement may have no effect"));
+ if (isnoeffect(ip->opcode)) {
+ if (ip->source_line != 0)
+ line = ip->source_line;
+ lintwarn_ln(line, ("statement may have no effect"));
+ }
}
if (ip->opcode == Op_push) { /* run-time warning */
diff --git a/awkgram.y b/awkgram.y
index b72d1c82..e4f5bab0 100644
--- a/awkgram.y
+++ b/awkgram.y
@@ -5904,12 +5904,22 @@ add_lint(INSTRUCTION *list, LINTTYPE linttype)
case LINT_no_effect:
if (list->lasti->opcode == Op_pop && list->nexti != list->lasti) {
- for (ip = list->nexti; ip->nexti != list->lasti; ip = ip->nexti)
- ;
+ int line = 0;
+
+ // Get down to the last instruction (FIXME: why?)
+ for (ip = list->nexti; ip->nexti != list->lasti; ip = ip->nexti) {
+ // along the way track line numbers, we will use the line
+ // closest to the opcode if that opcode doesn't have one
+ if (ip->source_line != 0)
+ line = ip->source_line;
+ }
if (do_lint) { /* compile-time warning */
- if (isnoeffect(ip->opcode))
- lintwarn_ln(ip->source_line, ("statement may have no effect"));
+ if (isnoeffect(ip->opcode)) {
+ if (ip->source_line != 0)
+ line = ip->source_line;
+ lintwarn_ln(line, ("statement may have no effect"));
+ }
}
if (ip->opcode == Op_push) { /* run-time warning */
diff --git a/test/ChangeLog b/test/ChangeLog
index 2ef21c6f..2942f7be 100644
--- a/test/ChangeLog
+++ b/test/ChangeLog
@@ -1,3 +1,7 @@
+2017-05-20 Arnold D. Robbins <arnold@skeeve.com>
+
+ * noeffect.awk, noeffect.ok: Updated after code change.
+
2017-05-01 Aharon Robbins <aharon.robbins@intel.com>
* Makefile.am (sourcesplit): New test.
diff --git a/test/noeffect.awk b/test/noeffect.awk
index b67a5c57..472c408e 100644
--- a/test/noeffect.awk
+++ b/test/noeffect.awk
@@ -2,4 +2,5 @@ BEGIN {
s == "hello, world";
s + 1
;;
+ "s" 1
}
diff --git a/test/noeffect.ok b/test/noeffect.ok
index e9bed995..6a0cc752 100644
--- a/test/noeffect.ok
+++ b/test/noeffect.ok
@@ -1,4 +1,5 @@
gawk: noeffect.awk:2: warning: statement may have no effect
gawk: noeffect.awk:3: warning: statement may have no effect
+gawk: noeffect.awk:5: warning: statement may have no effect
gawk: noeffect.awk:2: warning: reference to uninitialized variable `s'
gawk: noeffect.awk:3: warning: reference to uninitialized variable `s'