aboutsummaryrefslogtreecommitdiff
path: root/gcc/d/dmd/func.d
diff options
context:
space:
mode:
Diffstat (limited to 'gcc/d/dmd/func.d')
-rw-r--r--gcc/d/dmd/func.d118
1 files changed, 67 insertions, 51 deletions
diff --git a/gcc/d/dmd/func.d b/gcc/d/dmd/func.d
index 3b0b34e..93e3634 100644
--- a/gcc/d/dmd/func.d
+++ b/gcc/d/dmd/func.d
@@ -640,7 +640,7 @@ extern (C++) class FuncDeclaration : Declaration
}
/*************************************************
- * Find index of function in vtbl[0..dim] that
+ * Find index of function in vtbl[0..length] that
* this function overrides.
* Prefer an exact match to a covariant one.
* Params:
@@ -777,7 +777,7 @@ extern (C++) class FuncDeclaration : Declaration
{
foreach (b; cd.interfaces)
{
- auto v = findVtblIndex(&b.sym.vtbl, cast(int)b.sym.vtbl.dim);
+ auto v = findVtblIndex(&b.sym.vtbl, cast(int)b.sym.vtbl.length);
if (v >= 0)
return b;
}
@@ -1810,7 +1810,7 @@ extern (C++) class FuncDeclaration : Declaration
if (!isVirtual())
return false;
// If it's a final method, and does not override anything, then it is not virtual
- if (isFinalFunc() && foverrides.dim == 0)
+ if (isFinalFunc() && foverrides.length == 0)
{
return false;
}
@@ -1967,7 +1967,7 @@ extern (C++) class FuncDeclaration : Declaration
if (fdthis != this)
{
bool found = false;
- for (size_t i = 0; i < siblingCallers.dim; ++i)
+ for (size_t i = 0; i < siblingCallers.length; ++i)
{
if (siblingCallers[i] == fdthis)
found = true;
@@ -2033,12 +2033,12 @@ extern (C++) class FuncDeclaration : Declaration
if (requiresClosure)
goto Lyes;
- for (size_t i = 0; i < closureVars.dim; i++)
+ for (size_t i = 0; i < closureVars.length; i++)
{
VarDeclaration v = closureVars[i];
//printf("\tv = %s\n", v.toChars());
- for (size_t j = 0; j < v.nestedrefs.dim; j++)
+ for (size_t j = 0; j < v.nestedrefs.length; j++)
{
FuncDeclaration f = v.nestedrefs[j];
assert(f != this);
@@ -2167,7 +2167,7 @@ extern (C++) class FuncDeclaration : Declaration
*/
final bool hasNestedFrameRefs()
{
- if (closureVars.dim)
+ if (closureVars.length)
return true;
/* If a virtual function has contracts, assume its variables are referenced
@@ -2181,9 +2181,9 @@ extern (C++) class FuncDeclaration : Declaration
if (fdrequire || fdensure)
return true;
- if (foverrides.dim && isVirtualMethod())
+ if (foverrides.length && isVirtualMethod())
{
- for (size_t i = 0; i < foverrides.dim; i++)
+ for (size_t i = 0; i < foverrides.length; i++)
{
FuncDeclaration fdv = foverrides[i];
if (fdv.hasNestedFrameRefs())
@@ -2406,7 +2406,7 @@ extern (C++) class FuncDeclaration : Declaration
* becomes:
* in { { statements1... } { statements2... } ... }
*/
- assert(frequires.dim);
+ assert(frequires.length);
auto loc = (*frequires)[0].loc;
auto s = new Statements;
foreach (r; *frequires)
@@ -2425,7 +2425,7 @@ extern (C++) class FuncDeclaration : Declaration
* out(__result) { { ref id1 = __result; { statements1... } }
* { ref id2 = __result; { statements2... } } ... }
*/
- assert(fensures.dim);
+ assert(fensures.length);
auto loc = (*fensures)[0].ensure.loc;
auto s = new Statements;
foreach (r; *fensures)
@@ -3133,7 +3133,7 @@ FuncDeclaration resolveFuncCall(const ref Loc loc, Scope* sc, Dsymbol s,
printf("\tthis: %s\n", tthis.toChars());
if (fargs)
{
- for (size_t i = 0; i < fargs.dim; i++)
+ for (size_t i = 0; i < fargs.length; i++)
{
Expression arg = (*fargs)[i];
assert(arg.type);
@@ -3352,46 +3352,40 @@ if (is(Decl == TemplateDeclaration) || is(Decl == FuncDeclaration))
{
// max num of overloads to print (-v overrides this).
enum int DisplayLimit = 5;
- int displayed;
const(char)* constraintsTip;
-
// determine if the first candidate was printed
- bool printed = false;
+ int printed;
- overloadApply(declaration, (Dsymbol s)
+ bool matchSymbol(Dsymbol s, bool print, bool single_candidate = false)
{
- Dsymbol nextOverload;
-
if (auto fd = s.isFuncDeclaration())
{
// Don't print overloads which have errors.
// Not that if the whole overload set has errors, we'll never reach
// this point so there's no risk of printing no candidate
if (fd.errors || fd.type.ty == Terror)
- return 0;
+ return false;
// Don't print disabled functions, or `deprecated` outside of deprecated scope
if (fd.storage_class & STC.disable || (fd.isDeprecated() && !showDeprecated))
- return 0;
-
- const single_candidate = fd.overnext is null;
+ return false;
+ if (!print)
+ return true;
auto tf = cast(TypeFunction) fd.type;
.errorSupplemental(fd.loc,
printed ? " `%s%s`" :
single_candidate ? "Candidate is: `%s%s`" : "Candidates are: `%s%s`",
fd.toPrettyChars(),
parametersTypeToChars(tf.parameterList));
- printed = true;
- nextOverload = fd.overnext;
}
else if (auto td = s.isTemplateDeclaration())
{
import dmd.staticcond;
+ if (!print)
+ return true;
const tmsg = td.toCharsNoConstraints();
const cmsg = td.getConstraintEvalError(constraintsTip);
- const single_candidate = td.overnext is null;
-
// add blank space if there are multiple candidates
// the length of the blank space is `strlen("Candidates are: ")`
@@ -3401,7 +3395,6 @@ if (is(Decl == TemplateDeclaration) || is(Decl == FuncDeclaration))
printed ? " `%s`\n%s" :
single_candidate ? "Candidate is: `%s`\n%s" : "Candidates are: `%s`\n%s",
tmsg, cmsg);
- printed = true;
}
else
{
@@ -3409,26 +3402,38 @@ if (is(Decl == TemplateDeclaration) || is(Decl == FuncDeclaration))
printed ? " `%s`" :
single_candidate ? "Candidate is: `%s`" : "Candidates are: `%s`",
tmsg);
- printed = true;
}
- nextOverload = td.overnext;
}
-
- if (global.params.verbose || ++displayed < DisplayLimit)
- return 0;
-
- // Too many overloads to sensibly display.
- // Just show count of remaining overloads.
- int num = 0;
- overloadApply(nextOverload, (s) { ++num; return 0; });
-
- if (num > 0)
- .errorSupplemental(loc, "... (%d more, -v to show) ...", num);
- return 1; // stop iterating
+ return true;
+ }
+ // determine if there's > 1 candidate
+ int count = 0;
+ overloadApply(declaration, (s) {
+ if (matchSymbol(s, false))
+ count++;
+ return count > 1;
+ });
+ int skipped = 0;
+ overloadApply(declaration, (s) {
+ if (global.params.verbose || printed < DisplayLimit)
+ {
+ if (matchSymbol(s, true, count == 1))
+ printed++;
+ }
+ else
+ {
+ // Too many overloads to sensibly display.
+ // Just show count of remaining overloads.
+ if (matchSymbol(s, false))
+ skipped++;
+ }
+ return 0;
});
+ if (skipped > 0)
+ .errorSupplemental(loc, "... (%d more, -v to show) ...", skipped);
// Nothing was displayed, all overloads are either disabled or deprecated
- if (!displayed)
+ if (!printed)
.errorSupplemental(loc, "All possible candidates are marked as `deprecated` or `@disable`");
// should be only in verbose mode
if (constraintsTip)
@@ -3570,7 +3575,7 @@ private void markAsNeedingClosure(Dsymbol f, FuncDeclaration outerFunc)
for (Dsymbol sx = f; sx && sx != outerFunc; sx = sx.toParentP(outerFunc))
{
FuncDeclaration fy = sx.isFuncDeclaration();
- if (fy && fy.closureVars.dim)
+ if (fy && fy.closureVars.length)
{
/* fy needs a closure if it has closureVars[],
* because the frame pointer in the closure will be accessed.
@@ -3608,7 +3613,7 @@ private bool checkEscapingSiblings(FuncDeclaration f, FuncDeclaration outerFunc,
//printf("checkEscapingSiblings(f = %s, outerfunc = %s)\n", f.toChars(), outerFunc.toChars());
bool bAnyClosures = false;
- for (size_t i = 0; i < f.siblingCallers.dim; ++i)
+ for (size_t i = 0; i < f.siblingCallers.length; ++i)
{
FuncDeclaration g = f.siblingCallers[i];
if (g.isThis() || g.tookAddressOf)
@@ -4351,19 +4356,30 @@ bool setUnsafe(Scope* sc,
bool gag = false, Loc loc = Loc.init, const(char)* fmt = null,
RootObject arg0 = null, RootObject arg1 = null, RootObject arg2 = null)
{
- // TODO:
- // For @system variables, unsafe initializers at global scope should mark
- // the variable @system, see https://dlang.org/dips/1035
-
- if (!sc.func)
- return false;
-
if (sc.intypeof)
return false; // typeof(cast(int*)0) is safe
if (sc.flags & SCOPE.debug_) // debug {} scopes are permissive
return false;
+ if (!sc.func)
+ {
+ if (sc.varDecl)
+ {
+ if (sc.varDecl.storage_class & STC.safe)
+ {
+ .error(loc, fmt, arg0 ? arg0.toChars() : "", arg1 ? arg1.toChars() : "", arg2 ? arg2.toChars() : "");
+ return true;
+ }
+ else if (!(sc.varDecl.storage_class & STC.system))
+ {
+ sc.varDecl.storage_class |= STC.system;
+ }
+ }
+ return false;
+ }
+
+
if (sc.flags & SCOPE.compile) // __traits(compiles, x)
{
if (sc.func.isSafeBypassingInference())