Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move newScope methods from dclass.d to newScope visitor in dsymbolsem.d #17038

Draft
wants to merge 7 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions compiler/src/dmd/aggregate.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ namespace dmd
FuncDeclaration *search_toString(StructDeclaration *sd);
void semanticTypeInfoMembers(StructDeclaration *sd);
bool fill(StructDeclaration* sd, const Loc &loc, Expressions &elements, bool ctorinit);
Scope* newScope(AggregateDeclaration *d, Scope* sc);
Scope* newScope(AttribDeclaration *d, Scope* sc);
}

enum class ClassKind : uint8_t
Expand Down Expand Up @@ -117,7 +119,6 @@ class AggregateDeclaration : public ScopeDsymbol
d_bool disableNew; // disallow allocations using `new`
Sizeok sizeok; // set when structsize contains valid data

virtual Scope *newScope(Scope *sc);
virtual void finalizeSize() = 0;
uinteger_t size(const Loc &loc) override final;
Type *getType() override final;
Expand Down Expand Up @@ -281,7 +282,6 @@ class ClassDeclaration : public AggregateDeclaration
static ClassDeclaration *create(const Loc &loc, Identifier *id, BaseClasses *baseclasses, Dsymbols *members, bool inObject);
const char *toPrettyChars(bool QualifyTypes = false) override;
ClassDeclaration *syntaxCopy(Dsymbol *s) override;
Scope *newScope(Scope *sc) override;

#define OFFSET_RUNTIME 0x76543210
#define OFFSET_FWDREF 0x76543211
Expand Down Expand Up @@ -313,7 +313,6 @@ class InterfaceDeclaration final : public ClassDeclaration
{
public:
InterfaceDeclaration *syntaxCopy(Dsymbol *s) override;
Scope *newScope(Scope *sc) override;
bool isBaseOf(ClassDeclaration *cd, int *poffset) override;
const char *kind() const override;
int vtblOffset() const override;
Expand Down
26 changes: 0 additions & 26 deletions compiler/src/dmd/dclass.d
Original file line number Diff line number Diff line change
Expand Up @@ -409,19 +409,6 @@ extern (C++) class ClassDeclaration : AggregateDeclaration
return cd;
}

override Scope* newScope(Scope* sc)
thewilsonator marked this conversation as resolved.
Show resolved Hide resolved
{
auto sc2 = super.newScope(sc);
if (isCOMclass())
{
/* This enables us to use COM objects under Linux and
* work with things like XPCOM
*/
sc2.linkage = target.systemLinkage();
}
return sc2;
}

/*********************************************
* Determine if 'this' is a base class of cd.
* This is used to detect circular inheritance only.
Expand Down Expand Up @@ -975,19 +962,6 @@ extern (C++) final class InterfaceDeclaration : ClassDeclaration
return id;
}


override Scope* newScope(Scope* sc)
{
auto sc2 = super.newScope(sc);
if (com)
sc2.linkage = LINK.windows;
else if (classKind == ClassKind.cpp)
sc2.linkage = LINK.cpp;
else if (classKind == ClassKind.objc)
sc2.linkage = LINK.objc;
return sc2;
}

/*******************************************
* Determine if 'this' is a base class of cd.
* (Actually, if it is an interface supported by cd)
Expand Down
44 changes: 43 additions & 1 deletion compiler/src/dmd/dsymbolsem.d
Original file line number Diff line number Diff line change
Expand Up @@ -7349,7 +7349,7 @@
}
}

extern(D) Scope* newScope(Dsymbol d, Scope* sc)
extern(D) Scope* newScope(AttribDeclaration d, Scope* sc)
{
scope nsv = new NewScopeVisitor(sc);
d.accept(nsv);
Expand Down Expand Up @@ -7484,6 +7484,48 @@
}
}

//newScope of Aggregate Declaration.
extern(D) Scope* newScope(AggregateDeclaration d, Scope* sc)
{
scope nsv = new NewScopeVisitor(sc);
d.accept(nsv);
return nsv.sc;

Check warning on line 7492 in compiler/src/dmd/dsymbolsem.d

View check run for this annotation

Codecov / codecov/patch

compiler/src/dmd/dsymbolsem.d#L7490-L7492

Added lines #L7490 - L7492 were not covered by tests
}

private extern(C++) class NewScopeVisitor2 : Visitor
{
alias visit = typeof(super).visit;
Scope* sc;
this(Scope* sc)

Check warning on line 7499 in compiler/src/dmd/dsymbolsem.d

View check run for this annotation

Codecov / codecov/patch

compiler/src/dmd/dsymbolsem.d#L7499

Added line #L7499 was not covered by tests
{
this.sc = sc;

Check warning on line 7501 in compiler/src/dmd/dsymbolsem.d

View check run for this annotation

Codecov / codecov/patch

compiler/src/dmd/dsymbolsem.d#L7501

Added line #L7501 was not covered by tests
}

override void visit(ClassDeclaration cld)
{
auto sc2 = (cast(AggregateDeclaration)cld).newScope(sc);
if (cld.isCOMclass())

Check warning on line 7507 in compiler/src/dmd/dsymbolsem.d

View check run for this annotation

Codecov / codecov/patch

compiler/src/dmd/dsymbolsem.d#L7506-L7507

Added lines #L7506 - L7507 were not covered by tests
{
/* This enables us to use COM objects under Linux and
* work with things like XPCOM
*/
sc2.linkage = target.systemLinkage();

