1 2 /* Compiler implementation of the D programming language 3 * Copyright (C) 1999-2019 by The D Language Foundation, All Rights Reserved 4 * written by Walter Bright 5 * http://www.digitalmars.com 6 * Distributed under the Boost Software License, Version 1.0. 7 * http://www.boost.org/LICENSE_1_0.txt 8 * https://github.com/dlang/dmd/blob/master/src/dmd/identifier.h 9 */ 10 11 #pragma once 12 13 #include "root/root.h" 14 #include "root/stringtable.h" 15 16 class Identifier : public RootObject 17 { 18 private: 19 int value; 20 const char *string; 21 size_t len; 22 23 public: 24 Identifier(const char *string, size_t length, int value); 25 Identifier(const char *string); 26 static Identifier* create(const char *string); 27 bool equals(RootObject *o); 28 int compare(RootObject *o); 29 void print(); 30 const char *toChars(); 31 int getValue() const; 32 const char *toHChars2(); 33 int dyncast() const; 34 35 static StringTable stringtable; 36 static Identifier *generateId(const char *prefix); 37 static Identifier *generateId(const char *prefix, size_t i); 38 static Identifier *idPool(const char *s, size_t len); 39 static Identifier *idPool(const char *s, size_t len, int value); 40 idPool(const char * s)41 static inline Identifier *idPool(const char *s) 42 { 43 return idPool(s, strlen(s)); 44 } 45 46 static bool isValidIdentifier(const char *p); 47 static Identifier *lookup(const char *s, size_t len); 48 static void initTable(); 49 }; 50