aboutsummaryrefslogtreecommitdiff
path: root/gcc/d/dmd/dstruct.c
diff options
context:
space:
mode:
Diffstat (limited to 'gcc/d/dmd/dstruct.c')
-rw-r--r--gcc/d/dmd/dstruct.c318
1 files changed, 12 insertions, 306 deletions
diff --git a/gcc/d/dmd/dstruct.c b/gcc/d/dmd/dstruct.c
index 8829367..40c67ce 100644
--- a/gcc/d/dmd/dstruct.c
+++ b/gcc/d/dmd/dstruct.c
@@ -1,6 +1,6 @@
/* Compiler implementation of the D programming language
- * Copyright (C) 1999-2020 by The D Language Foundation, All Rights Reserved
+ * Copyright (C) 1999-2021 by The D Language Foundation, All Rights Reserved
* written by Walter Bright
* http://www.digitalmars.com
* Distributed under the Boost Software License, Version 1.0.
@@ -247,89 +247,6 @@ void AggregateDeclaration::setScope(Scope *sc)
ScopeDsymbol::setScope(sc);
}
-void AggregateDeclaration::semantic2(Scope *sc)
-{
- //printf("AggregateDeclaration::semantic2(%s) type = %s, errors = %d\n", toChars(), type->toChars(), errors);
- if (!members)
- return;
-
- if (_scope)
- {
- error("has forward references");
- return;
- }
-
- Scope *sc2 = newScope(sc);
-
- determineSize(loc);
-
- for (size_t i = 0; i < members->length; i++)
- {
- Dsymbol *s = (*members)[i];
- //printf("\t[%d] %s\n", i, s->toChars());
- s->semantic2(sc2);
- }
-
- sc2->pop();
-}
-
-void AggregateDeclaration::semantic3(Scope *sc)
-{
- //printf("AggregateDeclaration::semantic3(%s) type = %s, errors = %d\n", toChars(), type->toChars(), errors);
- if (!members)
- return;
-
- StructDeclaration *sd = isStructDeclaration();
- if (!sc) // from runDeferredSemantic3 for TypeInfo generation
- {
- assert(sd);
- sd->semanticTypeInfoMembers();
- return;
- }
-
- Scope *sc2 = newScope(sc);
-
- for (size_t i = 0; i < members->length; i++)
- {
- Dsymbol *s = (*members)[i];
- s->semantic3(sc2);
- }
-
- sc2->pop();
-
- // don't do it for unused deprecated types
- // or error types
- if (!getRTInfo && Type::rtinfo &&
- (!isDeprecated() || global.params.useDeprecated != DIAGNOSTICerror) &&
- (type && type->ty != Terror))
- {
- // Evaluate: RTinfo!type
- Objects *tiargs = new Objects();
- tiargs->push(type);
- TemplateInstance *ti = new TemplateInstance(loc, Type::rtinfo, tiargs);
-
- Scope *sc3 = ti->tempdecl->_scope->startCTFE();
- sc3->tinst = sc->tinst;
- sc3->minst = sc->minst;
- if (isDeprecated())
- sc3->stc |= STCdeprecated;
-
- ti->semantic(sc3);
- ti->semantic2(sc3);
- ti->semantic3(sc3);
- Expression *e = resolve(Loc(), sc3, ti->toAlias(), false);
-
- sc3->endCTFE();
-
- e = e->ctfeInterpret();
- getRTInfo = e;
- }
-
- if (sd)
- sd->semanticTypeInfoMembers();
- semanticRun = PASSsemantic3done;
-}
-
/***************************************
* Find all instance fields, then push them into `fields`.
*
@@ -364,7 +281,7 @@ bool AggregateDeclaration::determineFields()
AggregateDeclaration *ad = ((SV *)param)->agg;
if (v->semanticRun < PASSsemanticdone)
- v->semantic(NULL);
+ dsymbolSemantic(v, NULL);
// Note: Aggregate fields or size could have determined during v->semantic.
if (ad->sizeok != SIZEOKnone)
return 1;
@@ -437,7 +354,7 @@ bool AggregateDeclaration::determineSize(Loc loc)
}
if (_scope)
- semantic(NULL);
+ dsymbolSemantic(this, NULL);
// Determine the instance size of base class first.
if (ClassDeclaration *cd = isClassDeclaration())
@@ -480,7 +397,7 @@ void StructDeclaration::semanticTypeInfoMembers()
xeq->semanticRun < PASSsemantic3done)
{
unsigned errors = global.startGagging();
- xeq->semantic3(xeq->_scope);
+ semantic3(xeq, xeq->_scope);
if (global.endGagging(errors))
xeq = xerreq;
}
@@ -490,7 +407,7 @@ void StructDeclaration::semanticTypeInfoMembers()
xcmp->semanticRun < PASSsemantic3done)
{
unsigned errors = global.startGagging();
- xcmp->semantic3(xcmp->_scope);
+ semantic3(xcmp, xcmp->_scope);
if (global.endGagging(errors))
xcmp = xerrcmp;
}
@@ -500,28 +417,28 @@ void StructDeclaration::semanticTypeInfoMembers()
ftostr->_scope &&
ftostr->semanticRun < PASSsemantic3done)
{
- ftostr->semantic3(ftostr->_scope);
+ semantic3(ftostr, ftostr->_scope);
}
if (xhash &&
xhash->_scope &&
xhash->semanticRun < PASSsemantic3done)
{
- xhash->semantic3(xhash->_scope);
+ semantic3(xhash, xhash->_scope);
}
if (postblit &&
postblit->_scope &&
postblit->semanticRun < PASSsemantic3done)
{
- postblit->semantic3(postblit->_scope);
+ semantic3(postblit, postblit->_scope);
}
if (dtor &&
dtor->_scope &&
dtor->semanticRun < PASSsemantic3done)
{
- dtor->semantic3(dtor->_scope);
+ semantic3(dtor, dtor->_scope);
}
}
@@ -964,7 +881,7 @@ Dsymbol *AggregateDeclaration::searchCtor()
{
CtorDeclaration *f = s->isCtorDeclaration();
if (f && f->semanticRun == PASSinit)
- f->semantic(NULL);
+ dsymbolSemantic(f, NULL);
return 0;
}
};
@@ -1020,227 +937,16 @@ Dsymbol *StructDeclaration::syntaxCopy(Dsymbol *s)
return ScopeDsymbol::syntaxCopy(sd);
}
-void StructDeclaration::semantic(Scope *sc)
-{
- //printf("StructDeclaration::semantic(this=%p, %s '%s', sizeok = %d)\n", this, parent->toChars(), toChars(), sizeok);
-
- //static int count; if (++count == 20) halt();
-
- if (semanticRun >= PASSsemanticdone)
- return;
- unsigned errors = global.errors;
-
- //printf("+StructDeclaration::semantic(this=%p, %s '%s', sizeok = %d)\n", this, parent->toChars(), toChars(), sizeok);
- Scope *scx = NULL;
- if (_scope)
- {
- sc = _scope;
- scx = _scope; // save so we don't make redundant copies
- _scope = NULL;
- }
-
- if (!parent)
- {
- assert(sc->parent && sc->func);
- parent = sc->parent;
- }
- assert(parent && !isAnonymous());
-
- if (this->errors)
- type = Type::terror;
- if (semanticRun == PASSinit)
- type = type->addSTC(sc->stc | storage_class);
- type = type->semantic(loc, sc);
-
- if (type->ty == Tstruct && ((TypeStruct *)type)->sym != this)
- {
- TemplateInstance *ti = ((TypeStruct *)type)->sym->isInstantiated();
- if (ti && isError(ti))
- ((TypeStruct *)type)->sym = this;
- }
-
- // Ungag errors when not speculative
- Ungag ungag = ungagSpeculative();
-
- if (semanticRun == PASSinit)
- {
- protection = sc->protection;
-
- alignment = sc->alignment();
-
- storage_class |= sc->stc;
- if (storage_class & STCdeprecated)
- isdeprecated = true;
- if (storage_class & STCabstract)
- error("structs, unions cannot be abstract");
- userAttribDecl = sc->userAttribDecl;
-
- if (sc->linkage == LINKcpp)
- classKind = ClassKind::cpp;
- }
- else if (symtab && !scx)
- {
- return;
- }
- semanticRun = PASSsemantic;
-
- if (!members) // if opaque declaration
- {
- semanticRun = PASSsemanticdone;
- return;
- }
- if (!symtab)
- {
- symtab = new DsymbolTable();
-
- for (size_t i = 0; i < members->length; i++)
- {
- Dsymbol *s = (*members)[i];
- //printf("adding member '%s' to '%s'\n", s->toChars(), this->toChars());
- s->addMember(sc, this);
- }
- }
-
- Scope *sc2 = newScope(sc);
-
- /* Set scope so if there are forward references, we still might be able to
- * resolve individual members like enums.
- */
- for (size_t i = 0; i < members->length; i++)
- {
- Dsymbol *s = (*members)[i];
- //printf("struct: setScope %s %s\n", s->kind(), s->toChars());
- s->setScope(sc2);
- }
-
- for (size_t i = 0; i < members->length; i++)
- {
- Dsymbol *s = (*members)[i];
- s->importAll(sc2);
- }
-
- for (size_t i = 0; i < members->length; i++)
- {
- Dsymbol *s = (*members)[i];
- s->semantic(sc2);
- }
-
- if (!determineFields())
- {
- assert(type->ty == Terror);
- sc2->pop();
- semanticRun = PASSsemanticdone;
- return;
- }
-
- /* Following special member functions creation needs semantic analysis
- * completion of sub-structs in each field types. For example, buildDtor
- * needs to check existence of elaborate dtor in type of each fields.
- * See the case in compilable/test14838.d
- */
- for (size_t i = 0; i < fields.length; i++)
- {
- VarDeclaration *v = fields[i];
- Type *tb = v->type->baseElemOf();
- if (tb->ty != Tstruct)
- continue;
- StructDeclaration *sd = ((TypeStruct *)tb)->sym;
- if (sd->semanticRun >= PASSsemanticdone)
- continue;
-
- sc2->pop();
-
- _scope = scx ? scx : sc->copy();
- _scope->setNoFree();
- _scope->_module->addDeferredSemantic(this);
-
- //printf("\tdeferring %s\n", toChars());
- return;
- }
-
- /* Look for special member functions.
- */
- aggNew = (NewDeclaration *)search(Loc(), Id::classNew);
- aggDelete = (DeleteDeclaration *)search(Loc(), Id::classDelete);
-
- // Look for the constructor
- ctor = searchCtor();
-
- dtor = buildDtor(this, sc2);
- postblit = buildPostBlit(this, sc2);
-
- buildOpAssign(this, sc2);
- buildOpEquals(this, sc2);
-
- if (global.params.useTypeInfo && Type::dtypeinfo) // these functions are used for TypeInfo
- {
- xeq = buildXopEquals(this, sc2);
- xcmp = buildXopCmp(this, sc2);
- xhash = buildXtoHash(this, sc2);
- }
-
- inv = buildInv(this, sc2);
-
- Module::dprogress++;
- semanticRun = PASSsemanticdone;
- //printf("-StructDeclaration::semantic(this=%p, '%s')\n", this, toChars());
-
- sc2->pop();
-
- if (ctor)
- {
- Dsymbol *scall = search(Loc(), Id::call);
- if (scall)
- {
- unsigned xerrors = global.startGagging();
- sc = sc->push();
- sc->tinst = NULL;
- sc->minst = NULL;
- FuncDeclaration *fcall = resolveFuncCall(loc, sc, scall, NULL, NULL, NULL, 1);
- sc = sc->pop();
- global.endGagging(xerrors);
-
- if (fcall && fcall->isStatic())
- {
- error(fcall->loc, "static opCall is hidden by constructors and can never be called");
- errorSupplemental(fcall->loc, "Please use a factory method instead, or replace all constructors with static opCall.");
- }
- }
- }
-
- if (type->ty == Tstruct && ((TypeStruct *)type)->sym != this)
- {
- // https://issues.dlang.org/show_bug.cgi?id=19024
- StructDeclaration *sd = ((TypeStruct *)type)->sym;
- error("already exists at %s. Perhaps in another function with the same name?", sd->loc.toChars());
- }
-
- if (global.errors != errors)
- {
- // The type is no good.
- type = Type::terror;
- this->errors = true;
- if (deferred)
- deferred->errors = true;
- }
-
- if (deferred && !global.gag)
- {
- deferred->semantic2(sc);
- deferred->semantic3(sc);
- }
-}
-
Dsymbol *StructDeclaration::search(const Loc &loc, Identifier *ident, int flags)
{
//printf("%s.StructDeclaration::search('%s', flags = x%x)\n", toChars(), ident->toChars(), flags);
if (_scope && !symtab)
- semantic(_scope);
+ dsymbolSemantic(this, _scope);
if (!members || !symtab) // opaque or semantic() is not yet called
{
- error("is forward referenced when looking for '%s'", ident->toChars());
+ error("is forward referenced when looking for `%s`", ident->toChars());
return NULL;
}