view src/dil/lexer/Identifier.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 bcb74c9b895c
children
line wrap: on
line source

/++
  Author: Aziz Köksal
  License: GPL3
+/
module dil.lexer.Identifier;

import dil.lexer.TokensEnum;
import dil.lexer.IdentsEnum;
import common;

/// Represents an identifier as defined in the D specs.
///
///<pre>
///  Identifier := IdStart IdChar*
///  IdStart := "_" | Letter
///  IdChar := IdStart | "0"-"9"
///  Letter := UniAlpha
///</pre>
///  Unicode alphas are defined in Unicode 5.0.0.
align(1)
struct Identifier
{
  string str; /// The UTF-8 string of the identifier.
  TOK kind;   /// The token kind.
  IDK idKind; /// Only for predefined identifiers.

  static Identifier* opCall(string str, TOK kind)
  {
    auto id = new Identifier;
    id.str = str;
    id.kind = kind;
    return id;
  }

  static Identifier* opCall(string str, TOK kind, IDK idKind)
  {
    auto id = new Identifier;
    id.str = str;
    id.kind = kind;
    id.idKind = idKind;
    return id;
  }

  uint toHash()
  {
    uint hash;
    foreach(c; str) {
      hash *= 11;
      hash += c;
    }
    return hash;
  }
}
// pragma(msg, Identifier.sizeof.stringof);