[commit: ghc] master: Fix identifier parsing in hp2ps (0c823af)

git at git.haskell.org git at git.haskell.org
Sat Aug 29 11:26:03 UTC 2015


Repository : ssh://git@git.haskell.org/ghc

On branch  : master
Link       : http://ghc.haskell.org/trac/ghc/changeset/0c823af84d80ac103528e54eda8e1c6bdf2bea69/ghc

>---------------------------------------------------------------

commit 0c823af84d80ac103528e54eda8e1c6bdf2bea69
Author: Yuras Shumovich <shumovichy at gmail.com>
Date:   Sat Aug 29 12:25:14 2015 +0200

    Fix identifier parsing in hp2ps
    
    Now identifiers can start with a package key, which is a hash, so they
    may also start with a digit. Identifiers always appear at the beginning
    of a line, and numbers never appear here, soit's safe to allow
    identifiers to start with a digit.
    
    Test Plan: `concprog002` passes under `threaded2_hT` way
    
    Reviewers: austin, bgamari, thomie
    
    Reviewed By: austin, bgamari, thomie
    
    Differential Revision: https://phabricator.haskell.org/D1175
    
    GHC Trac Issues: #10661


>---------------------------------------------------------------

0c823af84d80ac103528e54eda8e1c6bdf2bea69
 testsuite/tests/concurrent/prog002/all.T |  1 -
 utils/hp2ps/HpFile.c                     | 44 +++++++++++++++++---------------
 2 files changed, 23 insertions(+), 22 deletions(-)

