コード例 #1
0
ファイル: DocTree.cs プロジェクト: nhweston/dfy
 private TypeRefNode ToTypeRefNode(Microsoft.Dafny.Type t, TokenNode token)
 {
     if (t.IsRevealableType && t.AsRevealableType is TypeSynonymDecl ts && ts.tok != null &&
         ts.tok.filename != null)
     {
         Console.WriteLine("Type synonym reference: " + ts.Name);
         return(new TypeRefNode {
             Name = ts.Name,
             Target = ToTokenNode(ts.tok),
             TypeParams = t.TypeArgs.Select(tp => ToTypeRefNode(tp, token)).ToList(),
             Token = token,
         });
     }
     if (t.IsArrayType)
     {
         Console.WriteLine("Array type reference");
         var at  = t.AsArrayType;
         var tps = new List <TypeRefNode>();
         tps.Add(ToTypeRefNode(t.TypeArgs[0], token));
         return(new TypeRefNode {
             Name = "array",
             TypeParams = tps,
             Token = token,
         });
     }
     if (t.AsCollectionType != null)
     {
         Console.WriteLine("Collection type reference");
         var ct = t.AsCollectionType;
         return(new TypeRefNode {
             Name = ct.CollectionTypeName,
             TypeParams = t.TypeArgs.Select(tp => ToTypeRefNode(tp, token)).ToList(),
             Token = token,
         });
     }
     if (t.IsArrowType)
     {
         Console.WriteLine("Function type reference");
         var at = t.AsArrowType;
         return(new TypeRefNode {
             Name = at.Name,
             TypeParams = t.TypeArgs.Select(tp => ToTypeRefNode(tp, token)).ToList(),
             Special = "Function",
             Token = token,
         });
     }
     if (t.IsTypeParameter)
     {
         Console.WriteLine("Type parameter reference");
         var tp = t.AsTypeParameter;
         return(new TypeRefNode {
             Name = tp.Name,
             Target = ToTokenNode(tp.tok),
             TypeParams = new TypeRefNode[0],
             Token = token,
         });
     }
     if (t.IsDatatype)
     {
         Console.WriteLine("Tuple type reference");
         var dt = t.AsDatatype;
         if (dt is TupleTypeDecl tt)
         {
             return(new TypeRefNode {
                 Name = dt.Name,
                 TypeParams = t.TypeArgs.Select(tp => ToTypeRefNode(tp, token)).ToList(),
                 Special = "Tuple",
                 Token = token,
             });
         }
     }
     if (t.IsNonNullRefType)
     {
         var udt = t.AsNonNullRefType;
         Console.WriteLine("Type reference: " + udt.Name);
         return(new TypeRefNode {
             Name = udt.Name,
             Target = ToTokenNode(udt.tok),
             TypeParams = t.TypeArgs.Select(tp => ToTypeRefNode(tp, token)).ToList(),
             Token = token,
         });
     }
     Console.WriteLine("Other type reference: " + t.ToString());
     return(new TypeRefNode {
         Name = t.ToString(),
         TypeParams = new TypeRefNode[0],
         Token = token,
     });
 }
コード例 #2
0
ファイル: DocTree.cs プロジェクト: nhweston/dfy
 private SpecNode ToSpecNode(Specification <FrameExpression> spec, string kind, TokenNode token)
 {
     Console.WriteLine("Specification (" + kind + ")");
     return(new SpecNode {
         Kind = kind,
         Clause = string.Join(", ", spec.Expressions.Select(e => Printer.ExprToString(e.E))),
         UserDoc = null,
         Token = token,
     });
 }