本文整理汇总了C++中OutBuffer::extractData方法的典型用法代码示例。如果您正苦于以下问题:C++ OutBuffer::extractData方法的具体用法?C++ OutBuffer::extractData怎么用?C++ OutBuffer::extractData使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OutBuffer
的用法示例。
在下文中一共展示了OutBuffer::extractData方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: return
char *Loc::toChars()
{
OutBuffer buf;
if (filename)
{
buf.printf("%s", filename);
}
if (linnum)
buf.printf("(%d)", linnum);
buf.writeByte(0);
return (char *)buf.extractData();
}
示例2: write
void LibOMF::write()
{
if (global.params.verbose)
fprintf(global.stdmsg, "library %s\n", libfile->name->toChars());
OutBuffer libbuf;
WriteLibToBuffer(&libbuf);
// Transfer image to file
libfile->setbuffer(libbuf.data, libbuf.offset);
libbuf.extractData();
FileName::ensurePathToNameExists(libfile->name->toChars());
libfile->writev();
}
示例3: write
void Library::write()
{
if (global.params.verbose)
printf("library %s\n", libfile->name->toChars());
OutBuffer libbuf;
WriteLibToBuffer(&libbuf);
// Transfer image to file
libfile->setbuffer(libbuf.data, libbuf.offset);
libbuf.extractData();
char *p = FileName::path(libfile->name->toChars());
FileName::ensurePathExists(p);
//mem.free(p);
libfile->writev();
}
示例4: parse
void Module::parse()
#endif
{ char *srcname;
unsigned char *buf;
unsigned buflen;
unsigned le;
unsigned bom;
//printf("Module::parse()\n");
srcname = srcfile->name->toChars();
//printf("Module::parse(srcname = '%s')\n", srcname);
buf = srcfile->buffer;
buflen = srcfile->len;
if (buflen >= 2)
{
/* Convert all non-UTF-8 formats to UTF-8.
* BOM : http://www.unicode.org/faq/utf_bom.html
* 00 00 FE FF UTF-32BE, big-endian
* FF FE 00 00 UTF-32LE, little-endian
* FE FF UTF-16BE, big-endian
* FF FE UTF-16LE, little-endian
* EF BB BF UTF-8
*/
bom = 1; // assume there's a BOM
if (buf[0] == 0xFF && buf[1] == 0xFE)
{
if (buflen >= 4 && buf[2] == 0 && buf[3] == 0)
{ // UTF-32LE
le = 1;
Lutf32:
OutBuffer dbuf;
unsigned *pu = (unsigned *)(buf);
unsigned *pumax = &pu[buflen / 4];
if (buflen & 3)
{ error("odd length of UTF-32 char source %u", buflen);
fatal();
}
dbuf.reserve(buflen / 4);
for (pu += bom; pu < pumax; pu++)
{ unsigned u;
u = le ? readlongLE(pu) : readlongBE(pu);
if (u & ~0x7F)
{
if (u > 0x10FFFF)
{ error("UTF-32 value %08x greater than 0x10FFFF", u);
fatal();
}
dbuf.writeUTF8(u);
}
else
dbuf.writeByte(u);
}
dbuf.writeByte(0); // add 0 as sentinel for scanner
buflen = dbuf.offset - 1; // don't include sentinel in count
buf = (unsigned char *) dbuf.extractData();
}
else
{ // UTF-16LE (X86)
// Convert it to UTF-8
le = 1;
Lutf16:
OutBuffer dbuf;
unsigned short *pu = (unsigned short *)(buf);
unsigned short *pumax = &pu[buflen / 2];
if (buflen & 1)
{ error("odd length of UTF-16 char source %u", buflen);
fatal();
}
dbuf.reserve(buflen / 2);
for (pu += bom; pu < pumax; pu++)
{ unsigned u;
u = le ? readwordLE(pu) : readwordBE(pu);
if (u & ~0x7F)
{ if (u >= 0xD800 && u <= 0xDBFF)
{ unsigned u2;
if (++pu > pumax)
{ error("surrogate UTF-16 high value %04x at EOF", u);
fatal();
}
u2 = le ? readwordLE(pu) : readwordBE(pu);
if (u2 < 0xDC00 || u2 > 0xDFFF)
{ error("surrogate UTF-16 low value %04x out of range", u2);
fatal();
}
u = (u - 0xD7C0) << 10;
u |= (u2 - 0xDC00);
}
//.........这里部分代码省略.........
示例5: if
Module *Module::load(Loc loc, Array *packages, Identifier *ident)
{ Module *m;
char *filename;
//printf("Module::load(ident = '%s')\n", ident->toChars());
// Build module filename by turning:
// foo.bar.baz
// into:
// foo\bar\baz
filename = ident->toChars();
if (packages && packages->dim)
{
OutBuffer buf;
int i;
for (i = 0; i < packages->dim; i++)
{ Identifier *pid = (Identifier *)packages->data[i];
buf.writestring(pid->toChars());
#if _WIN32
buf.writeByte('\\');
#else
buf.writeByte('/');
#endif
}
buf.writestring(filename);
buf.writeByte(0);
filename = (char *)buf.extractData();
}
m = new Module(filename, ident, 0, 0);
m->loc = loc;
/* Search along global.path for .di file, then .d file.
*/
char *result = NULL;
FileName *fdi = FileName::forceExt(filename, global.hdr_ext);
FileName *fd = FileName::forceExt(filename, global.mars_ext);
char *sdi = fdi->toChars();
char *sd = fd->toChars();
if (FileName::exists(sdi))
result = sdi;
else if (FileName::exists(sd))
result = sd;
else if (FileName::absolute(filename))
;
else if (!global.path)
;
else
{
for (size_t i = 0; i < global.path->dim; i++)
{
char *p = (char *)global.path->data[i];
char *n = FileName::combine(p, sdi);
if (FileName::exists(n))
{ result = n;
break;
}
mem.free(n);
n = FileName::combine(p, sd);
if (FileName::exists(n))
{ result = n;
break;
}
mem.free(n);
}
}
if (result)
m->srcfile = new File(result);
if (global.params.verbose)
{
printf("import ");
if (packages)
{
for (size_t i = 0; i < packages->dim; i++)
{ Identifier *pid = (Identifier *)packages->data[i];
printf("%s.", pid->toChars());
}
}
printf("%s\t(%s)\n", ident->toChars(), m->srcfile->toChars());
}
m->read(loc);
m->parse();
#ifdef IN_GCC
d_gcc_magic_module(m);
#endif
return m;
}
示例6: obj_write_deferred
void obj_write_deferred(Library *library)
{
for (int i = 0; i < obj_symbols_towrite.dim; i++)
{ Dsymbol *s = (Dsymbol *)obj_symbols_towrite.data[i];
Module *m = s->getModule();
char *mname;
if (m)
{ mname = m->srcfile->toChars();
lastmname = mname;
}
else
{
//mname = s->ident->toChars();
mname = lastmname;
assert(mname);
}
obj_start(mname);
static int count;
count++; // sequence for generating names
/* Create a module that's a doppelganger of m, with just
* enough to be able to create the moduleinfo.
*/
OutBuffer idbuf;
idbuf.printf("%s.%d", m ? m->ident->toChars() : mname, count);
char *idstr = idbuf.toChars();
idbuf.data = NULL;
Identifier *id = new Identifier(idstr, TOKidentifier);
Module *md = new Module(mname, id, 0, 0);
md->members = new Array();
md->members->push(s); // its only 'member' is s
if (m)
{
md->doppelganger = 1; // identify this module as doppelganger
md->md = m->md;
md->aimports.push(m); // it only 'imports' m
md->massert = m->massert;
md->marray = m->marray;
}
md->genobjfile(0);
/* Set object file name to be source name with sequence number,
* as mangled symbol names get way too long.
*/
char *fname = FileName::removeExt(mname);
OutBuffer namebuf;
unsigned hash = 0;
for (char *p = s->toChars(); *p; p++)
hash += *p;
namebuf.printf("%s_%x_%x.%s", fname, count, hash, global.obj_ext);
namebuf.writeByte(0);
mem.free(fname);
fname = (char *)namebuf.extractData();
//printf("writing '%s'\n", fname);
File *objfile = new File(fname);
obj_end(library, objfile);
}
obj_symbols_towrite.dim = 0;
}
示例7: Strings
// Split a path into an Array of paths
Strings *FileName::splitPath(const char *path)
{
char c = 0; // unnecessary initializer is for VC /W4
const char *p;
OutBuffer buf;
Strings *array;
array = new Strings();
if (path)
{
p = path;
do
{ char instring = 0;
while (isspace((unsigned char)*p)) // skip leading whitespace
p++;
buf.reserve(strlen(p) + 1); // guess size of path
for (; ; p++)
{
c = *p;
switch (c)
{
case '"':
instring ^= 1; // toggle inside/outside of string
continue;
#if MACINTOSH
case ',':
#endif
#if _WIN32
case ';':
#endif
#if POSIX
case ':':
#endif
p++;
break; // note that ; cannot appear as part
// of a path, quotes won't protect it
case 0x1A: // ^Z means end of file
case 0:
break;
case '\r':
continue; // ignore carriage returns
#if POSIX
case '~':
buf.writestring(getenv("HOME"));
continue;
#endif
#if 0
case ' ':
case '\t': // tabs in filenames?
if (!instring) // if not in string
break; // treat as end of path
#endif
default:
buf.writeByte(c);
continue;
}
break;
}
if (buf.offset) // if path is not empty
{
buf.writeByte(0); // to asciiz
array->push(buf.extractData());
}
} while (c);
}
return array;
}
示例8: runLINK
//.........这里部分代码省略.........
const char *windowssdkdir = getenv("WindowsSdkDir");
if (windowssdkdir)
{ cmdbuf.writestring(" \"/LIBPATH:");
cmdbuf.writestring(windowssdkdir);
cmdbuf.writestring("lib\\x64\"");
}
char *p = cmdbuf.toChars();
const char *lnkfilename = NULL;
size_t plen = strlen(p);
if (plen > 7000)
{
lnkfilename = FileName::forceExt(global.params.exefile, "lnk");
File flnk(lnkfilename);
flnk.setbuffer(p, plen);
flnk.ref = 1;
if (flnk.write())
error(Loc(), "error writing file %s", lnkfilename);
if (strlen(lnkfilename) < plen)
sprintf(p, "@%s", lnkfilename);
}
char *linkcmd = getenv("LINKCMD64");
if (!linkcmd)
{
if (vcinstalldir)
{
OutBuffer linkcmdbuf;
linkcmdbuf.writestring(vcinstalldir);
linkcmdbuf.writestring("bin\\amd64\\link");
linkcmd = linkcmdbuf.toChars();
linkcmdbuf.extractData();
}
else
linkcmd = "link";
}
int status = executecmd(linkcmd, p, 1);
if (lnkfilename)
{
remove(lnkfilename);
FileName::free(lnkfilename);
}
return status;
}
else
{
OutBuffer cmdbuf;
global.params.libfiles->push("user32");
global.params.libfiles->push("kernel32");
for (size_t i = 0; i < global.params.objfiles->dim; i++)
{
if (i)
cmdbuf.writeByte('+');
const char *p = (*global.params.objfiles)[i];
const char *basename = FileName::removeExt(FileName::name(p));
const char *ext = FileName::ext(p);
if (ext && !strchr(basename, '.'))
// Write name sans extension (but not if a double extension)
writeFilename(&cmdbuf, p, ext - p - 1);
else
writeFilename(&cmdbuf, p);
FileName::free(basename);
示例9: ErrorExp
Expression *BinExp::arrayOp(Scope *sc)
{
//printf("BinExp::arrayOp() %s\n", toChars());
if (type->toBasetype()->nextOf()->toBasetype()->ty == Tvoid)
{
error("Cannot perform array operations on void[] arrays");
return new ErrorExp();
}
Expressions *arguments = new Expressions();
/* The expression to generate an array operation for is mangled
* into a name to use as the array operation function name.
* Mangle in the operands and operators in RPN order, and type.
*/
OutBuffer buf;
buf.writestring("_array");
buildArrayIdent(&buf, arguments);
buf.writeByte('_');
/* Append deco of array element type
*/
#if DMDV2
buf.writestring(type->toBasetype()->nextOf()->toBasetype()->mutableOf()->deco);
#else
buf.writestring(type->toBasetype()->nextOf()->toBasetype()->deco);
#endif
size_t namelen = buf.offset;
buf.writeByte(0);
char *name = (char *)buf.extractData();
/* Look up name in hash table
*/
StringValue *sv = arrayfuncs.update(name, namelen);
FuncDeclaration *fd = (FuncDeclaration *)sv->ptrvalue;
if (!fd)
{
/* Some of the array op functions are written as library functions,
* presumably to optimize them with special CPU vector instructions.
* List those library functions here, in alpha order.
*/
static const char *libArrayopFuncs[] =
{
"_arrayExpSliceAddass_a",
"_arrayExpSliceAddass_d", // T[]+=T
"_arrayExpSliceAddass_f", // T[]+=T
"_arrayExpSliceAddass_g",
"_arrayExpSliceAddass_h",
"_arrayExpSliceAddass_i",
"_arrayExpSliceAddass_k",
"_arrayExpSliceAddass_s",
"_arrayExpSliceAddass_t",
"_arrayExpSliceAddass_u",
"_arrayExpSliceAddass_w",
"_arrayExpSliceDivass_d", // T[]/=T
"_arrayExpSliceDivass_f", // T[]/=T
"_arrayExpSliceMinSliceAssign_a",
"_arrayExpSliceMinSliceAssign_d", // T[]=T-T[]
"_arrayExpSliceMinSliceAssign_f", // T[]=T-T[]
"_arrayExpSliceMinSliceAssign_g",
"_arrayExpSliceMinSliceAssign_h",
"_arrayExpSliceMinSliceAssign_i",
"_arrayExpSliceMinSliceAssign_k",
"_arrayExpSliceMinSliceAssign_s",
"_arrayExpSliceMinSliceAssign_t",
"_arrayExpSliceMinSliceAssign_u",
"_arrayExpSliceMinSliceAssign_w",
"_arrayExpSliceMinass_a",
"_arrayExpSliceMinass_d", // T[]-=T
"_arrayExpSliceMinass_f", // T[]-=T
"_arrayExpSliceMinass_g",
"_arrayExpSliceMinass_h",
"_arrayExpSliceMinass_i",
"_arrayExpSliceMinass_k",
"_arrayExpSliceMinass_s",
"_arrayExpSliceMinass_t",
"_arrayExpSliceMinass_u",
"_arrayExpSliceMinass_w",
"_arrayExpSliceMulass_d", // T[]*=T
"_arrayExpSliceMulass_f", // T[]*=T
"_arrayExpSliceMulass_i",
"_arrayExpSliceMulass_k",
"_arrayExpSliceMulass_s",
"_arrayExpSliceMulass_t",
"_arrayExpSliceMulass_u",
"_arrayExpSliceMulass_w",
"_arraySliceExpAddSliceAssign_a",
"_arraySliceExpAddSliceAssign_d", // T[]=T[]+T
"_arraySliceExpAddSliceAssign_f", // T[]=T[]+T
"_arraySliceExpAddSliceAssign_g",
"_arraySliceExpAddSliceAssign_h",
"_arraySliceExpAddSliceAssign_i",
"_arraySliceExpAddSliceAssign_k",
//.........这里部分代码省略.........
示例10: semantic
void VarDeclaration::semantic(Scope *sc)
{
#if 0
printf("VarDeclaration::semantic('%s', parent = '%s')\n", toChars(), sc->parent->toChars());
printf(" type = %s\n", type ? type->toChars() : "null");
printf(" stc = x%x\n", sc->stc);
printf(" storage_class = x%x\n", storage_class);
printf("linkage = %d\n", sc->linkage);
//if (strcmp(toChars(), "mul") == 0) halt();
#endif
storage_class |= sc->stc;
if (storage_class & STCextern && init)
error("extern symbols cannot have initializers");
AggregateDeclaration *ad = isThis();
if (ad)
storage_class |= ad->storage_class & STC_TYPECTOR;
/* If auto type inference, do the inference
*/
int inferred = 0;
if (!type)
{ inuse++;
type = init->inferType(sc);
inuse--;
inferred = 1;
/* This is a kludge to support the existing syntax for RAII
* declarations.
*/
storage_class &= ~STCauto;
originalType = type;
}
else
{ if (!originalType)
originalType = type;
type = type->semantic(loc, sc);
}
//printf(" semantic type = %s\n", type ? type->toChars() : "null");
type->checkDeprecated(loc, sc);
linkage = sc->linkage;
this->parent = sc->parent;
//printf("this = %p, parent = %p, '%s'\n", this, parent, parent->toChars());
protection = sc->protection;
//printf("sc->stc = %x\n", sc->stc);
//printf("storage_class = x%x\n", storage_class);
#if DMDV2
if (storage_class & STCgshared && global.params.safe && !sc->module->safe)
{
error("__gshared not allowed in safe mode; use shared");
}
#endif
Dsymbol *parent = toParent();
FuncDeclaration *fd = parent->isFuncDeclaration();
Type *tb = type->toBasetype();
if (tb->ty == Tvoid && !(storage_class & STClazy))
{ error("voids have no value");
type = Type::terror;
tb = type;
}
if (tb->ty == Tfunction)
{ error("cannot be declared to be a function");
type = Type::terror;
tb = type;
}
if (tb->ty == Tstruct)
{ TypeStruct *ts = (TypeStruct *)tb;
if (!ts->sym->members)
{
error("no definition of struct %s", ts->toChars());
}
}
if ((storage_class & STCauto) && !inferred)
error("storage class 'auto' has no effect if type is not inferred, did you mean 'scope'?");
if (tb->ty == Ttuple)
{ /* Instead, declare variables for each of the tuple elements
* and add those.
*/
TypeTuple *tt = (TypeTuple *)tb;
size_t nelems = Parameter::dim(tt->arguments);
Objects *exps = new Objects();
exps->setDim(nelems);
Expression *ie = init ? init->toExpression() : NULL;
for (size_t i = 0; i < nelems; i++)
{ Parameter *arg = Parameter::getNth(tt->arguments, i);
OutBuffer buf;
buf.printf("_%s_field_%zu", ident->toChars(), i);
buf.writeByte(0);
const char *name = (const char *)buf.extractData();
Identifier *id = Lexer::idPool(name);
//.........这里部分代码省略.........
示例11: parse
void Module::parse()
{
//printf("Module::parse()\n");
char *srcname = srcfile->name->toChars();
//printf("Module::parse(srcname = '%s')\n", srcname);
utf8_t *buf = (utf8_t *)srcfile->buffer;
size_t buflen = srcfile->len;
if (buflen >= 2)
{
/* Convert all non-UTF-8 formats to UTF-8.
* BOM : http://www.unicode.org/faq/utf_bom.html
* 00 00 FE FF UTF-32BE, big-endian
* FF FE 00 00 UTF-32LE, little-endian
* FE FF UTF-16BE, big-endian
* FF FE UTF-16LE, little-endian
* EF BB BF UTF-8
*/
unsigned le;
unsigned bom = 1; // assume there's a BOM
if (buf[0] == 0xFF && buf[1] == 0xFE)
{
if (buflen >= 4 && buf[2] == 0 && buf[3] == 0)
{ // UTF-32LE
le = 1;
Lutf32:
OutBuffer dbuf;
unsigned *pu = (unsigned *)(buf);
unsigned *pumax = &pu[buflen / 4];
if (buflen & 3)
{ error("odd length of UTF-32 char source %u", buflen);
fatal();
}
dbuf.reserve(buflen / 4);
for (pu += bom; pu < pumax; pu++)
{ unsigned u;
u = le ? readlongLE(pu) : readlongBE(pu);
if (u & ~0x7F)
{
if (u > 0x10FFFF)
{ error("UTF-32 value %08x greater than 0x10FFFF", u);
fatal();
}
dbuf.writeUTF8(u);
}
else
dbuf.writeByte(u);
}
dbuf.writeByte(0); // add 0 as sentinel for scanner
buflen = dbuf.offset - 1; // don't include sentinel in count
buf = (utf8_t *) dbuf.extractData();
}
else
{ // UTF-16LE (X86)
// Convert it to UTF-8
le = 1;
Lutf16:
OutBuffer dbuf;
unsigned short *pu = (unsigned short *)(buf);
unsigned short *pumax = &pu[buflen / 2];
if (buflen & 1)
{ error("odd length of UTF-16 char source %u", buflen);
fatal();
}
dbuf.reserve(buflen / 2);
for (pu += bom; pu < pumax; pu++)
{ unsigned u;
u = le ? readwordLE(pu) : readwordBE(pu);
if (u & ~0x7F)
{ if (u >= 0xD800 && u <= 0xDBFF)
{ unsigned u2;
if (++pu > pumax)
{ error("surrogate UTF-16 high value %04x at EOF", u);
fatal();
}
u2 = le ? readwordLE(pu) : readwordBE(pu);
if (u2 < 0xDC00 || u2 > 0xDFFF)
{ error("surrogate UTF-16 low value %04x out of range", u2);
fatal();
}
u = (u - 0xD7C0) << 10;
u |= (u2 - 0xDC00);
}
else if (u >= 0xDC00 && u <= 0xDFFF)
{ error("unpaired surrogate UTF-16 value %04x", u);
fatal();
}
else if (u == 0xFFFE || u == 0xFFFF)
//.........这里部分代码省略.........
示例12: Module
Module *Module::load(Loc loc, Identifiers *packages, Identifier *ident)
{ Module *m;
char *filename;
//printf("Module::load(ident = '%s')\n", ident->toChars());
// Build module filename by turning:
// foo.bar.baz
// into:
// foo\bar\baz
filename = ident->toChars();
if (packages && packages->dim)
{
OutBuffer buf;
for (size_t i = 0; i < packages->dim; i++)
{ Identifier *pid = (*packages)[i];
buf.writestring(pid->toChars());
#if _WIN32
buf.writeByte('\\');
#else
buf.writeByte('/');
#endif
}
buf.writestring(filename);
buf.writeByte(0);
filename = (char *)buf.extractData();
}
m = new Module(filename, ident, 0, 0);
m->loc = loc;
/* Look for the source file
*/
const char *result = lookForSourceFile(filename);
if (result)
m->srcfile = new File(result);
if (global.params.verbose)
{
fprintf(global.stdmsg, "import ");
if (packages)
{
for (size_t i = 0; i < packages->dim; i++)
{ Identifier *pid = (*packages)[i];
fprintf(global.stdmsg, "%s.", pid->toChars());
}
}
fprintf(global.stdmsg, "%s\t(%s)\n", ident->toChars(), m->srcfile->toChars());
}
if (!m->read(loc))
return NULL;
m->parse();
#ifdef IN_GCC
d_gcc_magic_module(m);
#endif
return m;
}
示例13: ErrorExp
//.........这里部分代码省略.........
if (p)
error("%s", p);
else
buffer.writeUTF8(c);
}
newlen = buffer.offset;
buffer.writeUTF8(0);
goto L1;
case X(Twchar,Tdchar):
for (size_t u = 0; u < len;)
{ unsigned c;
const char *p = utf_decodeWchar((unsigned short *)se->string, len, &u, &c);
if (p)
error("%s", p);
buffer.write4(c);
newlen++;
}
buffer.write4(0);
goto L1;
case X(Tdchar,Tchar):
for (size_t u = 0; u < len; u++)
{
unsigned c = ((unsigned *)se->string)[u];
if (!utf_isValidDchar(c))
error("invalid UCS-32 char \\U%08x", c);
else
buffer.writeUTF8(c);
newlen++;
}
newlen = buffer.offset;
buffer.writeUTF8(0);
goto L1;
case X(Tdchar,Twchar):
for (size_t u = 0; u < len; u++)
{
unsigned c = ((unsigned *)se->string)[u];
if (!utf_isValidDchar(c))
error("invalid UCS-32 char \\U%08x", c);
else
buffer.writeUTF16(c);
newlen++;
}
newlen = buffer.offset / 2;
buffer.writeUTF16(0);
goto L1;
L1:
if (!copied)
{ se = (StringExp *)copy();
copied = 1;
}
se->string = buffer.extractData();
se->len = newlen;
se->sz = tb->nextOf()->size();
break;
default:
assert(typeb->nextOf()->size() != tb->nextOf()->size());
goto Lcast;
}
}
#undef X
L2:
assert(copied);
// See if need to truncate or extend the literal
if (tb->ty == Tsarray)
{
int dim2 = ((TypeSArray *)tb)->dim->toInteger();
//printf("dim from = %d, to = %d\n", se->len, dim2);
// Changing dimensions
if (dim2 != se->len)
{
// Copy when changing the string literal
unsigned newsz = se->sz;
void *s;
int d;
d = (dim2 < se->len) ? dim2 : se->len;
s = (unsigned char *)mem.malloc((dim2 + 1) * newsz);
memcpy(s, se->string, d * newsz);
// Extend with 0, add terminating 0
memset((char *)s + d * newsz, 0, (dim2 + 1 - d) * newsz);
se->string = s;
se->len = dim2;
}
}
se->type = t;
return se;
Lcast:
Expression *e = new CastExp(loc, se, t);
e->type = t; // so semantic() won't be run on e
return e;
}
示例14: obj_write_deferred
void obj_write_deferred(Library *library)
{
for (size_t i = 0; i < obj_symbols_towrite.dim; i++)
{ Dsymbol *s = obj_symbols_towrite[i];
Module *m = s->getModule();
char *mname;
if (m)
{ mname = m->srcfile->toChars();
lastmname = mname;
}
else
{
//mname = s->ident->toChars();
mname = lastmname;
assert(mname);
}
obj_start(mname);
static int count;
count++; // sequence for generating names
/* Create a module that's a doppelganger of m, with just
* enough to be able to create the moduleinfo.
*/
OutBuffer idbuf;
idbuf.printf("%s.%d", m ? m->ident->toChars() : mname, count);
char *idstr = idbuf.toChars();
if(!m)
{
// it doesn't make sense to make up a module if we don't know where to put the symbol
// so output it into it's own object file without ModuleInfo
objmod->initfile(idstr, NULL, mname);
s->toObjFile(0);
objmod->termfile();
}
else
{
idbuf.data = NULL;
Identifier *id = Identifier::create(idstr, TOKidentifier);
Module *md = Module::create(mname, id, 0, 0);
md->members = Dsymbols_create();
md->members->push(s); // its only 'member' is s
md->doppelganger = 1; // identify this module as doppelganger
md->md = m->md;
md->aimports.push(m); // it only 'imports' m
md->massert = m->massert;
md->munittest = m->munittest;
md->marray = m->marray;
md->genobjfile(0);
}
/* Set object file name to be source name with sequence number,
* as mangled symbol names get way too long.
*/
const char *fname = FileName::removeExt(mname);
OutBuffer namebuf;
unsigned hash = 0;
for (char *p = s->toChars(); *p; p++)
hash += *p;
namebuf.printf("%s_%x_%x.%s", fname, count, hash, global.obj_ext);
namebuf.writeByte(0);
FileName::free((char *)fname);
fname = (char *)namebuf.extractData();
//printf("writing '%s'\n", fname);
File *objfile = File::create(fname);
obj_end(library, objfile);
}
obj_symbols_towrite.dim = 0;
}