diff options
author | Iain Buclaw <ibuclaw@gdcproject.org> | 2022-03-02 18:16:08 +0100 |
---|---|---|
committer | Iain Buclaw <ibuclaw@gdcproject.org> | 2022-03-02 18:21:38 +0100 |
commit | 8977f4bec650bb6975792772245b07b722ee9843 (patch) | |
tree | 495444470878e267304174ed409829358ae07740 /gcc/d | |
parent | 12f8dc0b642db5edc702f252af1a5231606b29db (diff) | |
download | gcc-8977f4bec650bb6975792772245b07b722ee9843.zip gcc-8977f4bec650bb6975792772245b07b722ee9843.tar.gz gcc-8977f4bec650bb6975792772245b07b722ee9843.tar.bz2 |
d: Merge upstream dmd 423f19b41, druntime 100a608c, phobos a1f8c4c07.
D Runtime changes:
- Fix stdc.stdio bindings to not depend on druntime (PR104729).
- Implement stdc.math for Solaris (PR104735).
gcc/d/ChangeLog:
* dmd/MERGE: Merge upstream dmd 423f19b41.
libphobos/ChangeLog:
* libdruntime/MERGE: Merge upstream druntime 100a608c.
* src/MERGE: Merge upstream phobos a1f8c4c07.
Diffstat (limited to 'gcc/d')
-rw-r--r-- | gcc/d/dmd/MERGE | 2 | ||||
-rw-r--r-- | gcc/d/dmd/dtemplate.d | 9 | ||||
-rw-r--r-- | gcc/d/dmd/expression.d | 161 | ||||
-rw-r--r-- | gcc/d/dmd/lexer.d | 71 | ||||
-rw-r--r-- | gcc/d/dmd/optimize.d | 21 | ||||
-rw-r--r-- | gcc/d/dmd/statementsem.d | 2 | ||||
-rw-r--r-- | gcc/d/dmd/tokens.d | 2 | ||||
-rw-r--r-- | gcc/d/dmd/tokens.h | 1 |
8 files changed, 253 insertions, 16 deletions
diff --git a/gcc/d/dmd/MERGE b/gcc/d/dmd/MERGE index f08d53a..71dc2b0 100644 --- a/gcc/d/dmd/MERGE +++ b/gcc/d/dmd/MERGE @@ -1,4 +1,4 @@ -cf63dd8e5a77ecb68cf5e7c43bf7b6c4c1154bbe +423f19b41089f627808bf16ff21c60c0791712ba The first line of this file holds the git revision number of the last merge done from the dlang/dmd repository. diff --git a/gcc/d/dmd/dtemplate.d b/gcc/d/dmd/dtemplate.d index 457c5d1..6abe69a 100644 --- a/gcc/d/dmd/dtemplate.d +++ b/gcc/d/dmd/dtemplate.d @@ -4295,8 +4295,13 @@ MATCH deduceType(RootObject o, Scope* sc, Type tparam, TemplateParameters* param if (ti && ti.toAlias() == t.sym) { auto tx = new TypeInstance(Loc.initial, ti); - result = deduceType(tx, sc, tparam, parameters, dedtypes, wm); - return; + auto m = deduceType(tx, sc, tparam, parameters, dedtypes, wm); + // if we have a no match we still need to check alias this + if (m != MATCH.nomatch) + { + result = m; + return; + } } /* Match things like: diff --git a/gcc/d/dmd/expression.d b/gcc/d/dmd/expression.d index b3aa0b2..2b41219 100644 --- a/gcc/d/dmd/expression.d +++ b/gcc/d/dmd/expression.d @@ -83,7 +83,7 @@ void emplaceExp(T : UnionExp)(T* p, Expression e) memcpy(p, cast(void*)e, e.size); } -// Return value for `checkModifiable` +/// Return value for `checkModifiable` enum Modifiable { /// Not modifiable @@ -1766,6 +1766,7 @@ extern (C++) abstract class Expression : ASTNode } /*********************************************************** + * A compile-time known integer value */ extern (C++) final class IntegerExp : Expression { @@ -1982,6 +1983,7 @@ extern (C++) final class IntegerExp : Expression /*********************************************************** * Use this expression for error recovery. + * * It should behave as a 'sink' to prevent further cascaded error messages. */ extern (C++) final class ErrorExp : Expression @@ -2026,6 +2028,8 @@ extern (C++) final class ErrorExp : Expression /*********************************************************** * An uninitialized value, * generated from void initializers. + * + * https://dlang.org/spec/declaration.html#void_init */ extern (C++) final class VoidInitExp : Expression { @@ -2052,6 +2056,7 @@ extern (C++) final class VoidInitExp : Expression /*********************************************************** + * A compile-time known floating point number */ extern (C++) final class RealExp : Expression { @@ -2127,6 +2132,7 @@ extern (C++) final class RealExp : Expression } /*********************************************************** + * A compile-time complex number (deprecated) */ extern (C++) final class ComplexExp : Expression { @@ -2202,6 +2208,12 @@ extern (C++) final class ComplexExp : Expression } /*********************************************************** + * An identifier in the context of an expression (as opposed to a declaration) + * + * --- + * int x; // VarDeclaration with Identifier + * x++; // PostExp with IdentifierExp + * --- */ extern (C++) class IdentifierExp : Expression { @@ -2235,6 +2247,9 @@ extern (C++) class IdentifierExp : Expression } /*********************************************************** + * The dollar operator used when indexing or slicing an array. E.g `a[$]`, `a[1 .. $]` etc. + * + * https://dlang.org/spec/arrays.html#array-length */ extern (C++) final class DollarExp : IdentifierExp { @@ -2353,6 +2368,8 @@ extern (C++) final class SuperExp : ThisExp } /*********************************************************** + * A compile-time known `null` value + * * https://dlang.org/spec/expression.html#null */ extern (C++) final class NullExp : Expression @@ -2791,6 +2808,12 @@ extern (C++) final class StringExp : Expression } /*********************************************************** + * A sequence of expressions + * + * --- + * alias AliasSeq(T...) = T; + * alias Tup = AliasSeq!(3, int, "abc"); + * --- */ extern (C++) final class TupleExp : Expression { @@ -4127,6 +4150,9 @@ extern (C++) final class TraitsExp : Expression } /*********************************************************** + * Generates a halt instruction + * + * `assert(0)` gets rewritten to this with `CHECKACTION.halt` */ extern (C++) final class HaltExp : Expression { @@ -4185,6 +4211,9 @@ extern (C++) final class IsExp : Expression } /*********************************************************** + * Base class for unary operators + * + * https://dlang.org/spec/expression.html#unary-expression */ extern (C++) abstract class UnaExp : Expression { @@ -4255,6 +4284,7 @@ alias fp_t = UnionExp function(const ref Loc loc, Type, Expression, Expression); alias fp2_t = bool function(const ref Loc loc, EXP, Expression, Expression); /*********************************************************** + * Base class for binary operators */ extern (C++) abstract class BinExp : Expression { @@ -4550,6 +4580,7 @@ extern (C++) abstract class BinExp : Expression } /*********************************************************** + * Binary operator assignment, `+=` `-=` `*=` etc. */ extern (C++) class BinAssignExp : BinExp { @@ -4582,6 +4613,8 @@ extern (C++) class BinAssignExp : BinExp } /*********************************************************** + * A string mixin, `mixin("x")` + * * https://dlang.org/spec/expression.html#mixin_expressions */ extern (C++) final class MixinExp : Expression @@ -4628,6 +4661,11 @@ extern (C++) final class MixinExp : Expression } /*********************************************************** + * An import expression, `import("file.txt")` + * + * Not to be confused with module imports, `import std.stdio`, which is an `ImportStatement` + * + * https://dlang.org/spec/expression.html#import_expressions */ extern (C++) final class ImportExp : UnaExp { @@ -4643,6 +4681,8 @@ extern (C++) final class ImportExp : UnaExp } /*********************************************************** + * An assert expression, `assert(x == y)` + * * https://dlang.org/spec/expression.html#assert_expressions */ extern (C++) final class AssertExp : UnaExp @@ -5153,6 +5193,7 @@ FuncDeclaration isFuncAddress(Expression e, bool* hasOverloads = null) } /*********************************************************** + * The 'address of' operator, `&p` */ extern (C++) final class AddrExp : UnaExp { @@ -5174,6 +5215,7 @@ extern (C++) final class AddrExp : UnaExp } /*********************************************************** + * The pointer dereference operator, `*p` */ extern (C++) final class PtrExp : UnaExp { @@ -5226,6 +5268,7 @@ extern (C++) final class PtrExp : UnaExp } /*********************************************************** + * The negation operator, `-x` */ extern (C++) final class NegExp : UnaExp { @@ -5241,6 +5284,7 @@ extern (C++) final class NegExp : UnaExp } /*********************************************************** + * The unary add operator, `+x` */ extern (C++) final class UAddExp : UnaExp { @@ -5256,6 +5300,7 @@ extern (C++) final class UAddExp : UnaExp } /*********************************************************** + * The bitwise complement operator, `~x` */ extern (C++) final class ComExp : UnaExp { @@ -5271,6 +5316,7 @@ extern (C++) final class ComExp : UnaExp } /*********************************************************** + * The logical not operator, `!x` */ extern (C++) final class NotExp : UnaExp { @@ -5286,6 +5332,9 @@ extern (C++) final class NotExp : UnaExp } /*********************************************************** + * The delete operator, `delete x` (deprecated) + * + * https://dlang.org/spec/expression.html#delete_expressions */ extern (C++) final class DeleteExp : UnaExp { @@ -5304,7 +5353,11 @@ extern (C++) final class DeleteExp : UnaExp } /*********************************************************** - * Possible to cast to one type while painting to another type + * The type cast operator, `cast(T) x` + * + * It's possible to cast to one type while painting to another type + * + * https://dlang.org/spec/expression.html#cast_expressions */ extern (C++) final class CastExp : UnaExp { @@ -5500,6 +5553,7 @@ extern (C++) final class SliceExp : UnaExp } /*********************************************************** + * The `.length` property of an array */ extern (C++) final class ArrayLengthExp : UnaExp { @@ -5684,6 +5738,11 @@ extern (C++) final class IntervalExp : Expression } } +/*********************************************************** + * The `dg.ptr` property, pointing to the delegate's 'context' + * + * c.f.`DelegateFuncptrExp` for the delegate's function pointer `dg.funcptr` + */ extern (C++) final class DelegatePtrExp : UnaExp { extern (D) this(const ref Loc loc, Expression e1) @@ -5719,6 +5778,9 @@ extern (C++) final class DelegatePtrExp : UnaExp } /*********************************************************** + * The `dg.funcptr` property, pointing to the delegate's function + * + * c.f.`DelegatePtrExp` for the delegate's function pointer `dg.ptr` */ extern (C++) final class DelegateFuncptrExp : UnaExp { @@ -5835,7 +5897,7 @@ extern (C++) final class IndexExp : BinExp } /*********************************************************** - * For both i++ and i-- + * The postfix increment/decrement operator, `i++` / `i--` */ extern (C++) final class PostExp : BinExp { @@ -5852,7 +5914,7 @@ extern (C++) final class PostExp : BinExp } /*********************************************************** - * For both ++i and --i + * The prefix increment/decrement operator, `++i` / `--i` */ extern (C++) final class PreExp : UnaExp { @@ -5876,6 +5938,9 @@ enum MemorySet } /*********************************************************** + * The assignment / initialization operator, `=` + * + * Note: operator assignment `op=` has a different base class, `BinAssignExp` */ extern (C++) class AssignExp : BinExp { @@ -5953,6 +6018,7 @@ extern (C++) final class ConstructExp : AssignExp } /*********************************************************** + * A bit-for-bit copy from `e2` to `e1` */ extern (C++) final class BlitExp : AssignExp { @@ -5981,6 +6047,7 @@ extern (C++) final class BlitExp : AssignExp } /*********************************************************** + * `x += y` */ extern (C++) final class AddAssignExp : BinAssignExp { @@ -5996,6 +6063,7 @@ extern (C++) final class AddAssignExp : BinAssignExp } /*********************************************************** + * `x -= y` */ extern (C++) final class MinAssignExp : BinAssignExp { @@ -6011,6 +6079,7 @@ extern (C++) final class MinAssignExp : BinAssignExp } /*********************************************************** + * `x *= y` */ extern (C++) final class MulAssignExp : BinAssignExp { @@ -6026,6 +6095,7 @@ extern (C++) final class MulAssignExp : BinAssignExp } /*********************************************************** + * `x /= y` */ extern (C++) final class DivAssignExp : BinAssignExp { @@ -6041,6 +6111,7 @@ extern (C++) final class DivAssignExp : BinAssignExp } /*********************************************************** + * `x %= y` */ extern (C++) final class ModAssignExp : BinAssignExp { @@ -6056,6 +6127,7 @@ extern (C++) final class ModAssignExp : BinAssignExp } /*********************************************************** + * `x &= y` */ extern (C++) final class AndAssignExp : BinAssignExp { @@ -6071,6 +6143,7 @@ extern (C++) final class AndAssignExp : BinAssignExp } /*********************************************************** + * `x |= y` */ extern (C++) final class OrAssignExp : BinAssignExp { @@ -6086,6 +6159,7 @@ extern (C++) final class OrAssignExp : BinAssignExp } /*********************************************************** + * `x ^= y` */ extern (C++) final class XorAssignExp : BinAssignExp { @@ -6101,6 +6175,7 @@ extern (C++) final class XorAssignExp : BinAssignExp } /*********************************************************** + * `x ^^= y` */ extern (C++) final class PowAssignExp : BinAssignExp { @@ -6116,6 +6191,7 @@ extern (C++) final class PowAssignExp : BinAssignExp } /*********************************************************** + * `x <<= y` */ extern (C++) final class ShlAssignExp : BinAssignExp { @@ -6131,6 +6207,7 @@ extern (C++) final class ShlAssignExp : BinAssignExp } /*********************************************************** + * `x >>= y` */ extern (C++) final class ShrAssignExp : BinAssignExp { @@ -6146,6 +6223,7 @@ extern (C++) final class ShrAssignExp : BinAssignExp } /*********************************************************** + * `x >>>= y` */ extern (C++) final class UshrAssignExp : BinAssignExp { @@ -6161,7 +6239,9 @@ extern (C++) final class UshrAssignExp : BinAssignExp } /*********************************************************** - * The ~= operator. It can have one of the following operators: + * The `~=` operator. + * + * It can have one of the following operators: * * EXP.concatenateAssign - appending T[] to T[] * EXP.concatenateElemAssign - appending T to T[] @@ -6188,7 +6268,9 @@ extern (C++) class CatAssignExp : BinAssignExp } } -/// +/*********************************************************** + * The `~=` operator when appending a single element + */ extern (C++) final class CatElemAssignExp : CatAssignExp { extern (D) this(const ref Loc loc, Type type, Expression e1, Expression e2) @@ -6203,7 +6285,9 @@ extern (C++) final class CatElemAssignExp : CatAssignExp } } -/// +/*********************************************************** + * The `~=` operator when appending a single `dchar` + */ extern (C++) final class CatDcharAssignExp : CatAssignExp { extern (D) this(const ref Loc loc, Type type, Expression e1, Expression e2) @@ -6219,6 +6303,8 @@ extern (C++) final class CatDcharAssignExp : CatAssignExp } /*********************************************************** + * The addition operator, `x + y` + * * https://dlang.org/spec/expression.html#add_expressions */ extern (C++) final class AddExp : BinExp @@ -6235,6 +6321,9 @@ extern (C++) final class AddExp : BinExp } /*********************************************************** + * The minus operator, `x - y` + * + * https://dlang.org/spec/expression.html#add_expressions */ extern (C++) final class MinExp : BinExp { @@ -6250,6 +6339,8 @@ extern (C++) final class MinExp : BinExp } /*********************************************************** + * The concatenation operator, `x ~ y` + * * https://dlang.org/spec/expression.html#cat_expressions */ extern (C++) final class CatExp : BinExp @@ -6273,6 +6364,8 @@ extern (C++) final class CatExp : BinExp } /*********************************************************** + * The multiplication operator, `x * y` + * * https://dlang.org/spec/expression.html#mul_expressions */ extern (C++) final class MulExp : BinExp @@ -6289,6 +6382,8 @@ extern (C++) final class MulExp : BinExp } /*********************************************************** + * The division operator, `x / y` + * * https://dlang.org/spec/expression.html#mul_expressions */ extern (C++) final class DivExp : BinExp @@ -6305,6 +6400,8 @@ extern (C++) final class DivExp : BinExp } /*********************************************************** + * The modulo operator, `x % y` + * * https://dlang.org/spec/expression.html#mul_expressions */ extern (C++) final class ModExp : BinExp @@ -6321,6 +6418,8 @@ extern (C++) final class ModExp : BinExp } /*********************************************************** + * The 'power' operator, `x ^^ y` + * * https://dlang.org/spec/expression.html#pow_expressions */ extern (C++) final class PowExp : BinExp @@ -6337,6 +6436,9 @@ extern (C++) final class PowExp : BinExp } /*********************************************************** + * The 'shift left' operator, `x << y` + * + * https://dlang.org/spec/expression.html#shift_expressions */ extern (C++) final class ShlExp : BinExp { @@ -6352,6 +6454,9 @@ extern (C++) final class ShlExp : BinExp } /*********************************************************** + * The 'shift right' operator, `x >> y` + * + * https://dlang.org/spec/expression.html#shift_expressions */ extern (C++) final class ShrExp : BinExp { @@ -6367,6 +6472,9 @@ extern (C++) final class ShrExp : BinExp } /*********************************************************** + * The 'unsigned shift right' operator, `x >>> y` + * + * https://dlang.org/spec/expression.html#shift_expressions */ extern (C++) final class UshrExp : BinExp { @@ -6382,6 +6490,9 @@ extern (C++) final class UshrExp : BinExp } /*********************************************************** + * The bitwise 'and' operator, `x & y` + * + * https://dlang.org/spec/expression.html#and_expressions */ extern (C++) final class AndExp : BinExp { @@ -6397,6 +6508,9 @@ extern (C++) final class AndExp : BinExp } /*********************************************************** + * The bitwise 'or' operator, `x | y` + * + * https://dlang.org/spec/expression.html#or_expressions */ extern (C++) final class OrExp : BinExp { @@ -6412,6 +6526,9 @@ extern (C++) final class OrExp : BinExp } /*********************************************************** + * The bitwise 'xor' operator, `x ^ y` + * + * https://dlang.org/spec/expression.html#xor_expressions */ extern (C++) final class XorExp : BinExp { @@ -6427,6 +6544,8 @@ extern (C++) final class XorExp : BinExp } /*********************************************************** + * The logical 'and' / 'or' operator, `X && Y` / `X || Y` + * * https://dlang.org/spec/expression.html#andand_expressions * https://dlang.org/spec/expression.html#oror_expressions */ @@ -6445,6 +6564,8 @@ extern (C++) final class LogicalExp : BinExp } /*********************************************************** + * A comparison operator, `<` `<=` `>` `>=` + * * `op` is one of: * EXP.lessThan, EXP.lessOrEqual, EXP.greaterThan, EXP.greaterOrEqual * @@ -6465,6 +6586,11 @@ extern (C++) final class CmpExp : BinExp } /*********************************************************** + * The `in` operator, `"a" in ["a": 1]` + * + * Note: `x !in y` is rewritten to `!(x in y)` in the parser + * + * https://dlang.org/spec/expression.html#in_expressions */ extern (C++) final class InExp : BinExp { @@ -6480,6 +6606,8 @@ extern (C++) final class InExp : BinExp } /*********************************************************** + * Associative array removal, `aa.remove(arg)` + * * This deletes the key e1 from the associative array e2 */ extern (C++) final class RemoveExp : BinExp @@ -6539,7 +6667,7 @@ extern (C++) final class IdentityExp : BinExp } /*********************************************************** - * `econd ? e1 : e2` + * The ternary operator, `econd ? e1 : e2` * * https://dlang.org/spec/expression.html#conditional_expressions */ @@ -6672,6 +6800,18 @@ bool isDefaultInitOp(EXP op) pure nothrow @safe @nogc } /*********************************************************** + * A special keyword when used as a function's default argument + * + * When possible, special keywords are resolved in the parser, but when + * appearing as a default argument, they result in an expression deriving + * from this base class that is resolved for each function call. + * + * --- + * const x = __LINE__; // resolved in the parser + * void foo(string file = __FILE__, int line = __LINE__); // DefaultInitExp + * --- + * + * https://dlang.org/spec/expression.html#specialkeywords */ extern (C++) class DefaultInitExp : Expression { @@ -6687,6 +6827,7 @@ extern (C++) class DefaultInitExp : Expression } /*********************************************************** + * The `__FILE__` token as a default argument */ extern (C++) final class FileInitExp : DefaultInitExp { @@ -6717,6 +6858,7 @@ extern (C++) final class FileInitExp : DefaultInitExp } /*********************************************************** + * The `__LINE__` token as a default argument */ extern (C++) final class LineInitExp : DefaultInitExp { @@ -6739,6 +6881,7 @@ extern (C++) final class LineInitExp : DefaultInitExp } /*********************************************************** + * The `__MODULE__` token as a default argument */ extern (C++) final class ModuleInitExp : DefaultInitExp { @@ -6763,6 +6906,7 @@ extern (C++) final class ModuleInitExp : DefaultInitExp } /*********************************************************** + * The `__FUNCTION__` token as a default argument */ extern (C++) final class FuncInitExp : DefaultInitExp { @@ -6793,6 +6937,7 @@ extern (C++) final class FuncInitExp : DefaultInitExp } /*********************************************************** + * The `__PRETTY_FUNCTION__` token as a default argument */ extern (C++) final class PrettyFuncInitExp : DefaultInitExp { diff --git a/gcc/d/dmd/lexer.d b/gcc/d/dmd/lexer.d index 6377e9c..965b3b4 100644 --- a/gcc/d/dmd/lexer.d +++ b/gcc/d/dmd/lexer.d @@ -79,6 +79,12 @@ class Lexer bool doDocComment; // collect doc comment information bool anyToken; // seen at least one token bool commentToken; // comments are TOK.comment's + + version (DMDLIB) + { + bool whitespaceToken; // tokenize whitespaces + } + int inTokenStringConstant; // can be larger than 1 when in nested q{} strings int lastDocLine; // last line of previous doc comment @@ -145,6 +151,31 @@ class Lexer } } + version (DMDLIB) + { + this(const(char)* filename, const(char)* base, size_t begoffset, size_t endoffset, + bool doDocComment, bool commentToken, bool whitespaceToken) + { + this(filename, base, begoffset, endoffset, doDocComment, commentToken); + this.whitespaceToken = whitespaceToken; + } + + bool empty() const pure @property @nogc @safe + { + return front() == TOK.endOfFile; + } + + TOK front() const pure @property @nogc @safe + { + return token.value; + } + + void popFront() + { + nextToken(); + } + } + /// Returns: a newly allocated `Token`. Token* allocateToken() pure nothrow @safe { @@ -237,20 +268,52 @@ class Lexer while (*p == ' ') p++; LendSkipFourSpaces: + version (DMDLIB) + { + if (whitespaceToken) + { + t.value = TOK.whitespace; + return; + } + } continue; // skip white space case '\t': case '\v': case '\f': p++; + version (DMDLIB) + { + if (whitespaceToken) + { + t.value = TOK.whitespace; + return; + } + } continue; // skip white space case '\r': p++; if (*p != '\n') // if CR stands by itself endOfLine(); + version (DMDLIB) + { + if (whitespaceToken) + { + t.value = TOK.whitespace; + return; + } + } continue; // skip white space case '\n': p++; endOfLine(); + version (DMDLIB) + { + if (whitespaceToken) + { + t.value = TOK.whitespace; + return; + } + } continue; // skip white space case '0': if (!isZeroSecond(p[1])) // if numeric literal does not continue @@ -594,8 +657,12 @@ class Lexer } if (commentToken) { - p++; - endOfLine(); + version (DMDLIB) {} + else + { + p++; + endOfLine(); + } t.loc = startLoc; t.value = TOK.comment; return; diff --git a/gcc/d/dmd/optimize.d b/gcc/d/dmd/optimize.d index 3653aa8..10c265f 100644 --- a/gcc/d/dmd/optimize.d +++ b/gcc/d/dmd/optimize.d @@ -469,10 +469,11 @@ Expression Expression_optimize(Expression e, int result, bool keepLvalue) * Params: * e = the DotVarExp or VarExp * var = set to the VarExp at the end, or null if doesn't end in VarExp + * eint = set to the IntegerExp at the end, or null if doesn't end in IntegerExp * offset = accumulation of all the .var offsets encountered * Returns: true on error */ - static bool getVarAndOffset(Expression e, ref VarDeclaration var, ref uint offset) + static bool getVarAndOffset(Expression e, out VarDeclaration var, out IntegerExp eint, ref uint offset) { if (e.type.size() == SIZE_INVALID) // trigger computation of v.offset return true; @@ -483,7 +484,7 @@ Expression Expression_optimize(Expression e, int result, bool keepLvalue) if (!v || !v.isField() || v.isBitFieldDeclaration()) return false; - if (getVarAndOffset(dve.e1, var, offset)) + if (getVarAndOffset(dve.e1, var, eint, offset)) return true; offset += v.offset; } @@ -497,12 +498,20 @@ Expression Expression_optimize(Expression e, int result, bool keepLvalue) var = ve.var.isVarDeclaration(); } } + else if (auto ep = e.isPtrExp()) + { + if (auto ei = ep.e1.isIntegerExp()) + { + eint = ei; + } + } return false; } uint offset; VarDeclaration var; - if (getVarAndOffset(e.e1, var, offset)) + IntegerExp eint; + if (getVarAndOffset(e.e1, var, eint, offset)) { ret = ErrorExp.get(); return; @@ -513,6 +522,11 @@ Expression Expression_optimize(Expression e, int result, bool keepLvalue) ret.type = e.type; return; } + if (eint) + { + ret = new IntegerExp(e.loc, eint.toInteger() + offset, e.type); + return; + } } if (auto ae = e.e1.isIndexExp()) { @@ -828,6 +842,7 @@ Expression Expression_optimize(Expression e, int result, bool keepLvalue) void visitMin(MinExp e) { + //printf("MinExp::optimize(%s)\n", e.toChars()); if (binOptimize(e, result)) return; if (e.e1.isConst() && e.e2.isConst()) diff --git a/gcc/d/dmd/statementsem.d b/gcc/d/dmd/statementsem.d index 5dbe5b6..88520e8 100644 --- a/gcc/d/dmd/statementsem.d +++ b/gcc/d/dmd/statementsem.d @@ -47,6 +47,7 @@ import dmd.globals; import dmd.gluelayer; import dmd.id; import dmd.identifier; +import dmd.importc; import dmd.init; import dmd.intrange; import dmd.mtype; @@ -2862,6 +2863,7 @@ package (dmd) extern (C++) final class StatementSemanticVisitor : Visitor rs.exp = inferType(rs.exp, fld.treq.nextOf().nextOf()); rs.exp = rs.exp.expressionSemantic(sc); + rs.exp = rs.exp.arrayFuncConv(sc); // If we're returning by ref, allow the expression to be `shared` const returnSharedRef = (tf.isref && (fd.inferRetType || tret.isShared())); rs.exp.checkSharedAccess(sc, returnSharedRef); diff --git a/gcc/d/dmd/tokens.d b/gcc/d/dmd/tokens.d index 9c24df0..0b1d158 100644 --- a/gcc/d/dmd/tokens.d +++ b/gcc/d/dmd/tokens.d @@ -246,6 +246,7 @@ enum TOK : ubyte arrow, // -> colonColon, // :: wchar_tLiteral, + whitespace, // C only keywords inline, @@ -851,6 +852,7 @@ extern (C++) struct Token TOK.wcharLiteral: "wcharv", TOK.dcharLiteral: "dcharv", TOK.wchar_tLiteral: "wchar_tv", + TOK.whitespace: "whitespace", TOK.hexadecimalString: "xstring", diff --git a/gcc/d/dmd/tokens.h b/gcc/d/dmd/tokens.h index c23e0fb..6dfd0ce 100644 --- a/gcc/d/dmd/tokens.h +++ b/gcc/d/dmd/tokens.h @@ -255,6 +255,7 @@ enum class TOK : unsigned char arrow, // -> colonColon, // :: wchar_tLiteral, + whitespace, // C only keywords inline_, |