diff options
Diffstat (limited to 'gcc/m2')
| -rw-r--r-- | gcc/m2/ChangeLog | 54 | ||||
| -rw-r--r-- | gcc/m2/gm2-compiler/M2Comp.mod | 11 | ||||
| -rw-r--r-- | gcc/m2/gm2-compiler/M2MetaError.mod | 29 | ||||
| -rw-r--r-- | gcc/m2/gm2-compiler/M2Quads.mod | 59 | ||||
| -rw-r--r-- | gcc/m2/gm2-compiler/M2StackSpell.def | 10 | ||||
| -rw-r--r-- | gcc/m2/gm2-compiler/M2StackSpell.mod | 152 | ||||
| -rw-r--r-- | gcc/m2/gm2-compiler/P1Build.bnf | 17 | ||||
| -rw-r--r-- | gcc/m2/gm2-compiler/P1SymBuild.mod | 6 | ||||
| -rw-r--r-- | gcc/m2/gm2-compiler/SymbolTable.def | 18 | ||||
| -rw-r--r-- | gcc/m2/gm2-compiler/SymbolTable.mod | 80 | 
10 files changed, 343 insertions, 93 deletions
diff --git a/gcc/m2/ChangeLog b/gcc/m2/ChangeLog index 155c082..737ab12 100644 --- a/gcc/m2/ChangeLog +++ b/gcc/m2/ChangeLog @@ -1,3 +1,57 @@ +2025-11-02  Gaius Mulley  <gaiusmod2@gmail.com> + +	PR modula2/122499 +	* gm2-compiler/M2StackSpell.mod (PushName): Add comment. +	(GetSpellHint): Rewrite. +	(GetExportedSpellHint): New procedure function. +	(GetScopeSpellHint): New procedure function. +	* gm2-compiler/P1Build.bnf (IdentScope): Rewrite. +	(PossiblyExportIdent): Ditto. +	* gm2-compiler/P1SymBuild.mod (BuildImportInnerModule): Add +	parameter to AddNameToImportList. +	* gm2-compiler/SymbolTable.def (GetUnknownOnImport): New +	procedure function. +	(GetUnknownDeclScope): Ditto. +	(AddNameToScope): Add tok parameter. +	(AddNameToImportList): Ditto. +	* gm2-compiler/SymbolTable.mod (SymUndefined): New field +	declScope. +	New field onImport. +	(MakeObject): Add tok parameter. +	(FillInUnknownFields): Initialize declScope. +	Initialize onImport. +	(GetUnknownOnImport): New procedure function. +	(GetUnknownDeclScope): Ditto. +	(AddNameToScope): Pass tok to MakeObject. +	(AddNameToImportList): Add tok parameter. +	Pass tok to MakeObject. +	(GetDeclaredSym): Add parameters to FillInUnknownFields. +	(RequestSym): Ditto. +	(FetchUnknownFromModule): Ditto. +	(FetchUnknownFromDefImp): Ditto. +	(FetchUnknownFrom): Ditto. + +2025-10-30  Gaius Mulley  <gaiusmod2@gmail.com> + +	PR modula2/122485 +	* gm2-compiler/M2Comp.mod (Pass0CheckDef): Add spell check +	format specifier filtering on module names. +	* gm2-compiler/M2MetaError.mod (errorBlock): New field +	filterDef. +	(initErrorBlock): Initialize filterDef. +	(continuation): Add 'D' filter on definition module specifier. +	(SpellHint): Rewrite to check for filterDef and defimp symbols. +	(FilterOnDefinitionModule): New procedure. +	* gm2-compiler/M2Quads.mod (BuildSizeFunction): Rewrite to +	ensure variables are initialized. +	* gm2-compiler/M2StackSpell.def (GetDefModuleSpellHint): New +	procedure function. +	* gm2-compiler/M2StackSpell.mod (GetDefModuleSpellHint): New +	procedure function. +	(CandidatePushName): New procedure. +	(BuildHintStr): New procedure. +	(CheckForHintStr): Rewrite. +  2025-10-24  Gaius Mulley  <gaiusmod2@gmail.com>  	PR modula2/122407 diff --git a/gcc/m2/gm2-compiler/M2Comp.mod b/gcc/m2/gm2-compiler/M2Comp.mod index 741daeb..0190e01 100644 --- a/gcc/m2/gm2-compiler/M2Comp.mod +++ b/gcc/m2/gm2-compiler/M2Comp.mod @@ -851,12 +851,11 @@ BEGIN              MergeDeps (DepContent, ChildDep, LibName)           ELSE              (* Unrecoverable error.  *) -            MetaErrorString1 (Sprintf1 (InitString ('file {%%1EUAF%s} containing module {%%1a} cannot be found'), +            MetaErrorString1 (Sprintf1 (InitString ('file {%%1EUAF%s} containing module {%%1a} cannot be found {%%1&Ds}'),                                          FileName), sym)           END        ELSE -         (* Unrecoverable error.  *) -         MetaError1 ('the file containing the definition module {%1EMAa} cannot be found', sym) +         MetaError1 ('the file containing the definition module {%1EMAa} cannot be found {%1&Ds}', sym)        END ;        ModuleType := Implementation     ELSE @@ -928,15 +927,15 @@ BEGIN              qprintf0 ('\n') ;              CloseSource           ELSE -            (* It is quite legitimate to implement a module in C (and pretend it was a M2 +            (* It is legitimate to implement a module in C (and pretend it was a M2                 implementation) providing that it is not the main program module and the                 definition module does not declare a hidden type when -fextended-opaque                 is used.  *)              IF (NOT WholeProgram) OR (sym = Main) OR IsHiddenTypeDeclared (sym)              THEN                 (* Unrecoverable error.  *) -               MetaErrorString1 (Sprintf1 (InitString ('file {%%1EUAF%s} containing module {%%1a} cannot be found'), -                                           FileName), sym) ; +               MetaErrorString1 (Sprintf1 (InitString ('file {%%1EUAF%s} containing module {%%1a} cannot be found {%%1&Ds}'), +                                           FileName), sym)              END           END        END diff --git a/gcc/m2/gm2-compiler/M2MetaError.mod b/gcc/m2/gm2-compiler/M2MetaError.mod index aae0f02..22a1557 100644 --- a/gcc/m2/gm2-compiler/M2MetaError.mod +++ b/gcc/m2/gm2-compiler/M2MetaError.mod @@ -42,7 +42,6 @@ FROM SYSTEM IMPORT ADDRESS ;  FROM M2Error IMPORT MoveError ;  FROM M2Debug IMPORT Assert ;  FROM Storage IMPORT ALLOCATE ; -FROM M2StackSpell IMPORT GetSpellHint ;  FROM Indexing IMPORT Index, InitIndex, KillIndex, GetIndice, PutIndice,                       DeleteIndice, HighIndice ; @@ -74,6 +73,7 @@ IMPORT M2Error ;  IMPORT FilterError ;  FROM FilterError IMPORT Filter, AddSymError, IsSymError ; +FROM M2StackSpell IMPORT GetDefModuleSpellHint, GetSpellHint ;  CONST @@ -100,6 +100,7 @@ TYPE                     len,                     ini       : INTEGER ;                     vowel, +                   filterDef,                     importHint,                     exportHint,                     withStackHint, @@ -533,6 +534,7 @@ BEGIN        ini        := 0 ;        glyph      := FALSE ;  (* Nothing to output yet.  *)        vowel      := FALSE ;  (* Check for a vowel when outputing string?  *) +      filterDef  := FALSE ;  (* Filter on definition module list?  *)        importHint := FALSE;        exportHint := FALSE ;        withStackHint := FALSE ; @@ -1840,7 +1842,7 @@ END op ;  (* -   continuation := {':'|'1'|'2'|'3'|'4'|'i'|'s'|'x'|'w'} =: +   continuation := {':'|'1'|'2'|'3'|'4'|'i'|'s'|'x'|'w'|'D'} =:  *)  PROCEDURE continuation (VAR eb: errorBlock; @@ -1860,7 +1862,8 @@ BEGIN        'i':  AddImportsHint (eb) |        's':  SpellHint (eb, sym, bol) |        'x':  AddExportsHint (eb) | -      'w':  AddWithStackHint (eb) +      'w':  AddWithStackHint (eb) | +      'D':  FilterOnDefinitionModule (eb)        ELSE           InternalFormat (eb, 'expecting one of [:1234isxw]', @@ -1956,9 +1959,15 @@ END JoinSentances ;  PROCEDURE SpellHint (VAR eb: errorBlock; sym: ARRAY OF CARDINAL; bol: CARDINAL) ;  BEGIN -   IF (bol <= HIGH (sym)) AND IsUnknown (sym[bol]) +   IF bol <= HIGH (sym)     THEN -      JoinSentances (eb, GetSpellHint (sym[bol])) +      IF eb.filterDef AND IsDefImp (sym[bol]) +      THEN +         JoinSentances (eb, GetDefModuleSpellHint (sym[bol])) +      ELSIF IsUnknown (sym[bol]) +      THEN +         JoinSentances (eb, GetSpellHint (sym[bol])) +      END     END  END SpellHint ; @@ -1994,6 +2003,16 @@ END AddWithStackHint ;  (* +   FilterOnDefinitionModule - turn on filtering and include all the definition modules. +*) + +PROCEDURE FilterOnDefinitionModule (VAR eb: errorBlock) ; +BEGIN +   eb.filterDef := TRUE +END FilterOnDefinitionModule ; + + +(*     changeColor - changes to color, c.  *) diff --git a/gcc/m2/gm2-compiler/M2Quads.mod b/gcc/m2/gm2-compiler/M2Quads.mod index 5ceeb4f..a263ce3 100644 --- a/gcc/m2/gm2-compiler/M2Quads.mod +++ b/gcc/m2/gm2-compiler/M2Quads.mod @@ -10697,44 +10697,43 @@ BEGIN                     NoOfParam) ;        resulttok := functok ;        ReturnVar := MakeConstLit (resulttok, MakeKey('0'), Cardinal) -   ELSIF IsAModula2Type (OperandT (1)) -   THEN -      paramtok := OperandTok (1) ; -      resulttok := MakeVirtualTok (functok, functok, paramtok) ; -      BuildSizeCheckEnd (ProcSym) ;   (* Quadruple generation now on.  *) -      ReturnVar := MakeTemporary (resulttok, ImmediateValue) ; -      GenQuadO (resulttok, SizeOp, ReturnVar, NulSym, OperandT(1), TRUE) -   ELSIF IsVar (OperandT (1)) -   THEN -      BuildSizeCheckEnd (ProcSym) ;   (* Quadruple generation now on.  *) -      Type := GetSType (OperandT (1)) ; +   ELSE        paramtok := OperandTok (1) ;        resulttok := MakeVirtualTok (functok, functok, paramtok) ; -      IF IsUnbounded (Type) +      IF IsAModula2Type (OperandT (1))        THEN -         (* Eg. SIZE(a) ; where a is unbounded dereference HIGH and multiply by the TYPE.  *) -         dim := OperandD (1) ; -         IF dim = 0 +         BuildSizeCheckEnd (ProcSym) ;   (* Quadruple generation now on.  *) +         ReturnVar := MakeTemporary (resulttok, ImmediateValue) ; +         GenQuadO (resulttok, SizeOp, ReturnVar, NulSym, OperandT(1), TRUE) +      ELSIF IsVar (OperandT (1)) +      THEN +         BuildSizeCheckEnd (ProcSym) ;   (* Quadruple generation now on.  *) +         Type := GetSType (OperandT (1)) ; +         IF IsUnbounded (Type)           THEN -            ReturnVar := calculateMultipicand (resulttok, OperandT (1), Type, dim) +            (* Eg. SIZE(a) ; where a is unbounded dereference HIGH and multiply by the TYPE.  *) +            dim := OperandD (1) ; +            IF dim = 0 +            THEN +               ReturnVar := calculateMultipicand (resulttok, OperandT (1), Type, dim) +            ELSE +               ReturnVar := calculateMultipicand (resulttok, OperandA (1), Type, dim) +            END           ELSE -            ReturnVar := calculateMultipicand (resulttok, OperandA (1), Type, dim) +            ReturnVar := MakeTemporary (resulttok, ImmediateValue) ; +            IF Type = NulSym +            THEN +               MetaErrorT1 (resulttok, +                            'cannot get the type and size of {%1Ead}', OperandT (1)) +            END ; +            GenQuadO (resulttok, SizeOp, ReturnVar, NulSym, Type, TRUE)           END        ELSE -         ReturnVar := MakeTemporary (resulttok, ImmediateValue) ; -         IF Type = NulSym -         THEN -            MetaErrorT1 (resulttok, -                         'cannot get the type and size of {%1Ead}', OperandT (1)) -         END ; -         GenQuadO (resulttok, SizeOp, ReturnVar, NulSym, Type, TRUE) +         MetaErrorT1 (paramtok, +                      '{%E}SYSTEM procedure {%kSIZE} expects a variable or type as its parameter, seen {%1Ed} {%1&s}', +                      OperandT (1)) ; +         ReturnVar := MakeConstLit (paramtok, MakeKey('0'), Cardinal)        END -   ELSE -      paramtok := OperandTok (1) ; -      MetaErrorT1 (paramtok, -                   '{%E}SYSTEM procedure {%kSIZE} expects a variable or type as its parameter, seen {%1Ed} {%1&s}', -                   OperandT (1)) ; -      ReturnVar := MakeConstLit (resulttok, MakeKey('0'), Cardinal)     END ;     PopN (NoOfParam+1) ;       (* Destroy the arguments and function.  *)     PushTFtok (ReturnVar, GetSType(ProcSym), resulttok) diff --git a/gcc/m2/gm2-compiler/M2StackSpell.def b/gcc/m2/gm2-compiler/M2StackSpell.def index 7c1d00b..c45074a 100644 --- a/gcc/m2/gm2-compiler/M2StackSpell.def +++ b/gcc/m2/gm2-compiler/M2StackSpell.def @@ -59,4 +59,14 @@ PROCEDURE GetRecordField (tokno: CARDINAL;                            fieldName: Name) : CARDINAL ; +(* +   GetDefModuleSpellHint - return a string describing a spelling +                           hint for the definition module name +                           similiar to unknown.  NIL is returned +                           if no hint can be given. +*) + +PROCEDURE GetDefModuleSpellHint (defimp: CARDINAL) : String ; + +  END M2StackSpell. 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 ;  (* diff --git a/gcc/m2/gm2-compiler/P1Build.bnf b/gcc/m2/gm2-compiler/P1Build.bnf index 4cbdf17..d56a286 100644 --- a/gcc/m2/gm2-compiler/P1Build.bnf +++ b/gcc/m2/gm2-compiler/P1Build.bnf @@ -358,9 +358,12 @@ END Ident ;  *)  PROCEDURE IdentScope (stopset0: SetOfStop0; stopset1: SetOfStop1; stopset2: SetOfStop2) ; +VAR +   tokpos: CARDINAL ;  BEGIN -   Ident(stopset0, stopset1, stopset2) ; -   AddNameToScope(LastIdent) +   tokpos := GetTokenNo () ; +   Ident (stopset0, stopset1, stopset2) ; +   AddNameToScope (tokpos, LastIdent)  END IdentScope ; @@ -374,14 +377,14 @@ PROCEDURE PossiblyExportIdent (stopset0: SetOfStop0; stopset1: SetOfStop1; stops  VAR     nothing: CARDINAL ;  BEGIN -   AddNameToScope(makekey(currentstring)) ; -   PushTFtok(makekey(currentstring), identtok, GetTokenNo()) ; +   AddNameToScope (GetTokenNo (), makekey (currentstring)) ; +   PushTFtok (makekey (currentstring), identtok, GetTokenNo ()) ;     CheckExplicitExported ; -   IF NOT IsAutoPushOn() +   IF NOT IsAutoPushOn ()     THEN -      PopT(nothing) +      PopT (nothing)     END ; -   Expect(identtok, stopset0, stopset1, stopset2) +   Expect (identtok, stopset0, stopset1, stopset2)  END PossiblyExportIdent ; diff --git a/gcc/m2/gm2-compiler/P1SymBuild.mod b/gcc/m2/gm2-compiler/P1SymBuild.mod index d6c0f2f..33d12bd 100644 --- a/gcc/m2/gm2-compiler/P1SymBuild.mod +++ b/gcc/m2/gm2-compiler/P1SymBuild.mod @@ -39,6 +39,7 @@ FROM M2Reserved IMPORT ImportTok, ExportTok, QualifiedTok, UnQualifiedTok,  FROM FifoQueue IMPORT PutEnumerationIntoFifoQueue ;  FROM P0SymBuild IMPORT EnterBlock, LeaveBlock ; +FROM libc IMPORT printf ;  FROM SymbolTable IMPORT NulSym,                          ModeOfAddr, @@ -472,9 +473,6 @@ BEGIN                               OperandT(n+1)) ;        i := 1 ;        WHILE i<=n DO -(* -         WriteString('Importing ') ; WriteKey(Operand(j)) ; WriteString(' from ') ; WriteKey(GetSymName(ModSym)) ; WriteLn ; -*)           Sym := GetExported (OperandTok (n+1-i),                               ModSym, OperandT (n+1-i)) ;           PutImported (Sym) ; @@ -619,7 +617,7 @@ BEGIN        (* Ident List contains list of objects *)        i := 1 ;        WHILE i<=n DO -         AddNameToImportList (OperandT (i)) ; +         AddNameToImportList (OperandTok (i), OperandT (i)) ;           INC (i)        END     ELSE diff --git a/gcc/m2/gm2-compiler/SymbolTable.def b/gcc/m2/gm2-compiler/SymbolTable.def index 09a5590..2a2f201 100644 --- a/gcc/m2/gm2-compiler/SymbolTable.def +++ b/gcc/m2/gm2-compiler/SymbolTable.def @@ -2136,6 +2136,20 @@ PROCEDURE UnknownReported (sym: CARDINAL) ;  (* +   GetUnknownOnImport - returns the onimport field of unknown sym. +*) + +PROCEDURE GetUnknownOnImport (sym: CARDINAL) : BOOLEAN ; + + +(* +   GetUnknownDeclScope - returns the decl scope of unknown sym. +*) + +PROCEDURE GetUnknownDeclScope (sym: CARDINAL) : CARDINAL ; + + +(*     IsReallyPointer - returns TRUE is sym is a pointer, address or a                       type declared as a pointer or address.  *) @@ -2613,7 +2627,7 @@ PROCEDURE ResolveConstructorTypes ;                      current scope.  *) -PROCEDURE AddNameToScope (n: Name) ; +PROCEDURE AddNameToScope (tok: CARDINAL; n: Name) ;  (* @@ -2621,7 +2635,7 @@ PROCEDURE AddNameToScope (n: Name) ;                           module.  *) -PROCEDURE AddNameToImportList (n: Name) ; +PROCEDURE AddNameToImportList (tok: CARDINAL; n: Name) ;  (* diff --git a/gcc/m2/gm2-compiler/SymbolTable.mod b/gcc/m2/gm2-compiler/SymbolTable.mod index 023bd49..25170fb 100644 --- a/gcc/m2/gm2-compiler/SymbolTable.mod +++ b/gcc/m2/gm2-compiler/SymbolTable.mod @@ -230,6 +230,10 @@ TYPE     SymUndefined = RECORD                       name      : Name ;       (* Index into name array, name *)                                                (* of record.                  *) +                     declScope : CARDINAL ;   (* Scope where unknown is      *) +                                              (* created.                    *) +                     onImport  : BOOLEAN ;    (* Was it created during an    *) +                                              (* import?                     *)                       oafamily  : CARDINAL ;   (* The oafamily for this sym   *)                       errorScope: ErrorScope ; (* Title scope used if an      *)                                                (* error is emitted.           *) @@ -1591,7 +1595,7 @@ END IsError ;     MakeObject - creates an object node.  *) -PROCEDURE MakeObject (name: Name) : CARDINAL ; +PROCEDURE MakeObject (tok: CARDINAL; name: Name) : CARDINAL ;  VAR     pSym: PtrToSymbol ;     Sym : CARDINAL ; @@ -1601,8 +1605,8 @@ BEGIN     WITH pSym^ DO        SymbolType := ObjectSym ;        Object.name := name ; -      InitWhereDeclared(Object.At) ; -      InitWhereFirstUsed(Object.At) +      InitWhereDeclaredTok (tok, Object.At) ; +      InitWhereFirstUsedTok (tok, Object.At)     END ;     RETURN( Sym )  END MakeObject ; @@ -8647,7 +8651,7 @@ BEGIN        THEN           (* Make unknown *)           NewSym (Sym) ; -         FillInUnknownFields (tok, Sym, SymName) ; +         FillInUnknownFields (tok, Sym, SymName, NulSym, FALSE) ;           (* Add to unknown tree *)           AddSymToUnknownTree (ScopePtr, SymName, Sym)           (* @@ -8684,7 +8688,7 @@ BEGIN        THEN           (* Make unknown.  *)           NewSym (Sym) ; -         FillInUnknownFields (tok, Sym, SymName) ; +         FillInUnknownFields (tok, Sym, SymName, NulSym, FALSE) ;           (* Add to unknown tree *)           AddSymToUnknownTree (ScopePtr, SymName, Sym)           (* @@ -9252,7 +9256,7 @@ BEGIN                         IF Sym=NulSym                         THEN                            NewSym (Sym) ; -                          FillInUnknownFields (tok, Sym, SymName) ; +                          FillInUnknownFields (tok, Sym, SymName, ModSym, TRUE) ;                            PutSymKey (Unresolved, SymName, Sym)                         END                      END @@ -9283,7 +9287,7 @@ BEGIN                         IF Sym=NulSym                         THEN                            NewSym(Sym) ; -                          FillInUnknownFields (tok, Sym, SymName) ; +                          FillInUnknownFields (tok, Sym, SymName, ModSym, TRUE) ;                            PutSymKey (Unresolved, SymName, Sym)                         END                      END @@ -9310,7 +9314,7 @@ BEGIN                         IF Sym=NulSym                         THEN                            NewSym(Sym) ; -                          FillInUnknownFields (tok, Sym, SymName) ; +                          FillInUnknownFields (tok, Sym, SymName, scope, TRUE) ;                            PutSymKey(Unresolved, SymName, Sym)                         END                      END | @@ -9319,7 +9323,7 @@ BEGIN                         IF Sym=NulSym                         THEN                            NewSym(Sym) ; -                          FillInUnknownFields (tok, Sym, SymName) ; +                          FillInUnknownFields (tok, Sym, SymName, scope, TRUE) ;                            PutSymKey(Unresolved, SymName, Sym)                         END                      END | @@ -9328,7 +9332,7 @@ BEGIN                            IF Sym=NulSym                            THEN                               NewSym(Sym) ; -                             FillInUnknownFields (tok, Sym, SymName) ; +                             FillInUnknownFields (tok, Sym, SymName, NulSym, FALSE) ;                               PutSymKey(Unresolved, SymName, Sym)                            END                         END @@ -9599,7 +9603,8 @@ BEGIN                      CheckForUnknowns (tokno, name, ExportUnQualifiedTree,                                        'EXPORT UNQUALIFIED') ;                      CheckForSymbols (ExportRequest, -                                     'requested by another modules import (symbols have not been exported by the appropriate definition module)') ; +                                     'requested by another module import' + +                                     ' and the symbol has not been exported by the appropriate definition module') ;                      CheckForUnknowns (tokno, name, Unresolved, 'unresolved') ;                      CheckForUnknowns (tokno, name, LocalSymbols, 'locally used')                   END | @@ -9752,12 +9757,12 @@ PROCEDURE CheckForSymbols (Tree: SymbolTree; a: ARRAY OF CHAR) ;  VAR     s: String ;  BEGIN -   IF NOT IsEmptyTree(Tree) +   IF DoesTreeContainAny (Tree, IsUnreportedUnknown)     THEN        s := InitString ("the symbols are unknown at the end of module {%1Ea} when ") ;        s := ConCat (s, Mark(InitString(a))) ;        MetaErrorString1 (s, MainModule) ; -      ForeachNodeDo(Tree, SymbolError) +      ForeachNodeDo (Tree, SymbolError)     END  END CheckForSymbols ; @@ -11708,10 +11713,11 @@ END IsProcedureAnyNoReturn ;  (* -   FillInUnknownFields - +   FillInUnknownFields - fills in all fields for the undefined sym.  *) -PROCEDURE FillInUnknownFields (tok: CARDINAL; sym: CARDINAL; SymName: Name) ; +PROCEDURE FillInUnknownFields (tok: CARDINAL; sym: CARDINAL; SymName: Name; +                               descscope: CARDINAL; onimport: BOOLEAN) ;  VAR     pSym: PtrToSymbol ;  BEGIN @@ -11722,6 +11728,8 @@ BEGIN           name     := SymName ;           oafamily := NulSym ;           errorScope := GetCurrentErrorScope () ; +         declScope := descscope ; +         onImport := onimport ;           InitWhereFirstUsedTok (tok, At)        END     END @@ -11729,6 +11737,34 @@ END FillInUnknownFields ;  (* +   GetUnknownOnImport - returns the onimport field of unknown sym. +*) + +PROCEDURE GetUnknownOnImport (sym: CARDINAL) : BOOLEAN ; +VAR +   pSym: PtrToSymbol ; +BEGIN +   Assert (IsUnknown (sym)) ; +   pSym := GetPsym (sym) ; +   RETURN pSym^.Undefined.onImport +END GetUnknownOnImport ; + + +(* +   GetUnknownDeclScope - returns the decl scope of unknown sym. +*) + +PROCEDURE GetUnknownDeclScope (sym: CARDINAL) : CARDINAL ; +VAR +   pSym: PtrToSymbol ; +BEGIN +   Assert (IsUnknown (sym)) ; +   pSym := GetPsym (sym) ; +   RETURN pSym^.Undefined.declScope +END GetUnknownDeclScope ; + + +(*     FillInPointerFields - given a new symbol, sym, make it a pointer symbol                           and initialize its fields.  *) @@ -12985,7 +13021,7 @@ END AddNameTo ;                      current scope.  *) -PROCEDURE AddNameToScope (n: Name) ; +PROCEDURE AddNameToScope (tok: CARDINAL; n: Name) ;  VAR     pSym : PtrToSymbol ;     scope: CARDINAL ; @@ -12995,9 +13031,9 @@ BEGIN     WITH pSym^ DO        CASE SymbolType OF -      ProcedureSym:  AddNameTo(Procedure.NamedObjects, MakeObject(n)) | -      ModuleSym   :  AddNameTo(Module.NamedObjects, MakeObject(n)) | -      DefImpSym   :  AddNameTo(DefImp.NamedObjects, MakeObject(n)) +      ProcedureSym:  AddNameTo(Procedure.NamedObjects, MakeObject (tok, n)) | +      ModuleSym   :  AddNameTo(Module.NamedObjects, MakeObject (tok, n)) | +      DefImpSym   :  AddNameTo(DefImp.NamedObjects, MakeObject (tok, n))        ELSE           InternalError ('expecting - DefImp') @@ -13011,7 +13047,7 @@ END AddNameToScope ;                           module.  *) -PROCEDURE AddNameToImportList (n: Name) ; +PROCEDURE AddNameToImportList (tok: CARDINAL; n: Name) ;  VAR     pSym : PtrToSymbol ;     scope: CARDINAL ; @@ -13021,8 +13057,8 @@ BEGIN     WITH pSym^ DO        CASE SymbolType OF -      ModuleSym:  AddNameTo(Module.NamedImports, MakeObject(n)) | -      DefImpSym:  AddNameTo(DefImp.NamedImports, MakeObject(n)) +      ModuleSym:  AddNameTo (Module.NamedImports, MakeObject (tok, n)) | +      DefImpSym:  AddNameTo (DefImp.NamedImports, MakeObject (tok, n))        ELSE           InternalError ('expecting - DefImp or Module symbol')  | 
