logo

class

compiler::ReflectType

sys::Obj
  compiler::ReflectType : compiler::CType
  1  //
  2  // Copyright (c) 2006, Brian Frank and Andy Frank
  3  // Licensed under the Academic Free License version 3.0
  4  //
  5  // History:
  6  //   6 Jun 06  Brian Frank  Creation
  7  //
  8  
  9  **
 10  ** ReflectType is the implementation of CType for a type imported
 11  ** from a precompiled pod (as opposed to a TypeDef within the compilation
 12  ** units being compiled).
 13  **
 14  class ReflectType : CType
 15  {
 16  
 17  //////////////////////////////////////////////////////////////////////////
 18  // Construction
 19  //////////////////////////////////////////////////////////////////////////
 20  
 21    **
 22    ** Construct with loaded Type.
 23    **
 24    new make(ReflectNamespace ns, Type t)
 25    {
 26      this.pod    = ns.importPod(t.pod)
 27      this.t      = t
 28      this.base   = ns.importType(t.base)
 29      this.mixins = ns.importTypes(t.mixins)
 30    }
 31  
 32  //////////////////////////////////////////////////////////////////////////
 33  // CType
 34  //////////////////////////////////////////////////////////////////////////
 35  
 36    override ReflectNamespace ns() { return pod.ns }
 37    override Str name()      { return t.name }
 38    override Str qname()     { return t.qname }
 39    override Str signature() { return t.signature }
 40    override Int flags()     { return (Int)t->flags }
 41  
 42    override Bool isGeneric() { return t.isGeneric }
 43    override Bool isParameterized() { return !t.params.isEmpty }
 44    override Bool isGenericParameter() { return pod === ns.sysPod && name.size === 1 }
 45  
 46    override ListType toListOf()
 47    {
 48      if (listOf == null) listOf = ListType.make(this)
 49      return listOf
 50    }
 51  
 52    override Str:CSlot slots()
 53    {
 54      if (!slotsLoaded)
 55      {
 56        slotsLoaded = true
 57        if (!isGenericParameter)
 58        {
 59          t.slots.each |Slot s|
 60          {
 61            if (slotMap[s.name] == null)
 62              slotMap[s.name] = ns.importSlot(s)
 63          }
 64        }
 65      }
 66      return slotMap
 67    }
 68  
 69    override CSlot slot(Str name)
 70    {
 71      cs := slotMap[name]
 72      if (cs == null)
 73      {
 74        s := t.slot(name, false)
 75        if (s != null)
 76          slotMap[name] = cs = ns.importSlot(s)
 77      }
 78      return cs
 79    }
 80  
 81    override Str toStr() { return signature() }
 82  
 83  //////////////////////////////////////////////////////////////////////////
 84  // Fields
 85  //////////////////////////////////////////////////////////////////////////
 86  
 87    readonly Type t
 88    override readonly ReflectPod pod
 89    override readonly CType base
 90    override readonly CType[] mixins
 91    private Str:CSlot slotMap := Str:CSlot[:]
 92    private Bool slotsLoaded := false
 93    private ListType listOf
 94  
 95  }