diff --git a/testsuite/tests/concurrent/prog002/all.T b/testsuite/tests/concurrent/prog002/all.T
index 5eb6238..54613a7 100644
--- a/testsuite/tests/concurrent/prog002/all.T
+++ b/testsuite/tests/concurrent/prog002/all.T
@@ -11,7 +11,6 @@ else:
 
 test('concprog002',
      [only_ways(['threaded2','threaded2_hT']),
-      expect_broken_for(10661, ['threaded2_hT']),
       extra_ways(ways),
       exit_code(1),
       when(fast(), skip),
diff --git a/utils/hp2ps/HpFile.c b/utils/hp2ps/HpFile.c
index 9459247..12ef8d6 100644
--- a/utils/hp2ps/HpFile.c
+++ b/utils/hp2ps/HpFile.c
@@ -35,7 +35,7 @@ static boolish insample = 0;			/* true when in sample  */
 static floatish lastsample;			/* the last sample time */
 
 static void GetHpLine PROTO((FILE *));		/* forward */
-static void GetHpTok  PROTO((FILE *));		/* forward */
+static void GetHpTok  PROTO((FILE *, int));	/* forward */
 
 static struct entry *GetEntry PROTO((char *));	/* forward */
 
@@ -77,7 +77,7 @@ GetHpFile(FILE *infp)
     linenum = 1;
     lastsample = 0.0;
 
-    GetHpTok(infp);
+    GetHpTok(infp, 1);
 
     while (endfile == 0) {
 	GetHpLine(infp);
@@ -122,49 +122,49 @@ GetHpLine(FILE *infp)
 
     switch (thetok) {
     case JOB_TOK:
-	GetHpTok(infp);
+	GetHpTok(infp, 0);
 	if (thetok != STRING_TOK) {
 	    Error("%s, line %d: string must follow JOB", hpfile, linenum);
         }
 	jobstring = thestring;
 	gotjob = 1;
-        GetHpTok(infp);
+        GetHpTok(infp, 1);
 	break;
 
     case DATE_TOK:
-	GetHpTok(infp);
+	GetHpTok(infp, 0);
 	if (thetok != STRING_TOK) {
 	    Error("%s, line %d: string must follow DATE", hpfile, linenum);
         }
 	datestring = thestring;
 	gotdate = 1;
-        GetHpTok(infp);
+        GetHpTok(infp, 1);
 	break;
 
     case SAMPLE_UNIT_TOK:
-	GetHpTok(infp);
+	GetHpTok(infp, 0);
 	if (thetok != STRING_TOK) {
 	    Error("%s, line %d: string must follow SAMPLE_UNIT", hpfile, 
 	          linenum);
         }
 	sampleunitstring = thestring;
 	gotsampleunit = 1;
-        GetHpTok(infp);
+        GetHpTok(infp, 1);
 	break;
 
     case VALUE_UNIT_TOK:
-        GetHpTok(infp);
+        GetHpTok(infp, 0);
 	if (thetok != STRING_TOK) {
 	    Error("%s, line %d: string must follow VALUE_UNIT", hpfile, 
 	          linenum);
         }
 	valueunitstring = thestring;
 	gotvalueunit = 1;
-        GetHpTok(infp);
+        GetHpTok(infp, 1);
 	break;
 
     case MARK_TOK:
-	GetHpTok(infp);
+	GetHpTok(infp, 0);
         if (thetok != FLOAT_TOK) {
             Error("%s, line %d, floating point number must follow MARK",
 	          hpfile, linenum);
@@ -182,12 +182,12 @@ GetHpLine(FILE *infp)
 	    }
 	}
 	markmap[ nmarks++ ] = thefloatish; 
-        GetHpTok(infp);
+        GetHpTok(infp, 1);
         break;
 
     case BEGIN_SAMPLE_TOK: 
 	insample = 1;
-	GetHpTok(infp); 
+	GetHpTok(infp, 0);
 	if (thetok != FLOAT_TOK) {
 	    Error("%s, line %d, floating point number must follow BEGIN_SAMPLE",	          hpfile, linenum);
 	}
@@ -207,28 +207,28 @@ GetHpLine(FILE *infp)
 	    }
 	}
 	samplemap[ nsamples ] = thefloatish;
-	GetHpTok(infp);
+	GetHpTok(infp, 1);
 	break;
 
     case END_SAMPLE_TOK: 
 	insample = 0;
-	GetHpTok(infp); 
+	GetHpTok(infp, 0);
 	if (thetok != FLOAT_TOK) {
 	    Error("%s, line %d: floating point number must follow END_SAMPLE", 
                   hpfile, linenum);
 	}
         nsamples++;
-	GetHpTok(infp);
+	GetHpTok(infp, 1);
 	break;
 
     case IDENTIFIER_TOK:
-	GetHpTok(infp);
+	GetHpTok(infp, 0);
 	if (thetok != INTEGER_TOK) {
 	    Error("%s, line %d: integer must follow identifier", hpfile, 
                   linenum);
 	}
         StoreSample(GetEntry(theident), nsamples, thefloatish);
-	GetHpTok(infp); 
+	GetHpTok(infp, 1);
         break;
 
     case EOF_TOK:
@@ -274,10 +274,12 @@ TokenToString(token t)
  *	the corresponding value is also assigned to "theinteger"
  *	or "thefloatish" as appropriate; in the case of identifiers 
  *	it is assigned to "theident".
+ *
+ *	startline argument should be true for the first token on a line
  */
 
 static void
-GetHpTok(FILE *infp)
+GetHpTok(FILE *infp, int startline)
 {
 
     while (isspace(ch)) {		/* skip whitespace */
@@ -290,7 +292,8 @@ GetHpTok(FILE *infp)
 	return;
     }
 
-    if (isdigit(ch)) {
+    if (isdigit(ch) && !startline) {
+	/* there should not be numbers at start of line */
 	thetok = GetNumber(infp);
 	return;
     } else if (ch == '\"') {
@@ -298,7 +301,6 @@ GetHpTok(FILE *infp)
 	thetok = STRING_TOK;
 	return;
     } else if (IsIdChar(ch)) {
-	ASSERT(! (isdigit(ch)));	/* ch can't be a digit here */
 	GetIdent(infp);
 	if (!isupper((int)theident[0])) {
 	    thetok = IDENTIFIER_TOK;



More information about the ghc-commits mailing list