Check warning on line 7512 in compiler/src/dmd/dsymbolsem.d

View check run for this annotation

Codecov / codecov/patch

compiler/src/dmd/dsymbolsem.d#L7512

Added line #L7512 was not covered by tests
}
sc = sc2;

Check warning on line 7514 in compiler/src/dmd/dsymbolsem.d

View check run for this annotation

Codecov / codecov/patch

compiler/src/dmd/dsymbolsem.d#L7514

Added line #L7514 was not covered by tests
}

override void visit(InterfaceDeclaration ifd)
{
auto sc2 = (cast(ClassDeclaration)ifd).newScope(sc);
if (ifd.com)
sc2.linkage = LINK.windows;
else if (ifd.classKind == ClassKind.cpp)
sc2.linkage = LINK.cpp;
else if (ifd.classKind == ClassKind.objc)
sc2.linkage = LINK.objc;
sc = sc2;

Check warning on line 7526 in compiler/src/dmd/dsymbolsem.d

View check run for this annotation

Codecov / codecov/patch

compiler/src/dmd/dsymbolsem.d#L7519-L7526

Added lines #L7519 - L7526 were not covered by tests
}
}

extern(C++) Dsymbols* include(Dsymbol d, Scope* sc)
{
Expand Down
2 changes: 0 additions & 2 deletions compiler/src/dmd/frontend.h
Original file line number Diff line number Diff line change
Expand Up @@ -6508,7 +6508,6 @@ class ClassDeclaration : public AggregateDeclaration
static ClassDeclaration* create(const Loc& loc, Identifier* id, Array<BaseClass* >* baseclasses, Array<Dsymbol* >* members, bool inObject);
const char* toPrettyChars(bool qualifyTypes = false) override;
ClassDeclaration* syntaxCopy(Dsymbol* s) override;
Scope* newScope(Scope* sc) override;
enum : int32_t { OFFSET_RUNTIME = 1985229328 };

enum : int32_t { OFFSET_FWDREF = 1985229329 };
Expand Down Expand Up @@ -6536,7 +6535,6 @@ class InterfaceDeclaration final : public ClassDeclaration
{
public:
InterfaceDeclaration* syntaxCopy(Dsymbol* s) override;
Scope* newScope(Scope* sc) override;
bool isBaseOf(ClassDeclaration* cd, int32_t* poffset) override;
const char* kind() const override;
int32_t vtblOffset() const override;
Expand Down
1 change: 1 addition & 0 deletions compiler/src/tests/cxxfrontend.cc
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ void test_visitors()
ClassDeclaration *cd = ClassDeclaration::create(loc, Identifier::idPool("TypeInfo"), NULL, NULL, true);
assert(cd->isClassDeclaration() == cd);
assert(cd->vtblOffset() == 1);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this assert failing means that

if (isCOMinterface() || isCPPinterface())
    return 0;
return 1;

is returning the wrong value.
Both of those methods should return false for classes (i.e. only for interfaces should they possibly return true). I'm not really sure why that is happening. You might want to check what the actual return value is. If it is 0 or if it is some other value (which would indicate a corrupt vtable on the C++ side).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is odd that is only happens with G++/MSVC(???) as the C++ compiler

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

okay i'd look at the actual return value

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@thewilsonator I'm a bit lost here, how do I figure that out??

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

printf("cd->vtblOffset() = %d\n", cd->vtblOffset());

//assert(dmd::vtblOffset(cd) == 1);
cd->accept(&tv);
assert(tv.aggr == true);

Expand Down
Loading