
1 // 2 // Copyright (c) 2006, Brian Frank and Andy Frank 3 // Licensed under the Academic Free License version 3.0 4 // 5 // History: 6 // 10 Nov 05 Brian Frank Creation 7 // 3 Jun 06 Brian Frank Ported from Java to Fan - Megan's b-day! 8 // 9 10 ** 11 ** DefNode is the abstract base class for definition nodes such as TypeDef, 12 ** MethodDef, and FieldDef. All definitions may be documented using a 13 ** Javadoc style FanDoc comment. 14 ** 15 abstract class DefNode : Node 16 { 17 18 ////////////////////////////////////////////////////////////////////////// 19 // Construction 20 ////////////////////////////////////////////////////////////////////////// 21 22 new make(Location location) 23 : super(location) 24 { 25 } 26 27 ////////////////////////////////////////////////////////////////////////// 28 // Tree 29 ////////////////////////////////////////////////////////////////////////// 30 31 abstract Namespace ns() 32 33 Void walkFacets(Visitor v, VisitDepth depth) 34 { 35 if (facets != null && depth >= VisitDepth.expr) 36 { 37 facets.each |FacetDef f| { f.walk(v) } 38 } 39 } 40 41 Void addFacet(CompilerSupport support, Str name, Obj value) 42 { 43 if (facets == null) facets = Str:FacetDef[:] 44 f := FacetDef.make(location, name, LiteralExpr.makeFor(location, ns, value)) 45 46 dup := facets[name] 47 if (dup != null) 48 support.err("Facet '$name' conflicts with auto-generated facet", dup.location) 49 else 50 facets.add(name, f) 51 } 52 53 Void printFacets(AstWriter out) 54 { 55 if (facets == null) return 56 facets.each |FacetDef f| { f.print(out) } 57 } 58 59 ////////////////////////////////////////////////////////////////////////// 60 // Fields 61 ////////////////////////////////////////////////////////////////////////// 62 63 Str[] doc // lines of fandoc comment or null 64 Int flags := 0 // type/slot flags 65 Str:FacetDef facets // facet declarations (may be null) 66 67 }