Skip to content

Commit

Permalink
Merge v2.091.0-beta.1
Browse files Browse the repository at this point in the history
  • Loading branch information
kinke committed Feb 26, 2020
1 parent 3327def commit 685e31c
Show file tree
Hide file tree
Showing 8 changed files with 104 additions and 92 deletions.
4 changes: 2 additions & 2 deletions dmd/cli.d
Original file line number Diff line number Diff line change
Expand Up @@ -750,9 +750,9 @@ dmd -cov -unittest myprog.d
Feature("dip1000", "vsafe",
"implement https://github.com/dlang/DIPs/blob/master/DIPs/other/DIP1000.md (Scoped Pointers)"),
Feature("dip1008", "ehnogc",
"implement https://github.com/dlang/DIPs/blob/master/DIPs/DIP1008.md (@nogc Throwable)"),
"implement https://github.com/dlang/DIPs/blob/master/DIPs/other/DIP1008.md (@nogc Throwable)"),
Feature("dip1021", "useDIP1021",
"implement https://github.com/dlang/DIPs/blob/master/DIPs/DIP1021.md (Mutable function arguments)"),
"implement https://github.com/dlang/DIPs/blob/master/DIPs/accepted/DIP1021.md (Mutable function arguments)"),
Feature("fieldwise", "fieldwise", "use fieldwise comparisons for struct equality"),
Feature("markdown", "markdown", "enable Markdown replacements in Ddoc"),
Feature("fixAliasThis", "fixAliasThis",
Expand Down
128 changes: 58 additions & 70 deletions dmd/dtoh.d
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,7 @@ import dmd.astcodegen;
import dmd.arraytypes;
import dmd.globals;
import dmd.identifier;
import dmd.json;
import dmd.mars;
import dmd.root.array;
import dmd.root.file;
import dmd.root.filename;
import dmd.root.rmem;
import dmd.visitor;
import dmd.tokens;

Expand All @@ -44,6 +39,7 @@ private struct DMDType
__gshared Identifier c_longlong;
__gshared Identifier c_ulonglong;
__gshared Identifier c_long_double;
__gshared Identifier c_wchar_t;
__gshared Identifier AssocArray;
__gshared Identifier Array;

Expand All @@ -54,6 +50,7 @@ private struct DMDType
c_longlong = Identifier.idPool("__c_longlong");
c_ulonglong = Identifier.idPool("__c_ulonglong");
c_long_double = Identifier.idPool("__c_long_double");
c_wchar_t = Identifier.idPool("__c_wchar_t");

if (isBuildingCompiler)
{
Expand Down Expand Up @@ -176,6 +173,33 @@ private bool isFrontendModule(ASTCodegen.Module m)
(m.parent.parent.ident == DMDModule.dmd && !m.parent.parent.parent));
}

private string translateBasicType(ubyte ty)
{
import AST = dmd.mtype;
switch (ty)
{
case AST.Tvoid: return "void";
case AST.Tbool: return "bool";
case AST.Tchar: return "char";
case AST.Twchar: return "char16_t";
case AST.Tdchar: return "char32_t";
case AST.Tint8: return "int8_t";
case AST.Tuns8: return "uint8_t";
case AST.Tint16: return "int16_t";
case AST.Tuns16: return "uint16_t";
case AST.Tint32: return "int32_t";
case AST.Tuns32: return "uint32_t";
case AST.Tint64: return "int64_t";
case AST.Tuns64: return "uint64_t";
case AST.Tfloat32: return "float";
case AST.Tfloat64: return "double";
case AST.Tfloat80: return "_d_real";
default:
//t.print();
assert(0);
}
}

private void initialize()
{
__gshared bool initialized;
Expand All @@ -193,47 +217,24 @@ private void initialize()
}
}

