view src/dil/semantic/Package.d @ 820:1d06b4aed7cf

Revised code in the first pass. Added code to handle anonymous unions and structs. Hope the idea will work. Added type to class Aggregate and isAnonymous to some other Symbol classes.
author Aziz K?ksal <aziz.koeksal@gmail.com>
date Fri, 14 Mar 2008 15:42:08 +0100
parents 35d238d502cb
children
line wrap: on
line source

/++
  Author: Aziz Köksal
  License: GPL3
+/
module dil.semantic.Package;

import dil.semantic.Symbol;
import dil.semantic.Symbols;
import dil.semantic.Module;
import dil.lexer.IdTable;
import common;

/// A package groups modules and other packages.
class Package : ScopeSymbol
{
  string pckgName;    /// The name of the package. E.g.: 'dil'.
  Package[] packages; /// The sub-packages contained in this package.
  Module[] modules;   /// The modules contained in this package.

  /// Constructs a Package object.
  this(string pckgName)
  {
    auto ident = IdTable.lookup(pckgName);
    super(SYM.Package, ident, null);
    this.pckgName = pckgName;
  }

  /// Returns true if this is the root package.
  bool isRoot()
  {
    return parent is null;
  }

  /// Returns the parent package or null if this is the root.
  Package parentPackage()
  {
    if (isRoot())
      return null;
    assert(parent.isPackage);
    return parent.to!(Package);
  }

  /// Adds a module to this package.
  void add(Module modul)
  {
    modul.parent = this;
    modules ~= modul;
    insert(modul, modul.name);
  }

  /// Adds a package to this package.
  void add(Package pckg)
  {
    pckg.parent = this;
    packages ~= pckg;
    insert(pckg, pckg.name);
  }
}