Bladeren bron

Autodoc: receivers (methods) work

Arthur Yefimov 2 jaren geleden
bovenliggende
commit
8aefb99093
2 gewijzigde bestanden met toevoegingen van 79 en 7 verwijderingen
  1. 54 4
      src/Autodoc/AutodocHtml.Mod
  2. 25 3
      src/Autodoc/AutodocParser.Mod

+ 54 - 4
src/Autodoc/AutodocHtml.Mod

@@ -49,7 +49,13 @@ VAR
 
   (** Module names of modules to which <a href> will work *)
   linkMods: ARRAY 256 OF ARRAY 64 OF CHAR;
-  linkModCount: INTEGER; (** Actual length of linkMods array *)
+  linkModCount: INTEGER; (** Actual length of array linkMods *)
+
+(** List of Declared Names **)
+
+  (** Names declared in the same module to which <a href> will work *)
+  declNames: ARRAY 256 OF ARRAY 64 OF CHAR;
+  declNameCount: INTEGER; (** Actual length of array declNames *)
 
 (** Link Module List **)
 
@@ -289,7 +295,15 @@ BEGIN Strings.Extract(s, 0, len, z); i := 0;
 WHILE (i # linkModCount) & (linkMods[i] # z) DO INC(i) END
 RETURN i # linkModCount END IsLinkedMod;
 
-(** Write s, but maybe add <a href> to another module *)
+PROCEDURE IsNameDeclared(s: ARRAY OF CHAR): BOOLEAN;
+VAR i: INTEGER;
+BEGIN
+  i := 0;
+  WHILE (i # declNameCount) & (declNames[i] # s) DO INC(i) END
+RETURN i # declNameCount END IsNameDeclared;
+
+(** Writes `s`, and maybe adds <a href> around it to another module or
+    to another place in this module *)
 PROCEDURE PrintLink(s: ARRAY OF CHAR);
 VAR i, j, k: INTEGER;
   written: BOOLEAN;
@@ -299,18 +313,21 @@ BEGIN written := FALSE;
   IF s[i] = '.' THEN (* First '.' found *)
     (* Find second '.', put in j *)
     j := i + 1; WHILE IsAlphanum(s[j]) DO INC(j) END;
-    IF (s[j] = 0X) & IsLinkedMod(s, i) THEN (* No second '.', all is alphanum *)
+    IF (s[j] = 0X) & IsLinkedMod(s, i) THEN (* No 2nd '.', all is alphanum *)
       Write('<a href="');
       FOR k := 0 TO i - 1 DO WriteChar(s[k]) END;
       Write('.html#');
       FOR k := i + 1 TO j - 1 DO WriteChar(s[k]) END;
       Write('">'); Write(s); Write('</a>'); written := TRUE
     END
+  ELSIF (s[i] = 0X) & IsNameDeclared(s) THEN (* No '.' in s *)
+    Write('<a href="#'); Write(s); Write('">'); Write(s); Write('</a>');
+    written := TRUE
   END;
   IF ~written THEN Write(s) END
 END PrintLink;
 
-(** Prints a href to a module name. *)
+(** Prints a href to a module name *)
 PROCEDURE PrintModLink(s: ARRAY OF CHAR);
 VAR i: INTEGER;
 BEGIN
@@ -478,6 +495,14 @@ BEGIN
   Write(p.name); WriteLn('">');
   WriteLn ('  <div class="def">');
   WriteLn ('    PROCEDURE');
+  IF p.receiver # NIL THEN
+    WriteLn('    <span class="receiver">');
+    Write  ('      (<span class="name">'); Write(p.receiver.name);
+    WriteLn('</span>:');
+    PrintType(p.receiver.type, indent, TRUE);
+    WriteLn(')');
+    WriteLn('    </span>')
+  END;
   Write   ('    <span class="name">'); Write(p.name);
   Write('</span>'); WriteExport(p); Write('<span class="params">');
   x := p.params.first;
@@ -617,9 +642,34 @@ BEGIN
   END
 END PrintSection;
 
+PROCEDURE DeclareNamesInSection(L: P.List);
+VAR g, p: P.Object;
+BEGIN
+  g := L.first;
+  WHILE g # NIL DO
+    p := g(P.Group).first;
+    WHILE p # NIL DO
+      IF declNameCount # LEN(declNames) THEN
+        Strings.Copy(p.name, declNames[declNameCount]);
+        INC(declNameCount)
+      END;
+      p := p.next
+    END;
+    g := g.next
+  END
+END DeclareNamesInSection;
+
+PROCEDURE DeclareNames(M: P.Module);
+BEGIN
+  declNameCount := 0;
+  DeclareNamesInSection(M.consts);
+  DeclareNamesInSection(M.types)
+END DeclareNames;
+
 PROCEDURE PrintModule(M: P.Module; indent: INTEGER; inlined: BOOLEAN);
 VAR s: ARRAY 64 OF CHAR;
 BEGIN
+  DeclareNames(M);
   showExportMarks := ~M.exportedOnly;
   Header(M.name, FALSE);
   PrintComment(M.comment, FALSE);

+ 25 - 3
src/Autodoc/AutodocParser.Mod

@@ -103,7 +103,7 @@ TYPE
 
   Type* = POINTER TO TypeDesc;
   TypeDesc* = RECORD(ObjectDesc)
-    form*: INTEGER; (** See @Form of Types *)
+    form*: INTEGER; (** See @Forms of Types *)
     len*: Str;      (** Length of array (may be an expression), or '' *)
     base*: Type;    (** Base type of rec/arr/pointer, return of procedure *)
     fields*: List
@@ -116,14 +116,16 @@ TYPE
 
   Param* = POINTER TO ParamDesc;
   ParamDesc* = RECORD(ObjectDesc)
-    passed*: INTEGER; (** See values of Param.pass *)
+    passed*: INTEGER; (** See constants above (values of Param.passed) *)
     type*: Type
   END;
 
   Procedure* = POINTER TO ProcedureDesc;
   ProcedureDesc* = RECORD(ObjectDesc)
     returnType*: Type;
-    params*: List
+    params*: List;
+    receiver*: Param;
+    modifier*: Str
   END;
 
   Module* = POINTER TO ModuleDesc;
@@ -1372,6 +1374,23 @@ BEGIN
   WHILE sym = procedure DO UpdateCurGroup(M.procedures);
     NEW(P); InitObject(P); SaveComment(P, -1); GetSym; foreign := FALSE;
     forward := FALSE; P.params := NewList(); P.exported := FALSE;
+    P.modifier[0] := 0X;
+    IF sym = lparen THEN NEW(P.receiver); InitObject(P.receiver); GetSym;
+      NEW(P.receiver.type); InitObject(P.receiver.type);
+      IF sym = var THEN GetSym; P.receiver.passed := byVar
+      ELSE P.receiver.passed := byValue
+      END;
+      IF sym = ident THEN Strings.Copy(id, P.receiver.name); GetSym
+      ELSE MarkExp('receiver name')
+      END;
+      IF sym = colon THEN GetSym ELSE MarkExp(':') END;
+      IF sym = ident THEN Strings.Copy(id, P.receiver.type.name); GetSym;
+        P.receiver.type.len[0] := 0X;
+        P.receiver.type.form := namedType
+      ELSE MarkExp('receiver name')
+      END;
+      IF sym = rparen THEN GetSym ELSE MarkExp(')') END
+    END;
     IF (sym = minus) OR (sym = arrow) THEN GetSym; forward := TRUE;
     ELSIF sym = times THEN GetSym
     END;
@@ -1392,6 +1411,9 @@ BEGIN
       IF sym = rparen THEN GetSym ELSE MarkExp(')') END;
       IF sym = colon THEN GetSym; P.returnType := ParseNamedType() END
     END;
+    IF (sym = comma) & (P.receiver # NIL) THEN GetSym;
+      IF sym = ident THEN Strings.Copy(id, P.modifier); GetSym END
+    END;
     IF sym = string THEN GetSym END; (* Foreign code *)
     IF sym = semicol THEN GetSym ELSE MarkExp(';') END;
     IF ~forward & ~foreign THEN