errorpi.c revision 7c478bd95313f5f23a4c958a745db2134aa03244
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/* Copyright 1990 Sun Microsystems. Inc */
#pragma ident "%Z%%M% %I% %E% SMI"
/* - - - - -- - - - -- - - - - - - - - - - - - - - - - - - - - -*/
#include <stdio.h>
#include <ctype.h>
#include "error.h"
extern char *currentfilename;
static char *c_linenumber;
/*
* Attempt to handle error messages produced by pi (and by pc)
*
* problem #1: There is no file name available when a file does not
* use a #include; this will have to be given to error
* in the command line.
* problem #2: pi doesn't always tell you what line number
* a error refers to; for example during the tree
* walk phase of code generation and error detection,
* an error can refer to "variable foo in procedure bletch"
* without giving a line number
* problem #3: line numbers, when available, are attached to
* the source line, along with the source line itself
* These line numbers must be extracted, and
* the source line thrown away.
* problem #4: Some error messages produce more than one line number
* on the same message.
* There are only two (I think):
* %s undefined on line%s
* %s improperly used on line%s
* here, the %s makes line plural or singular.
*
* Here are the error strings used in pi version 1.2 that can refer
* to a file name or line number:
*
* Multiply defined label in case, lines %d and %d
* Goto %s from line %d is into a structured statement
* End matched %s on line %d
* Inserted keyword end matching %s on line %d
*
* Here are the general pi patterns recognized:
* define piptr == -.*^-.*
* define msg = .*
* define digit = [0-9]
* definename = .*
* define date_format letter*3 letter*3 (digit | (digit digit))
* (digit | (digit digit)):digit*2 digit*4
*
* {e,E} (piptr) (msg) Encounter an error during textual scan
* E {digit}* - (msg) Have an error message that refers to a new line
* E - msg Have an error message that refers to current
* function, program or procedure
* (date_format) (name): When switch compilation files
* ... (msg) When refer to the previous line
* 'In' ('procedure'|'function'|'program') (name):
* pi is now complaining about 2nd pass errors.
*
* Here is the output from a compilation
*
*
* 2 var i:integer;
* e --------------^--- Inserted ';'
* E 2 - All variables must be declared in one var part
* E 5 - Include filename must end in .i
* Mon Apr 21 15:56 1980 test.h:
* 2 begin
* e ------^--- Inserted ';'
* Mon Apr 21 16:06 1980 test.p:
* E 2 - Function type must be specified
* 6 procedure foo(var x:real);
* e ------^--- Inserted ';'
* In function bletch:
* E - No assignment to the function variable
* w - variable x is never used
* E 6 - foo is already defined in this block
* In procedure foo:
* w - variable x is neither used nor set
* 9 z : = 23;
* E --------------^--- Undefined variable
* 10 y = [1];
* e ----------------^--- Inserted ':'
* 13 z := 345.;
* e -----------------------^--- Digits required after decimal point
* E 10 - Constant set involved in non set context
* E 11 - Type clash: real is incompatible with integer
* ... Type of expression clashed with type of variable in assignment
* E 12 - Parameter type not identical to type of var parameter x of foo
* In program mung:
* w - variable y is never used
* w - type foo is never used
* w - function bletch is never used
* E - z undefined on lines 9 13
*/
char *Months[] = {
"Jan", "Feb", "Mar", "Apr", "May", "Jun",
"Jul", "Aug", "Sep", "Oct","Nov", "Dec",
0
};
char *Days[] = {
"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", 0
};
char *Piroutines[] = {
"program", "function", "procedure", 0
};
{
continue;
return(*string == '\0');
}
char *member;
{
return(TRUE);
}
return(FALSE);
}
int wordc;
char **wordv;
{
return(
(wordc == 5)
}
{
if (*string != '-')
return(FALSE);
string++;
if (*string != '^')
return(FALSE);
string++;
string++;
return(*string == '\0');
}
extern int wordc;
extern char **wordv;
Errorclass pi()
{
char **nwordv;
if (wordc < 2)
return (C_UNKNOWN);
) {
/*
* We have recognized a first pass error of the form:
* letter ------^---- message
*
* turn into an error message of the form:
*
* file line 'pascal errortype' letter \n |---- message
* or of the form:
* file line letter |---- message
* when there are strlen("(*[pi]") or more
* preceding '-' on the error pointer.
*
* Where the | is intended to be a down arrow, so that
* the pi error messages can be inserted above the
* line in error, instead of below. (All of the other
* langauges put thier messages before the source line,
* instead of after it as does pi.)
*
* where the pointer to the error has been truncated
* by 6 characters to account for the fact that
* the pointer points into a tab preceded input line.
*/
if (!longpiptr){
}
return(C_TRUE);
}
if ( (wordc >= 4)
){
/*
* Message of the form: letter linenumber - message
* Turn into form: filename linenumber letter - message
*/
wordc += 1;
return(C_TRUE);
}
if ( (wordc >= 3)
) {
/*
* Message of the form: letter - message
* This happens only when we are traversing the tree
* during the second pass of pi, and discover semantic
* errors.
*
* We have already (presumably) saved the header message
* and can now construct a nulled error message for the
* current file.
*
* Turns into a message of the form:
* filename (header) letter - message
*
* First, see if it is a message referring to more than
* one line number. Only of the form:
* %s undefined on line%s
* %s improperly used on line%s
*/
int wordindex;
){
wordindex++){
}
return(C_TRUE);
}
return(C_THISFILE);
}
/*
* have a continuation error message
* of the form: ... message
* Turn into form : filename linenumber message
*/
wordc += 1;
return(C_TRUE);
}
if( (wordc == 6)
){
/*
* Have message that tells us we have changed files
*/
return(C_SYNC);
}
if( (wordc == 3)
) {
return(C_SYNC);
}
/*
* now, check for just the line number followed by the text
*/
return(C_IGNORE);
}
/*
* Attempt to match messages refering to a line number
*
* Multiply defined label in case, lines %d and %d
* Goto %s from line %d is into a structured statement
* End matched %s on line %d
* Inserted keyword end matching %s on line %d
*/
multiple = structured = 0;
if (
){
wordc += 2;
if (!multiple)
return(C_TRUE);
return(C_TRUE);
}
return(C_UNKNOWN);
}