view trunk/src/dil/semantic/Symbols.d @ 590:641041912670

Moved dil.Symbols to dil.semantic.Symbols.
author Aziz K?ksal <aziz.koeksal@gmail.com>
date Sat, 05 Jan 2008 23:44:26 +0100
parents trunk/src/dil/Symbols.d@de365ddcfbd4
children 26addda6365b
line wrap: on
line source

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

import dil.semantic.Symbol;
import dil.SymbolTable;
import dil.ast.Node;
import dil.Enums;
import dil.semantic.Types;
import dil.Identifier;
import common;

/// A symbol that has its own scope with a symbol table.
class ScopeSymbol : Symbol
{
  protected SymbolTable symbolTable; /// The symbol table.

  this()
  {
  }

  /// Look up ident in the table.
  Symbol lookup(Identifier* ident)
  {
    return symbolTable.lookup(ident);
  }

  /// Insert a symbol into the table.
  void insert(Symbol s, Identifier* ident)
  {
    symbolTable.insert(s, ident);
  }
}

/// Aggregates have function and field members.
class Aggregate : ScopeSymbol
{
  Identifier* ident; /// The name of this aggregate.
  Function[] funcs;
  Variable[] fields;

  override void insert(Symbol s, Identifier* ident)
  {
    if (s.isVariable)
      // Append variable to fields.
      fields ~= cast(Variable)cast(void*)s;
    else if (s.isFunction)
      // Append function to funcs.
      funcs ~= cast(Function)cast(void*)s;
    super.insert(s, ident);
  }
}

class Class : Aggregate
{
  this(Identifier* ident, Node classNode)
  {
    this.sid = SYM.Class;
    this.ident = ident;
    this.node = classNode;
  }
}

class Interface : Aggregate
{
  this(Identifier* ident, Node interfaceNode)
  {
    this.sid = SYM.Interface;
    this.ident = ident;
    this.node = interfaceNode;
  }
}

class Union : Aggregate
{
  this(Identifier* ident, Node unionNode)
  {
    this.sid = SYM.Union;
    this.ident = ident;
    this.node = unionNode;
  }
}

class Struct : Aggregate
{
  this(Identifier* ident, Node structNode)
  {
    this.sid = SYM.Struct;
    this.ident = ident;
    this.node = structNode;
  }
}

class Function : ScopeSymbol
{
  StorageClass stc;
  LinkageType linkType;

  Type returnType;
  Identifier* ident;
  Variable[] params;

  this()
  {
    this.sid = SYM.Function;
  }
}

class Variable : Symbol
{
  StorageClass stc;
  LinkageType linkType;

  Type type;
  Identifier* ident;

  this(StorageClass stc, LinkageType linkType,
       Type type, Identifier* ident, Node varDecl)
  {
    this.sid = SYM.Variable;

    this.stc = stc;
    this.linkType = linkType;
    this.type = type;
    this.ident = ident;
    this.node = varDecl;
  }
}