view dmd/lstring.h @ 715:30b42a283c8e

Removed TypeOpaque from DMD. Changed runtime functions taking opaque[] to void[]. Implemented proper type painting, to avoid "resizing" array casts in runtime calls that previously took opaque[]. Implemented dynamic arrays as first class types, this implements proper ABI for these types on x86. Added dwarf region end after call to assert function, fixes some problems with llvm not allowing this to be missing. Reverted change to WithStatement from rev [704] it breaks MiniD, mini/with2.d needs to be fixed some other way... Fixed tango bug 1339 in runtime, problem with _adReverseChar on invalid UTF-8. Disabled .bc generation in the compiler runtime part, genobj.d triggers some llvm bug when using debug info. the .o seems to work fine.
author Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
date Wed, 22 Oct 2008 14:55:33 +0200
parents c53b6e3fe49a
children
line wrap: on
line source


// lstring.h
// length-prefixed strings

// Copyright (c) 1999-2002 by Digital Mars
// All Rights Reserved
// written by Walter Bright
// www.digitalmars.com
// License for redistribution is by either the Artistic License
// in artistic.txt, or the GNU General Public License in gnu.txt.
// See the included readme.txt for details.

#ifndef LSTRING_H
#define LSTRING_H 1

#include "dchar.h"

struct Lstring
{
    unsigned length;

    // Disable warning about nonstandard extension
    #pragma warning (disable : 4200)
    dchar string[];

    static Lstring zero;	// 0 length string

    // No constructors because we want to be able to statically
    // initialize Lstring's, and Lstrings are of variable size.

    #if M_UNICODE
    #define LSTRING(p,length) { length, L##p }
    #else
    #define LSTRING(p,length) { length, p }
    #endif

#if __GNUC__
    #define LSTRING_EMPTY() { 0 }
#else
    #define LSTRING_EMPTY() LSTRING("", 0)
#endif

    static Lstring *ctor(const dchar *p) { return ctor(p, Dchar::len(p)); }
    static Lstring *ctor(const dchar *p, unsigned length);
    static unsigned size(unsigned length) { return sizeof(Lstring) + (length + 1) * sizeof(dchar); }
    static Lstring *alloc(unsigned length);
    Lstring *clone();

    unsigned len() { return length; }

    dchar *toDchars() { return string; }

    hash_t hash() { return Dchar::calcHash(string, length); }
    hash_t ihash() { return Dchar::icalcHash(string, length); }

    static int cmp(const Lstring *s1, const Lstring *s2)
    {
	int c = s2->length - s1->length;
	return c ? c : Dchar::memcmp(s1->string, s2->string, s1->length);
    }

    static int icmp(const Lstring *s1, const Lstring *s2)
    {
	int c = s2->length - s1->length;
	return c ? c : Dchar::memicmp(s1->string, s2->string, s1->length);
    }

    Lstring *append(const Lstring *s);
    Lstring *substring(int start, int end);
};

#endif