|
From: <got...@us...> - 2009-09-21 15:06:02
|
Revision: 351
http://scstudio.svn.sourceforge.net/scstudio/?rev=351&view=rev
Author: gotthardp
Date: 2009-09-21 15:05:55 +0000 (Mon, 21 Sep 2009)
Log Message:
-----------
Enhanced z120 error reporting function.
Modified Paths:
--------------
trunk/src/data/Z120/Context_Impl.h
trunk/src/data/Z120/display_error.cpp
trunk/src/data/Z120/display_error.h
trunk/tests/z120_test/z120_test42.mpr.result
trunk/tests/z120_test/z120_test50.mpr.result
trunk/tests/z120_test/z120_test53.mpr.result
trunk/tests/z120_test/z120_test56.mpr.result
trunk/tests/z120_test/z120_test58.mpr.result
trunk/tests/z120_test/z120_test59.mpr.result
Property Changed:
----------------
trunk/src/data/Z120/Context_Impl.h
trunk/src/data/Z120/display_error.cpp
trunk/src/data/Z120/display_error.h
Modified: trunk/src/data/Z120/Context_Impl.h
===================================================================
--- trunk/src/data/Z120/Context_Impl.h 2009-09-21 11:52:58 UTC (rev 350)
+++ trunk/src/data/Z120/Context_Impl.h 2009-09-21 15:05:55 UTC (rev 351)
@@ -13,7 +13,7 @@
*
* Copyright (c) 2008 Matus Madzin <go...@ma...>
*
- * $Id: Context_Impl.h 332 2009-09-15 14:13:20Z madzin $
+ * $Id$
*/
/*
@@ -90,6 +90,6 @@
void create_future_connections_fun(struct Context* context, SuccessorNode* succ);
+#endif // _Context_Impl_
-#endif
-
+// $Id$
Property changes on: trunk/src/data/Z120/Context_Impl.h
___________________________________________________________________
Added: svn:keywords
+ Id
Added: svn:eol-style
+ native
Modified: trunk/src/data/Z120/display_error.cpp
===================================================================
--- trunk/src/data/Z120/display_error.cpp 2009-09-21 11:52:58 UTC (rev 350)
+++ trunk/src/data/Z120/display_error.cpp 2009-09-21 15:05:55 UTC (rev 351)
@@ -1,248 +1,220 @@
#include "data/Z120/display_error.h"
#include "data/Z120/Context_Impl.h"
+// Implementation based on src/runtime/C/antlr3baserecognizer.c, display()
+
void reportError (pANTLR3_BASE_RECOGNIZER recognizer)
+{
+ if (recognizer->state->errorRecovery == ANTLR3_TRUE)
{
- if (recognizer->state->errorRecovery == ANTLR3_TRUE)
- {
- return;
- }
+ return;
+ }
- // Signal we are in error recovery now
- //
- recognizer->state->errorRecovery = ANTLR3_TRUE;
+ // Signal we are in error recovery now
+ recognizer->state->errorRecovery = ANTLR3_TRUE;
- // Indicate this recognizer had an error while processing.
- //
- recognizer->state->errorCount++;
+ // Indicate this recognizer had an error while processing.
+ recognizer->state->errorCount++;
- // Call the error display routine
- //
- recognizer->displayRecognitionError(recognizer, recognizer->state->tokenNames);
+ // Call the error display routine
+ recognizer->displayRecognitionError(recognizer, recognizer->state->tokenNames);
+}
+void display_error(struct Context* context, pANTLR3_BASE_RECOGNIZER recognizer, pANTLR3_UINT8 *tokenNames)
+{
+ stringize report;
+ // Retrieve some info for easy reading.
+ pANTLR3_EXCEPTION ex = recognizer->state->exception;
+
+ // See if there is a 'filename' we can use
+ if (ex->streamName == NULL)
+ {
+ if (((pANTLR3_COMMON_TOKEN)(ex->token))->type == ANTLR3_TOKEN_EOF)
+ {
+ report << "<EOF>";
+ }
+ else
+ {
+ report << "<unknown>";
+ }
}
+ else
+ {
+ pANTLR3_STRING ftext = ex->streamName->to8(ex->streamName);
+ char* last_slash = (char *)ftext->chars;
+ // strip file path
+ for(char *ch = (char *)ftext->chars; *ch != 0; ch++)
+ {
+ if(*ch == '\\' || *ch == '/')
+ last_slash = ch;
+ }
-//void scstudio_error_reporting(pANTLR3_BASE_RECOGNIZER recognizer, pANTLR3_UINT8 *tokenNames)
-void display_error(struct Context* context, pANTLR3_BASE_RECOGNIZER recognizer, pANTLR3_UINT8 *tokenNames)
-{
-// pANTLR3_PARSER parser;
-// pANTLR3_TREE_PARSER tparser;
-// pANTLR3_INT_STREAM is;
- pANTLR3_STRING ttext;
- pANTLR3_STRING ftext;
- pANTLR3_EXCEPTION ex;
-// pANTLR3_COMMON_TOKEN theToken;
-// pANTLR3_BASE_TREE theBaseTree;
-// pANTLR3_COMMON_TREE theCommonTree;
+ report << last_slash+1
+ << "[" << recognizer->state->exception->line
+ << "," << recognizer->state->exception->charPositionInLine << "]";
+ }
- // Retrieve some info for easy reading.
- //
- ex = recognizer->state->exception;
- ttext = NULL;
+ report << " ";
- // See if there is a 'filename' we can use
- //
- if (ex->streamName == NULL)
+ // Note that in the general case, errors thrown by tree parsers indicate a problem
+ // with the output of the parser or with the tree grammar itself. The job of the parser
+ // is to produce a perfect (in traversal terms) syntactically correct tree, so errors
+ // at that stage should really be semantic errors that your own code determines and handles
+ // in whatever way is appropriate.
+ switch (ex->type)
+ {
+ case ANTLR3_UNWANTED_TOKEN_EXCEPTION:
+
+ // Indicates that the recognizer was fed a token which seesm to be
+ // spurious input. We can detect this when the token that follows
+ // this unwanted token would normally be part of the syntactically
+ // correct stream. Then we can see that the token we are looking at
+ // is just something that should not be there and throw this exception.
+ if (tokenNames == NULL)
+ {
+ report << "Unwanted input";
+ }
+ else
+ {
+ if (ex->expecting == ANTLR3_TOKEN_EOF)
{
- if (((pANTLR3_COMMON_TOKEN)(ex->token))->type == ANTLR3_TOKEN_EOF)
- {
- context->z->print_report(RS_ERROR, stringize() << "-end of input-(");
- }
- else
- {
- context->z->print_report(RS_ERROR,stringize() << "-unknown source-(");
- }
+ report << "Unwanted input: expected <EOF>";
}
else
{
- ftext = ex->streamName->to8(ex->streamName);
- context->z->print_report(RS_ERROR, stringize() << (char*) ftext->chars << "(Line: "
- << recognizer->state->exception->line << ", Line position: "
- << recognizer->state->exception->charPositionInLine << ")");
+ report << "Unwanted input: expected " << (char*)(tokenNames[ex->expecting]);
}
+ }
+ break;
- // should be as helpful as possible for grammar developers and serve as an example
- // of what you can do with each exception type. In general, when you make up your
- // 'real' handler, you should debug the routine with all possible errors you expect
- // which will then let you be as specific as possible about all circumstances.
- //
- // Note that in the general case, errors thrown by tree parsers indicate a problem
- // with the output of the parser or with the tree grammar itself. The job of the parser
- // is to produce a perfect (in traversal terms) syntactically correct tree, so errors
- // at that stage should really be semantic errors that your own code determines and handles
- // in whatever way is appropriate.
- //
- switch (ex->type)
+ case ANTLR3_MISSING_TOKEN_EXCEPTION:
+
+ // Indicates that the recognizer detected that the token we just
+ // hit would be valid syntactically if preceeded by a particular
+ // token. Perhaps a missing ';' at line end or a missing ',' in an
+ // expression list, and such like.
+ if (tokenNames == NULL)
+ {
+ report << "Missing token (" << ex->expecting << ")";
+ }
+ else
+ {
+ if (ex->expecting == ANTLR3_TOKEN_EOF)
{
- case ANTLR3_UNWANTED_TOKEN_EXCEPTION:
+ report << "Missing <EOF>";
+ }
+ else
+ {
+ report << "Missing " << (char*)(tokenNames[ex->expecting]);
+ }
+ }
+ break;
- // Indicates that the recognizer was fed a token which seesm to be
- // spurious input. We can detect this when the token that follows
- // this unwanted token would normally be part of the syntactically
- // correct stream. Then we can see that the token we are looking at
- // is just something that should not be there and throw this exception.
- //
- if (tokenNames == NULL)
- {
- context->z->print_report(RS_ERROR, stringize() << " Extraneous input...");
- }
- else
- {
- if (ex->expecting == ANTLR3_TOKEN_EOF)
- {
- context->z->print_report(RS_ERROR, stringize() << "Extraneous input - expected <EOF>\n");
- }
- else
- {
- context->z->print_report(RS_ERROR, stringize() << " Error " << recognizer->state->exception->type << ": " << "Extraneous input - expected " << (char*) (tokenNames[ex->expecting]) << "...\n");
- }
- }
- break;
+ case ANTLR3_RECOGNITION_EXCEPTION:
- case ANTLR3_MISSING_TOKEN_EXCEPTION:
+ // Indicates that the recognizer received a token
+ // in the input that was not predicted. This is the basic exception type
+ // from which all others are derived. So we assume it was a syntax error.
+ // You may get this if there are not more tokens and more are needed
+ // to complete a parse for instance.
+ report << "Syntax error";
+ break;
- // Indicates that the recognizer detected that the token we just
- // hit would be valid syntactically if preceeded by a particular
- // token. Perhaps a missing ';' at line end or a missing ',' in an
- // expression list, and such like.
- //
- if (tokenNames == NULL)
- {
- context->z->print_report(RS_ERROR, stringize() << "Missing token (" << ex->expecting << ")...");
- }
- else
- {
- if (ex->expecting == ANTLR3_TOKEN_EOF)
- {
- context->z->print_report(RS_ERROR, stringize() << "Missing <EOF>");
- }
- else
- {
- context->z->print_report(RS_ERROR, stringize() << " Error " << recognizer->state->exception->type << ": " << "Missing " << (char*) (tokenNames[ex->expecting]));
- }
- }
- break;
- case ANTLR3_RECOGNITION_EXCEPTION:
+ case ANTLR3_MISMATCHED_TOKEN_EXCEPTION:
- // Indicates that the recognizer received a token
- // in the input that was not predicted. This is the basic exception type
- // from which all others are derived. So we assume it was a syntax error.
- // You may get this if there are not more tokens and more are needed
- // to complete a parse for instance.
- //
- context->z->print_report(RS_ERROR, stringize() << "syntax error...\n");
- break;
+ // We were expecting to see one thing and got another. This is the
+ // most common error if we coudl not detect a missing or unwanted token.
+ // Here you can spend your efforts to
+ // derive more useful error messages based on the expected
+ // token set and the last token and so on. The error following
+ // bitmaps do a good job of reducing the set that we were looking
+ // for down to something small. Knowing what you are parsing may be
+ // able to allow you to be even more specific about an error.
+ if (tokenNames == NULL)
+ {
+ report << "Syntax error";
+ }
+ else
+ {
+ if (ex->expecting == ANTLR3_TOKEN_EOF)
+ {
+ report << "Expected <EOF>";
+ }
+ else
+ {
+ report << "Expected " << tokenNames[ex->expecting];
+ }
+ }
+ break;
- case ANTLR3_MISMATCHED_TOKEN_EXCEPTION:
+ case ANTLR3_NO_VIABLE_ALT_EXCEPTION:
- // We were expecting to see one thing and got another. This is the
- // most common error if we coudl not detect a missing or unwanted token.
- // Here you can spend your efforts to
- // derive more useful error messages based on the expected
- // token set and the last token and so on. The error following
- // bitmaps do a good job of reducing the set that we were looking
- // for down to something small. Knowing what you are parsing may be
- // able to allow you to be even more specific about an error.
- //
- if (tokenNames == NULL)
- {
- context->z->print_report(RS_ERROR, stringize() << "syntax error...\n");
- }
- else
- {
- if (ex->expecting == ANTLR3_TOKEN_EOF)
- {
- context->z->print_report(RS_ERROR, stringize() << "expected <EOF>");
- }
- else
- {
- context->z->print_report(RS_ERROR, stringize() << " Error " << recognizer->state->exception->type << ": " << "expected " << tokenNames[ex->expecting] << "...");
- }
- }
- break;
- case ANTLR3_NO_VIABLE_ALT_EXCEPTION:
+ // We could not pick any alt decision from the input given
+ // so god knows what happened - however when you examine your grammar,
+ // you should. It means that at the point where the current token occurred
+ // that the DFA indicates nowhere to go from here.
+ report << "Cannot match to any predicted input";
+ break;
- // We could not pick any alt decision from the input given
- // so god knows what happened - however when you examine your grammar,
- // you should. It means that at the point where the current token occurred
- // that the DFA indicates nowhere to go from here.
- //
- context->z->print_report(RS_ERROR, stringize() << " Error " << recognizer->state->exception->type << ": " << " : cannot match to any predicted input...\n");
+ case ANTLR3_MISMATCHED_SET_EXCEPTION:
+ {
- break;
+ // This means we were able to deal with one of a set of
+ // possible tokens at this point, but we did not see any
+ // member of that set.
+ report << "Unexpected input";
- case ANTLR3_MISMATCHED_SET_EXCEPTION:
+ // What tokens could we have accepted at this point in the parse?
+ pANTLR3_BITSET errBits = antlr3BitsetLoad(ex->expectingSet);
+ ANTLR3_UINT32 numbits = errBits->numBits(errBits);
+ ANTLR3_UINT32 size = errBits->size(errBits);
- {
- ANTLR3_UINT32 count;
- ANTLR3_UINT32 bit;
- ANTLR3_UINT32 size;
- ANTLR3_UINT32 numbits;
- pANTLR3_BITSET errBits;
+ if (size > 0)
+ {
+ ANTLR3_UINT32 count = 0;
+ report << ": expected one of";
- // This means we were able to deal with one of a set of
- // possible tokens at this point, but we did not see any
- // member of that set.
- //
- context->z->print_report(RS_ERROR, stringize() << " : unexpected input...\n expected one of : ");
+ // However many tokens we could have dealt with here, it is usually
+ // not useful to print ALL of the set here. I arbitrarily chose 8
+ // here, but you should do whatever makes sense for you of course.
+ // No token number 0, so look for bit 1 and on.
+ for(ANTLR3_UINT32 bit = 1; bit < numbits && count < 8 && count < size; bit++)
+ {
+ // TODO: This doesn;t look right - should be asking if the bit is set!!
+ if (tokenNames[bit])
+ {
+ report << (count > 0 ? ", " : " ") << "<" << tokenNames[bit] << ">";
+ count++;
+ }
+ }
+ }
- // What tokens could we have accepted at this point in the
- // parse?
- //
- count = 0;
- errBits = antlr3BitsetLoad (ex->expectingSet);
- numbits = errBits->numBits (errBits);
- size = errBits->size (errBits);
+ break;
+ }
- if (size > 0)
- {
- // However many tokens we could have dealt with here, it is usually
- // not useful to print ALL of the set here. I arbitrarily chose 8
- // here, but you should do whatever makes sense for you of course.
- // No token number 0, so look for bit 1 and on.
- //
- for (bit = 1; bit < numbits && count < 8 && count < size; bit++)
- {
- // TODO: This doesn;t look right - should be asking if the bit is set!!
- //
+ case ANTLR3_EARLY_EXIT_EXCEPTION:
- if (tokenNames[bit])
- {
- context->z->print_report(RS_ERROR, stringize() << (count > 0 ? ", " : "") << tokenNames[bit]);
- count++;
- }
- }
- context->z->print_report(RS_ERROR, stringize() << "");
- }
- else
- {
- context->z->print_report(RS_ERROR, stringize() << "Actually dude, we didn't seem to be expecting anything here, or at least");
- context->z->print_report(RS_ERROR, stringize() << "I could not work out what I was expecting, like so many of us these days!");
- }
- }
- break;
+ // We entered a loop requiring a number of token sequences
+ // but found a token that ended that sequence earlier than
+ // we should have done.
+ report << "Missing elements";
+ break;
- case ANTLR3_EARLY_EXIT_EXCEPTION:
+ default:
- // We entered a loop requiring a number of token sequences
- // but found a token that ended that sequence earlier than
- // we should have done.
- //
- context->z->print_report(RS_ERROR, stringize() << " : missing elements...");
- break;
+ // We don't handle any other exceptions here, but you can
+ // if you wish. If we get an exception that hits this point
+ // then we are just going to report what we know about the
+ // token.
+ report << "Syntax not recognized";
+ break;
+ }
- default:
+ report << ".";
- // We don't handle any other exceptions here, but you can
- // if you wish. If we get an exception that hits this point
- // then we are just going to report what we know about the
- // token.
- //
- context->z->print_report(RS_ERROR, stringize() << " : syntax not recognized...");
- break;
- }
-
-
+ context->z->print_report(RS_ERROR, report);
}
+
+// $Id$
Property changes on: trunk/src/data/Z120/display_error.cpp
___________________________________________________________________
Added: svn:keywords
+ Id
Added: svn:eol-style
+ native
Modified: trunk/src/data/Z120/display_error.h
===================================================================
--- trunk/src/data/Z120/display_error.h 2009-09-21 11:52:58 UTC (rev 350)
+++ trunk/src/data/Z120/display_error.h 2009-09-21 15:05:55 UTC (rev 351)
@@ -15,4 +15,6 @@
}
#endif
-#endif
+#endif // _Z120Display_H
+
+// $Id$
Property changes on: trunk/src/data/Z120/display_error.h
___________________________________________________________________
Added: svn:keywords
+ Id
Added: svn:eol-style
+ native
Modified: trunk/tests/z120_test/z120_test42.mpr.result
===================================================================
--- trunk/tests/z120_test/z120_test42.mpr.result 2009-09-21 11:52:58 UTC (rev 350)
+++ trunk/tests/z120_test/z120_test42.mpr.result 2009-09-21 15:05:55 UTC (rev 351)
@@ -1,9 +1,5 @@
-z120_test42.mpr(Line: 11, Line position: 0)
- Error 3: : cannot match to any predicted input...
-
-z120_test42.mpr(Line: 30, Line position: 0)
- Error 3: : cannot match to any predicted input...
-
+z120_test42.mpr[11,0] Cannot match to any predicted input.
+z120_test42.mpr[30,0] Cannot match to any predicted input.
Warning 09: There is reference to nonexisted MSC
OK: z120_test42 is correct, should be correct
Modified: trunk/tests/z120_test/z120_test50.mpr.result
===================================================================
--- trunk/tests/z120_test/z120_test50.mpr.result 2009-09-21 11:52:58 UTC (rev 350)
+++ trunk/tests/z120_test/z120_test50.mpr.result 2009-09-21 15:05:55 UTC (rev 351)
@@ -1,6 +1,4 @@
-z120_test50.mpr(Line: 8, Line position: 4)
- Error 3: : cannot match to any predicted input...
-
+z120_test50.mpr[8,4] Cannot match to any predicted input.
Warning 08: There is reference to nonexisted node
Warning 09: There is reference to nonexisted MSC
Modified: trunk/tests/z120_test/z120_test53.mpr.result
===================================================================
--- trunk/tests/z120_test/z120_test53.mpr.result 2009-09-21 11:52:58 UTC (rev 350)
+++ trunk/tests/z120_test/z120_test53.mpr.result 2009-09-21 15:05:55 UTC (rev 351)
@@ -1,6 +1,4 @@
-z120_test53.mpr(Line: 7, Line position: 0)
- Error 3: : cannot match to any predicted input...
-
+z120_test53.mpr[7,0] Cannot match to any predicted input.
OK: z120_test53 is correct, should be correct
mscdocument z120_test53;
Modified: trunk/tests/z120_test/z120_test56.mpr.result
===================================================================
--- trunk/tests/z120_test/z120_test56.mpr.result 2009-09-21 11:52:58 UTC (rev 350)
+++ trunk/tests/z120_test/z120_test56.mpr.result 2009-09-21 15:05:55 UTC (rev 351)
@@ -1,13 +1,6 @@
-z120_test56.mpr(11) : error 3 : ()+ loopback of 217:4: ( 'inst' instance_item )+, at offset 0
- near [Index: 53 (Start: 159855249-Stop: 159855250) ='in', type<59> Line: 11 LinePos:0]
- : cannot match to any predicted input...
-z120_test56.mpr(11) : error 3 : ()+ loopback of 217:4: ( 'inst' instance_item )+, at offset 0
- near [Index: 53 (Start: 159855249-Stop: 159855250) ='in', type<59> Line: 11 LinePos:0]
- : cannot match to any predicted input...
-z120_test56.mpr(11) : error 3 : 368:1: event_definition : ( NAME ':' instance_event_list | instance_name_list ':' multi_instance_event_list );, at offset 14
- near [Index: 62 (Start: 159855263-Stop: 159855263) =';', type<26> Line: 11 LinePos:14]
- : cannot match to any predicted input...
+z120_test56.mpr[11,0] Cannot match to any predicted input.
Warning 05: There is complete message with only one event
+Warning 09: There is reference to nonexisted MSC
OK: z120_test56 is correct, should be correct
Modified: trunk/tests/z120_test/z120_test58.mpr.result
===================================================================
--- trunk/tests/z120_test/z120_test58.mpr.result 2009-09-21 11:52:58 UTC (rev 350)
+++ trunk/tests/z120_test/z120_test58.mpr.result 2009-09-21 15:05:55 UTC (rev 351)
@@ -1,9 +1,5 @@
-z120_test58.mpr(16) : error 10 : Missing token, at offset 9
- near [Index: 0 (Start: 0-Stop: 0) ='<missing ';'>', type<26> Line: 16 LinePos:9]
- : Missing ';'
-z120_test58.mpr(16) : error 9 : Extraneous token, at offset 9
- near [Index: 0 (Start: 0-Stop: 0) ='<missing ';'>', type<26> Line: 16 LinePos:9]
- : Extraneous input - expected ';' ...
+z120_test58.mpr[16,9] Missing ';'.
+z120_test58.mpr[16,9] Unwanted input: expected ';'.
Warning 11: Instance server does not have open any coregion
OK: z120_test58 is correct, should be correct
Modified: trunk/tests/z120_test/z120_test59.mpr.result
===================================================================
--- trunk/tests/z120_test/z120_test59.mpr.result 2009-09-21 11:52:58 UTC (rev 350)
+++ trunk/tests/z120_test/z120_test59.mpr.result 2009-09-21 15:05:55 UTC (rev 351)
@@ -1,6 +1,4 @@
-z120_test59.mpr(28) : error 9 : Extraneous token, at offset 0
- near [Index: 151 (Start: 140641322-Stop: 140641331) ='concurrent', type<102> Line: 28 LinePos:0]
- : Extraneous input - expected ';' ...
+z120_test59.mpr[28,0] Unwanted input: expected ';'.
Warning 11: Instance server does not have open any coregion
OK: z120_test59 is correct, should be correct
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|