void genCppHdrFiles(ref Modules ms)
extern(C++) void genCppHdrFiles(ref Modules ms)
{
initialize();

OutBuffer buf;
buf.writestring("#pragma once\n");
buf.printf("// Automatically generated by %s Compiler v%d\n", global.vendor.ptr, global.versionNumber());
buf.writeByte('\n');
buf.printf("// Automatically generated by dmd -HC\n");
buf.writestring("#pragma once\n");
buf.writeByte('\n');
buf.writestring("#include <assert.h>\n");
buf.writestring("#include <stddef.h>\n");
buf.writestring("#include <stdint.h>\n");
buf.writestring("#include <stdio.h>\n");
buf.writestring("#include <string.h>\n");
buf.writeByte('\n');
buf.writestring("#define _d_void void\n");
buf.writestring("#define _d_bool bool\n");
buf.writestring("#define _d_byte signed char\n");
buf.writestring("#define _d_ubyte unsigned char\n");
buf.writestring("#define _d_short short\n");
buf.writestring("#define _d_ushort unsigned short\n");
buf.writestring("#define _d_int int\n");
buf.writestring("#define _d_uint unsigned\n");
if (global.params.isLP64)
{
buf.writestring("#define _d_long long\n");
buf.writestring("#define _d_ulong unsigned long\n");
}
else
{
buf.writestring("#define _d_long long long\n");
buf.writestring("#define _d_ulong unsigned long long\n");
}
buf.writestring("#define _d_float float\n");
buf.writestring("#define _d_double double\n");
buf.writestring("#define _d_real long double\n");
buf.writestring("#define _d_char char\n");
buf.writestring("#define _d_wchar wchar_t\n");
buf.writestring("#define _d_dchar unsigned\n");
buf.writestring("typedef _d_long d_int64;\n");
buf.writestring("\n");
buf.writestring("#define _d_null NULL\n");
buf.writestring("#if !defined(_d_real)\n");
buf.writestring("# define _d_real long double\n");
buf.writestring("#endif\n");
buf.writestring("\n\n");

OutBuffer check;
Expand Down Expand Up @@ -1005,8 +1006,8 @@ public:
else
{
//printf("Using cpp 98\n");
buf.writestring("typedef _d_");
buf.writestring(ed.memtype.kind);
buf.writestring("typedef ");
buf.writestring(translateBasicType(ed.memtype.ty));
buf.writeByte(' ');
buf.writestring(ident);
buf.writestring(";\n");
Expand Down Expand Up @@ -1114,22 +1115,7 @@ public:
}
if (!cdparent && t.isConst())
buf.writestring("const ");
switch (t.ty)
{
case AST.Tbool, AST.Tvoid:
case AST.Tchar, AST.Twchar, AST.Tdchar:
case AST.Tint8, AST.Tuns8:
case AST.Tint16, AST.Tuns16:
case AST.Tint32, AST.Tuns32:
case AST.Tint64, AST.Tuns64:
case AST.Tfloat32, AST.Tfloat64, AST.Tfloat80:
buf.writestring("_d_");
buf.writestring(t.dstring);
break;
default:
//t.print();
assert(0);
}
buf.writestring(translateBasicType(t.ty));
}

override void visit(AST.TypePointer t)
Expand Down Expand Up @@ -1212,25 +1198,27 @@ public:
}
if (ed.isSpecial())
{
buf.writestring(ed.toChars());
if (ed.ident == DMDType.c_long)
buf.writestring("long");
else if (ed.ident == DMDType.c_ulong)
buf.writestring("unsigned long");
else if (ed.ident == DMDType.c_longlong)
buf.writestring("long long");
else if (ed.ident == DMDType.c_ulonglong)
buf.writestring("unsigned long long");
else if (ed.ident == DMDType.c_long_double)
buf.writestring("long double");
else if (ed.ident == DMDType.c_wchar_t)
buf.writestring("wchar_t");
else
{
//ed.print();
assert(0);
}
return;
}

if (ed.ident == DMDType.c_long)
buf.writestring("long");
else if (ed.ident == DMDType.c_ulong)
buf.writestring("unsigned long");
else if (ed.ident == DMDType.c_longlong)
buf.writestring("long long");
else if (ed.ident == DMDType.c_ulonglong)
buf.writestring("unsigned long long");
else if (ed.ident == DMDType.c_long_double)
buf.writestring("long double");
else
{
//ed.print();
assert(0);
}
buf.writestring(ed.toChars());
}

override void visit(AST.TypeEnum t)
Expand Down Expand Up @@ -1548,7 +1536,7 @@ public:
printf("[AST.NullExp enter] %s\n", e.toChars());
scope(exit) printf("[AST.NullExp exit] %s\n", e.toChars());
}
buf.writestring("_d_null");
buf.writestring("nullptr");
}

override void visit(AST.ArrayLiteralExp e)
Expand Down
2 changes: 1 addition & 1 deletion dmd/globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ struct Param
bool useInline; // inline expand functions
bool useDIP25; // implement http://wiki.dlang.org/DIP25
bool noDIP25; // revert to pre-DIP25 behavior
bool useDIP1021; // implement https://github.com/dlang/DIPs/blob/master/DIPs/DIP1021.md
bool useDIP1021; // implement https://github.com/dlang/DIPs/blob/master/DIPs/accepted/DIP1021.md
bool release; // build release version
bool preservePaths; // true means don't strip path from source file
Diagnostic warnings;
Expand Down
1 change: 1 addition & 0 deletions dmd/hdrgen.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@
class Module;

