NPGSCuspPre.mesa
Copyright Ó 1989 by Xerox Corporation. All rights reserved.
CuspPGS preprocessor to create errorMsg array
JKF February 6, 1989 3:33:17 pm PST
created by Dageforde  June 8, 1982 2:57 PM
last edited by Dageforde   29-Aug-88 18:22:54
edited by Dageforde   11-Nov-82 17:27:54
DIRECTORY
NPGSConDefs,
NPGSTypes;
NPGSCuspPre: CEDAR PROGRAM
IMPORTS NPGSConDefs
EXPORTS NPGSConDefs = {
Used: TYPE = NPGSTypes.Used;
TokenSeq: TYPE = NPGSTypes.TokenSeq;
TokensUsed: TYPE = NPGSTypes.TokensUsed;
tokensUsed: TokensUsed;
ErrorType: TYPE = NPGSTypes.ErrorType;
ErrSeq: TYPE = NPGSTypes.ErrSeq;
ErrorMsg: TYPE = NPGSTypes.ErrorMsg;
errorMsg: ErrorMsg ← NIL;
tokenIconExpr, tokenClose, tokenCopy, tokenMove, tokenSelect: CARDINAL;
prioritySize: CARDINAL = 30;
priorityMsg: ARRAY[1..prioritySize] OF ErrorType = [
MExpr, MOpd, MOpd, MOpd, MOpd,
MOpd, MOpd, MOpd, MOpd, MOpd,
MOpd, MOpd, MOpd, Stmt, MAgg,
IconExpr, MId, MId, MId, MDotLB,
MId, MTypeId, MFieldTypeId, MId, MTxt,
MCalled, MThe, MRArrow, MOptn, MSecs];
priorityToken: ARRAY [1..prioritySize] OF CARDINAL;
priorityStr: ARRAY [1..prioritySize] OF REF TEXT ← [
"Expr", "Disjunct", "Conjunct", "Negation", "Relation", "Str", "Sum", "Prod", "Factor", "Primary", "FunctionCall", "BuiltInVal", "Constant", "Statement", "Aggregate", "IconExpr", "DocObjExpr", "PathName", "IconContExpr", "Accessor", "BoundId", "IconType", "FieldType", "PropertyName", "PropertyValue", "RangeVarDecl", "RowExpr", "->", "OR", "SecOrSecs"];
CuspPreSetPriorityTokenArray: PUBLIC PROC [hashChain: NPGSTypes.HashChain] = {
does case matter? yes
LocateToken: PROC [string: REF TEXT] RETURNS [CARDINAL] = {
returns token corresponding to string
i, j: CARDINAL;
j ← hashChain[(string.length*256+(string[0]-0c)) MOD (NPGSTypes.symTabSize/4) + 1];
j ← hashChain[(string.length*256+(string[0].ORD)) MOD (NPGSTypes.symTabSize/4) + 1];
WHILE j # 0 DO
IF NPGSConDefs.symInfo[j].length = string.length THEN {
i ← j*NPGSTypes.tokenSize;
FOR k: CARDINAL IN [0..string.length) DO
IF NPGSConDefs.symTab[i+k]#string[k] THEN EXIT
REPEAT FINISHED => RETURN [j]
ENDLOOP
};
j ← NPGSConDefs.symInfo[j].link;
ENDLOOP;
RETURN [0]
}; -- LocateToken --
tokens go from 1 to totalTokens, but MakeTokenSeq makes 0-origin
array, so use totalTokens+1 as length
tokensUsed ← LOOPHOLE[makearray[totalTokens+1, SIZE[BOOLEAN]]];
tokensUsed ← NPGSConDefs.MakeTokenSeq[NPGSConDefs.totalTokens+1];
FOR i: CARDINAL IN [1..prioritySize] DO
r: REF TEXT ← priorityStr[i];
priorityToken[i] ← LocateToken[r];
ENDLOOP;
tokenIconExpr ← LocateToken["IconExpr"];
tokenClose ← LocateToken["CLOSE"];
tokenCopy ← LocateToken["COPY"];
tokenMove ← LocateToken["MOVE"];
tokenSelect ← LocateToken["SELECT"];
}; -- of InitPriorityToken --
CuspPreClearTokensUsedArray: PUBLIC PROC = {
tokensUsed ← ALL[FALSE];
FOR i: CARDINAL IN [1..NPGSConDefs.totalTokens] DO
tokensUsed[i] ← no ENDLOOP;
};
CuspPreClearErrorMsgArray: PUBLIC PROC = {
errorMsg ← NIL};
CuspPreGetErrorMsg: PUBLIC PROC [i: CARDINAL] RETURNS [NPGSTypes.ErrorType] = {
RETURN[errorMsg[i]];
};
CuspPreSetNextTokenUsed: PUBLIC PROC [token: CARDINAL] = {
tokensUsed[token] ← yes;
};
CuspPreSetHeaderUsed: PUBLIC PROC [token: CARDINAL] = {
tokensUsed[token] ← header;
};
CuspPreSetNextErrorMsgElement: PUBLIC PROC [state: CARDINAL] = {
i,j: CARDINAL;
IF errorMsg = NIL THEN errorMsg ← NPGSConDefs.MakeErrSeq[NPGSConDefs.sLim];
i ← 1;
WHILE i <= prioritySize DO
IF tokensUsed[j ← priorityToken[i]] = yes THEN {
errorMsg[state] ←
IF j = tokenIconExpr THEN
(IF tokensUsed[tokenClose] = header THEN CloseIconExpr
ELSE IF tokensUsed[tokenCopy] = header THEN CopyIconExpr
ELSE IF tokensUsed[tokenMove] = header THEN MoveIconExpr
ELSE IF tokensUsed[tokenSelect] = header THEN SelectIconExpr
ELSE MThe)
ELSE priorityMsg[i];
EXIT
};
i ← i + 1;
REPEAT
FINISHED => errorMsg[state] ← tl;
ENDLOOP;
};
CuspPreRenumber: PUBLIC PROC [lastntstate: CARDINAL, renumber: NPGSTypes.Renumber] = {
i,j: CARDINAL;
temp: ErrorType;
FOR i IN [2..lastntstate] DO
IF (j ← renumber[i]) # 0 THEN {
temp ← errorMsg[i];
errorMsg[i] ← errorMsg[j];
errorMsg[j] ← temp
};
ENDLOOP;
};
}.