aboutsummaryrefslogtreecommitdiff
path: root/gcc/m2/gm2-compiler/M2StackSpell.mod
diff options
context:
space:
mode:
Diffstat (limited to 'gcc/m2/gm2-compiler/M2StackSpell.mod')
-rw-r--r--gcc/m2/gm2-compiler/M2StackSpell.mod152
1 files changed, 135 insertions, 17 deletions
diff --git a/gcc/m2/gm2-compiler/M2StackSpell.mod b/gcc/m2/gm2-compiler/M2StackSpell.mod
index 7a072ae..06ce923 100644
--- a/gcc/m2/gm2-compiler/M2StackSpell.mod
+++ b/gcc/m2/gm2-compiler/M2StackSpell.mod
@@ -23,15 +23,17 @@ IMPLEMENTATION MODULE M2StackSpell ;
FROM SymbolTable IMPORT NulSym, IsModule, IsDefImp, IsRecord,
IsEnumeration, IsProcedure, GetNth,
- GetSymName, GetSym, GetLocalSym,
- UnknownReported,
+ GetSymName, GetSym, GetLocalSym, GetScope,
+ UnknownReported, IsUnknown,
+ GetUnknownOnImport, GetUnknownDeclScope,
+ ForeachExportedDo,
ForeachProcedureDo, ForeachLocalSymDo,
ForeachFieldEnumerationDo ;
FROM SymbolKey IMPORT PerformOperation ;
FROM DynamicStrings IMPORT InitStringCharStar, InitString, Mark, string, ConCat ;
FROM FormatStrings IMPORT Sprintf1, Sprintf2, Sprintf3 ;
-FROM NameKey IMPORT KeyToCharStar ;
+FROM NameKey IMPORT KeyToCharStar, NulName ;
FROM M2MetaError IMPORT MetaErrorStringT0 ;
FROM M2StackWord IMPORT StackOfWord, PushWord, PopWord,
@@ -39,6 +41,7 @@ FROM M2StackWord IMPORT StackOfWord, PushWord, PopWord,
NoOfItemsInStackWord, PeepWord ;
FROM CDataTypes IMPORT ConstCharStar ;
+FROM M2Batch IMPORT GetModuleNo ;
IMPORT m2spellcheck ;
FROM m2spellcheck IMPORT Candidates ;
@@ -97,6 +100,60 @@ END GetRecordField ;
(*
+ CandidatePushName - push a symbol name to the candidate list.
+*)
+
+PROCEDURE CandidatePushName (cand: Candidates; sym: CARDINAL) ;
+VAR
+ str: String ;
+BEGIN
+ str := InitStringCharStar (KeyToCharStar (GetSymName (sym))) ;
+ m2spellcheck.Push (cand, string (str)) ;
+ INC (PushCount)
+END CandidatePushName ;
+
+
+(*
+ GetDefModuleSpellHint - return a string describing a spelling
+ hint for the definition module name
+ similiar to defimp. The premise is that
+ defimp has been misspelt. NIL is returned
+ if no hint can be given.
+*)
+
+PROCEDURE GetDefModuleSpellHint (defimp: CARDINAL) : String ;
+VAR
+ i : CARDINAL ;
+ sym : CARDINAL ;
+ cand : Candidates ;
+ misspell,
+ content : ConstCharStar ;
+ HintStr : String ;
+BEGIN
+ HintStr := NIL ;
+ IF GetSymName (defimp) # NulName
+ THEN
+ misspell := KeyToCharStar (GetSymName (defimp)) ;
+ i := 1 ;
+ sym := GetModuleNo (i) ;
+ cand := m2spellcheck.InitCandidates () ;
+ WHILE sym # NulSym DO
+ IF sym # defimp
+ THEN
+ CandidatePushName (cand, sym)
+ END ;
+ INC (i) ;
+ sym := GetModuleNo (i)
+ END ;
+ content := m2spellcheck.FindClosestCharStar (cand, misspell) ;
+ HintStr := BuildHintStr (HintStr, content) ;
+ m2spellcheck.KillCandidates (cand)
+ END ;
+ RETURN AddPunctuation (HintStr, '?')
+END GetDefModuleSpellHint ;
+
+
+(*
Push - push a scope onto the spelling stack.
sym might be a ModSym, DefImpSym or a varsym
of a record type denoting a with statement.
@@ -124,8 +181,9 @@ VAR
PushCount : CARDINAL ;
PushCandidate: Candidates ;
+
(*
- PushName -
+ PushName - push a name to the candidate vec.
*)
PROCEDURE PushName (sym: CARDINAL) ;
@@ -184,6 +242,30 @@ END PushCandidates ;
(*
+ BuildHintStr - create the did you mean hint and return it
+ if HintStr is NIL. Otherwise append a hint
+ to HintStr. If content is NIL then return NIL.
+*)
+
+PROCEDURE BuildHintStr (HintStr: String; content: ConstCharStar) : String ;
+VAR
+ str: String ;
+BEGIN
+ IF content # NIL
+ THEN
+ str := InitStringCharStar (content) ;
+ IF HintStr = NIL
+ THEN
+ RETURN Sprintf1 (Mark (InitString (", did you mean %s")), str)
+ ELSE
+ RETURN Sprintf2 (Mark (InitString ("%s or %s")), HintStr, str)
+ END
+ END ;
+ RETURN NIL
+END BuildHintStr ;
+
+
+(*
CheckForHintStr - lookup a spell hint matching misspelt. If one exists
then append it to HintStr. Return HintStr.
*)
@@ -193,7 +275,6 @@ PROCEDURE CheckForHintStr (sym: CARDINAL;
VAR
cand : Candidates ;
content: ConstCharStar ;
- str : String ;
BEGIN
IF IsModule (sym) OR IsDefImp (sym) OR IsProcedure (sym) OR
IsRecord (sym) OR IsEnumeration (sym)
@@ -201,21 +282,12 @@ BEGIN
cand := m2spellcheck.InitCandidates () ;
IF PushCandidates (cand, sym) > 1
THEN
- content := m2spellcheck.FindClosestCharStar (cand, string (misspelt)) ;
+ content := m2spellcheck.FindClosestCharStar (cand, string (misspelt))
ELSE
content := NIL
END ;
m2spellcheck.KillCandidates (cand) ;
- IF content # NIL
- THEN
- str := InitStringCharStar (content) ;
- IF HintStr = NIL
- THEN
- RETURN Sprintf1 (Mark (InitString (", did you mean %s")), str)
- ELSE
- RETURN Sprintf2 (Mark (InitString ("%s or %s")), HintStr, str)
- END
- END
+ HintStr := BuildHintStr (HintStr, content)
END ;
RETURN HintStr
END CheckForHintStr ;
@@ -241,6 +313,52 @@ END AddPunctuation ;
*)
PROCEDURE GetSpellHint (unknown: CARDINAL) : String ;
+BEGIN
+ IF IsUnknown (unknown) AND
+ GetUnknownOnImport (unknown) AND
+ (GetUnknownDeclScope (unknown) # GetScope (unknown))
+ THEN
+ (* It was created during an import statement. *)
+ RETURN GetExportedSpellHint (unknown, GetUnknownDeclScope (unknown))
+ END ;
+ RETURN GetScopeSpellHint (unknown)
+END GetSpellHint ;
+
+
+(*
+ GetExportedSpellHint - return a string describing a spelling hint
+ using the module exported identifiers.
+*)
+
+PROCEDURE GetExportedSpellHint (unknown, module: CARDINAL) : String ;
+VAR
+ content : ConstCharStar ;
+ misspell,
+ HintStr : String ;
+BEGIN
+ misspell := InitStringCharStar (KeyToCharStar (GetSymName (unknown))) ;
+ HintStr := NIL ;
+ PushCount := 0 ;
+ PushCandidate := m2spellcheck.InitCandidates () ;
+ ForeachExportedDo (module, PushName) ;
+ ForeachLocalSymDo (module, PushName) ;
+ IF PushCount > 0
+ THEN
+ content := m2spellcheck.FindClosestCharStar (PushCandidate,
+ string (misspell)) ;
+ HintStr := BuildHintStr (HintStr, content)
+ END ;
+ m2spellcheck.KillCandidates (PushCandidate) ;
+ RETURN AddPunctuation (HintStr, '?')
+END GetExportedSpellHint ;
+
+
+(*
+ GetScopeSpellHint - return a string describing a spelling hint
+ using the visible scopes.
+*)
+
+PROCEDURE GetScopeSpellHint (unknown: CARDINAL) : String ;
VAR
i, n : CARDINAL ;
sym : CARDINAL ;
@@ -262,7 +380,7 @@ BEGIN
INC (i)
END ;
RETURN AddPunctuation (HintStr, '?')
-END GetSpellHint ;
+END GetScopeSpellHint ;
(*