void genhdrfile(Module *m);
void genCppHdrFiles(Modules &ms);
void moduleToBuffer(OutBuffer *buf, Module *m);
const char *parametersTypeToChars(ParameterList pl);
55 changes: 39 additions & 16 deletions dmd/iasmgcc.d
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@ int parseExtAsmOperands(Parser)(Parser p, GccAsmStatement s)
case TOK.leftBracket:
if (p.peekNext() == TOK.identifier)
{
// Skip over opening `[`
p.nextToken();
// Store the symbolic name
name = p.token.ident;
p.nextToken();
}
Expand All @@ -76,8 +78,13 @@ int parseExtAsmOperands(Parser)(Parser p, GccAsmStatement s)
p.error(s.loc, "expected identifier after `[`");
goto Lerror;
}
// Look for closing `]`
p.check(TOK.rightBracket);
goto case;
// Look for the string literal and fall through
if (p.token.value == TOK.string_)
goto case;
else
goto default;

case TOK.string_:
constraint = p.parsePrimaryExp();
Expand Down Expand Up @@ -285,8 +292,7 @@ extern(C++) // IN_LLVM
public Statement gccAsmSemantic(GccAsmStatement s, Scope *sc)
{
//printf("GccAsmStatement.semantic()\n");
scope diagnosticReporter = new StderrDiagnosticReporter(global.params.useDeprecated);
scope p = new Parser!ASTCodegen(sc._module, ";", false, diagnosticReporter);
scope p = new Parser!ASTCodegen(sc._module, ";", false);

// Make a safe copy of the token list before parsing.
Token *toklist = null;
Expand All @@ -303,8 +309,9 @@ public Statement gccAsmSemantic(GccAsmStatement s, Scope *sc)
p.scanloc = s.loc;

// Parse the gcc asm statement.
const errors = global.errors;
s = p.parseGccAsm(s);
if (p.errors)
if (errors != global.errors)
return null;
s.stc = sc.stc;

Expand Down Expand Up @@ -366,25 +373,41 @@ public Statement gccAsmSemantic(GccAsmStatement s, Scope *sc)

unittest
{
import dmd.mtype : TypeBasic;

uint errors = global.startGagging();
scope(exit) global.endGagging(errors);

// If this check fails, then Type._init() was called before reaching here,
// and the entire chunk of code that follows can be removed.
assert(ASTCodegen.Type.tint32 is null);
// Minimally initialize the cached types in ASTCodegen.Type, as they are
// dependencies for some fail asm tests to succeed.
ASTCodegen.Type.stringtable._init();
scope(exit)
{
ASTCodegen.Type.deinitialize();
ASTCodegen.Type.tint32 = null;
}
scope tint32 = new TypeBasic(ASTCodegen.Tint32);
ASTCodegen.Type.tint32 = tint32;

// Immitates asmSemantic if version = IN_GCC.
// Imitates asmSemantic if version = IN_GCC.
static int semanticAsm(Token* tokens)
{
const errors = global.errors;
scope gas = new GccAsmStatement(Loc.initial, tokens);
scope diagnosticReporter = new StderrDiagnosticReporter(global.params.useDeprecated);
scope p = new Parser!ASTCodegen(null, ";", false, diagnosticReporter);
scope p = new Parser!ASTCodegen(null, ";", false);
p.token = *tokens;
p.parseGccAsm(gas);
return p.errors;
return global.errors - errors;
}

// Immitates parseStatement for asm statements.
// Imitates parseStatement for asm statements.
static void parseAsm(string input, bool expectError)
{
// Generate tokens from input test.
scope diagnosticReporter = new StderrDiagnosticReporter(global.params.useDeprecated);
scope p = new Parser!ASTCodegen(null, input, false, diagnosticReporter);
scope p = new Parser!ASTCodegen(null, input, false);
p.nextToken();

Token* toklist = null;
Expand All @@ -404,7 +427,8 @@ unittest
p.check(TOK.rightCurly);

auto res = semanticAsm(toklist);
assert(res == 0 || expectError);
// Checks for both unexpected passes and failures.
assert((res == 0) != expectError);
}

/// Assembly Tests, all should pass.
Expand Down Expand Up @@ -455,7 +479,9 @@ unittest
q{ asm { ""h;
} },

/+ Need a way to test without depending on Type._init()
// https://issues.dlang.org/show_bug.cgi?id=20592
q{ asm { "nop" : [name] string (expr); } },

// Expression expected, not ';'
q{ asm { ""[;
} },
Expand All @@ -465,14 +491,11 @@ unittest
:
: "g" a ? b : : c;
} },
+/
];

foreach (test; passAsmTests)
parseAsm(test, false);

foreach (test; failAsmTests)
parseAsm(test, true);

global.endGagging(errors);
}

0 comments on commit 685e31c

Please sign in to comment.