-
Notifications
You must be signed in to change notification settings - Fork 593
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
Swap the Order that the Parser Creates 'Def' and 'Decl' Types #3359
Changes from all commits
6e41c52
877cb15
64da316
3b18c5d
f231569
ef3f744
f6fac9c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1173,10 +1173,8 @@ Slice::Container::createClassDef(const string& name, int id, const ClassDefPtr& | |
} | ||
else | ||
{ | ||
bool declared = dynamic_pointer_cast<InterfaceDecl>(matches.front()) != nullptr; | ||
ostringstream os; | ||
os << "class '" << name << "' was previously " << (declared ? "declared" : "defined") << " as " | ||
<< prependA(matches.front()->kindOf()); | ||
os << "class '" << name << "' was previously defined as " << prependA(matches.front()->kindOf()); | ||
_unit->error(os.str()); | ||
} | ||
return nullptr; | ||
|
@@ -1187,29 +1185,27 @@ Slice::Container::createClassDef(const string& name, int id, const ClassDefPtr& | |
return nullptr; | ||
} | ||
|
||
// Implicitly create a class declaration for each class definition. | ||
// This way the code generator can rely on always having a class declaration available for lookup. | ||
ClassDefPtr def = make_shared<ClassDef>(shared_from_this(), name, id, base); | ||
_unit->addContent(def); | ||
_contents.push_back(def); | ||
ClassDeclPtr decl = createClassDecl(name); | ||
def->_declaration = decl; | ||
decl->_definition = def; | ||
Comment on lines
+1191
to
+1193
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the main part of this PR. We want to call
So that |
||
|
||
// Patch forward declarations which may of been created in other openings of this class' module. | ||
for (const auto& q : matches) | ||
{ | ||
ClassDeclPtr decl = dynamic_pointer_cast<ClassDecl>(q); | ||
decl->_definition = def; | ||
dynamic_pointer_cast<ClassDecl>(q)->_definition = def; | ||
} | ||
|
||
// Implicitly create a class declaration for each class definition. | ||
// This way the code generator can rely on always having a class declaration available for lookup. | ||
ClassDeclPtr decl = createClassDecl(name); | ||
def->_declaration = decl; | ||
|
||
_unit->addContent(def); | ||
_contents.push_back(def); | ||
return def; | ||
} | ||
|
||
ClassDeclPtr | ||
Slice::Container::createClassDecl(const string& name) | ||
{ | ||
ClassDefPtr def; | ||
|
||
ContainedList matches = _unit->findContents(thisScope() + name); | ||
for (const auto& p : matches) | ||
{ | ||
|
@@ -1235,10 +1231,8 @@ Slice::Container::createClassDecl(const string& name) | |
} | ||
else | ||
{ | ||
bool declared = dynamic_pointer_cast<InterfaceDecl>(matches.front()) != nullptr; | ||
ostringstream os; | ||
os << "class '" << name << "' was previously " << (declared ? "declared" : "defined") << " as " | ||
<< prependA(matches.front()->kindOf()); | ||
Comment on lines
-1238
to
-1241
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Always say |
||
os << "class '" << name << "' was previously defined as " << prependA(matches.front()->kindOf()); | ||
_unit->error(os.str()); | ||
} | ||
return nullptr; | ||
|
@@ -1263,21 +1257,12 @@ Slice::Container::createClassDecl(const string& name) | |
{ | ||
return decl; | ||
} | ||
|
||
def = dynamic_pointer_cast<ClassDef>(q); | ||
assert(def); | ||
Comment on lines
-1267
to
-1268
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is impossible to hit. And the line above this is basically: So, even if a |
||
} | ||
} | ||
|
||
ClassDeclPtr decl = make_shared<ClassDecl>(shared_from_this(), name); | ||
_unit->addContent(decl); | ||
_contents.push_back(decl); | ||
|
||
if (def) | ||
{ | ||
decl->_definition = def; | ||
} | ||
Comment on lines
-1276
to
-1279
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ... And a result, |
||
|
||
return decl; | ||
} | ||
|
||
|
@@ -1320,10 +1305,8 @@ Slice::Container::createInterfaceDef(const string& name, const InterfaceList& ba | |
} | ||
else | ||
{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same idea as the code above, except for |
||
bool declared = dynamic_pointer_cast<ClassDecl>(matches.front()) != nullptr; | ||
ostringstream os; | ||
os << "interface '" << name << "' was previously " << (declared ? "declared" : "defined") << " as " | ||
<< prependA(matches.front()->kindOf()); | ||
os << "interface '" << name << "' was previously defined as " << prependA(matches.front()->kindOf()); | ||
_unit->error(os.str()); | ||
} | ||
return nullptr; | ||
|
@@ -1336,29 +1319,27 @@ Slice::Container::createInterfaceDef(const string& name, const InterfaceList& ba | |
|
||
InterfaceDecl::checkBasesAreLegal(name, bases, _unit); | ||
|
||
// Implicitly create an interface declaration for each interface definition. | ||
// This way the code generator can rely on always having an interface declaration available for lookup. | ||
InterfaceDefPtr def = make_shared<InterfaceDef>(shared_from_this(), name, bases); | ||
_unit->addContent(def); | ||
_contents.push_back(def); | ||
InterfaceDeclPtr decl = createInterfaceDecl(name); | ||
def->_declaration = decl; | ||
decl->_definition = def; | ||
|
||
// Patch forward declarations which may of been created in other openings of this interface's module. | ||
for (const auto& q : matches) | ||
{ | ||
InterfaceDeclPtr decl = dynamic_pointer_cast<InterfaceDecl>(q); | ||
decl->_definition = def; | ||
dynamic_pointer_cast<InterfaceDecl>(q)->_definition = def; | ||
} | ||
|
||
// Implicitly create an interface declaration for each interface definition. | ||
// This way the code generator can rely on always having an interface declaration available for lookup. | ||
InterfaceDeclPtr decl = createInterfaceDecl(name); | ||
def->_declaration = decl; | ||
|
||
_unit->addContent(def); | ||
_contents.push_back(def); | ||
return def; | ||
} | ||
|
||
InterfaceDeclPtr | ||
Slice::Container::createInterfaceDecl(const string& name) | ||
{ | ||
InterfaceDefPtr def; | ||
|
||
ContainedList matches = _unit->findContents(thisScope() + name); | ||
for (const auto& p : matches) | ||
{ | ||
|
@@ -1384,10 +1365,8 @@ Slice::Container::createInterfaceDecl(const string& name) | |
} | ||
else | ||
{ | ||
bool declared = dynamic_pointer_cast<ClassDecl>(matches.front()) != nullptr; | ||
ostringstream os; | ||
os << "interface '" << name << "' was previously " << (declared ? "declared" : "defined") << " as " | ||
<< prependA(matches.front()->kindOf()); | ||
os << "interface '" << name << "' was previously defined as " << prependA(matches.front()->kindOf()); | ||
_unit->error(os.str()); | ||
} | ||
return nullptr; | ||
|
@@ -1409,21 +1388,12 @@ Slice::Container::createInterfaceDecl(const string& name) | |
{ | ||
return decl; | ||
} | ||
|
||
def = dynamic_pointer_cast<InterfaceDef>(q); | ||
assert(def); | ||
} | ||
} | ||
|
||
InterfaceDeclPtr decl = make_shared<InterfaceDecl>(shared_from_this(), name); | ||
_unit->addContent(decl); | ||
_contents.push_back(decl); | ||
|
||
if (def) | ||
{ | ||
decl->_definition = def; | ||
} | ||
|
||
return decl; | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1057,9 +1057,7 @@ Slice::Gen::ForwardDeclVisitor::visitModuleEnd(const ModulePtr&) | |
void | ||
Slice::Gen::ForwardDeclVisitor::visitClassDecl(const ClassDeclPtr& p) | ||
{ | ||
ClassDefPtr def = p->definition(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. More dead variables. |
||
string name = fixKwd(p->name()); | ||
|
||
H << nl << "class " << name << ';'; | ||
H << nl << "using " << p->name() << "Ptr " << getDeprecatedAttribute(p) << "= ::std::shared_ptr<" << name << ">;" | ||
<< sp; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -131,11 +131,7 @@ CodeVisitor::visitClassDecl(const ClassDeclPtr& p) | |
|
||
string type = getTypeVar(p); | ||
_out << sp << nl << "global " << type << ';'; | ||
|
||
_out << nl << "if(!isset(" << type << "))"; | ||
_out << sb; | ||
_out << nl << type << " = IcePHP_declareClass('" << scoped << "');"; | ||
_out << eb; | ||
Comment on lines
-135
to
-138
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe that this check for
which should ensure that this code is only generated once. Even if I'm wrong (which I don't think I am), there's nothing wrong with setting |
||
|
||
endNamespace(); | ||
|
||
|
@@ -156,10 +152,7 @@ CodeVisitor::visitInterfaceDecl(const InterfaceDeclPtr& p) | |
_out << sp << nl << "global " << type << ';'; | ||
|
||
_out << nl << "global " << type << "Prx;"; | ||
_out << nl << "if(!isset(" << type << "))"; | ||
_out << sb; | ||
_out << nl << type << "Prx = IcePHP_declareProxy('" << scoped << "');"; | ||
_out << eb; | ||
|
||
endNamespace(); | ||
|
||
|
@@ -271,12 +264,6 @@ CodeVisitor::visitClassDefStart(const ClassDefPtr& p) | |
|
||
_out << eb; // End of class. | ||
|
||
if (_classHistory.count(scoped) == 0 && p->canBeCyclic()) | ||
{ | ||
// Emit a forward declaration for the class in case a data member refers to this type. | ||
_out << sp << nl << type << " = IcePHP_declareClass('" << scoped << "');"; | ||
} | ||
Comment on lines
-274
to
-278
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Impossible to hit. |
||
|
||
{ | ||
string type; | ||
vector<string> seenType; | ||
|
@@ -348,11 +335,6 @@ CodeVisitor::visitClassDefStart(const ClassDefPtr& p) | |
|
||
endNamespace(); | ||
|
||
if (_classHistory.count(scoped) == 0) | ||
{ | ||
_classHistory.insert(scoped); // Avoid redundant declarations. | ||
} | ||
|
||
return false; | ||
} | ||
|
||
|
@@ -583,11 +565,6 @@ CodeVisitor::visitInterfaceDefStart(const InterfaceDefPtr& p) | |
|
||
endNamespace(); | ||
|
||
if (_classHistory.count(scoped) == 0) | ||
{ | ||
_classHistory.insert(scoped); // Avoid redundant declarations. | ||
} | ||
|
||
return false; | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -551,7 +551,6 @@ Slice::Python::CodeVisitor::visitClassDefStart(const ClassDefPtr& p) | |
{ | ||
string scoped = p->scoped(); | ||
string type = getAbsolute(p, "_t_"); | ||
string classType = getAbsolute(p, "_t_", "Disp"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So many dead variables. |
||
string abs = getAbsolute(p); | ||
string valueName = fixIdent(p->name()); | ||
ClassDefPtr base = p->base(); | ||
|
@@ -639,13 +638,6 @@ Slice::Python::CodeVisitor::visitClassDefStart(const ClassDefPtr& p) | |
|
||
_out.dec(); | ||
|
||
if (_classHistory.count(scoped) == 0 && p->canBeCyclic()) | ||
{ | ||
// | ||
// Emit a forward declaration for the class in case a data member refers to this type. | ||
// | ||
_out << sp << nl << "_M_" << type << " = IcePy.declareValue('" << scoped << "')"; | ||
} | ||
Comment on lines
-642
to
-648
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Impossible to hit.
|
||
DataMemberList members = p->dataMembers(); | ||
_out << sp << nl << "_M_" << type << " = IcePy.defineValue('" << scoped << "', " << valueName << ", " | ||
<< p->compactId() << ", "; | ||
|
@@ -708,19 +700,13 @@ Slice::Python::CodeVisitor::visitClassDefStart(const ClassDefPtr& p) | |
|
||
_out.dec(); | ||
|
||
if (_classHistory.count(scoped) == 0) | ||
{ | ||
_classHistory.insert(scoped); // Avoid redundant declarations. | ||
} | ||
|
||
return false; | ||
} | ||
|
||
bool | ||
Slice::Python::CodeVisitor::visitInterfaceDefStart(const InterfaceDefPtr& p) | ||
{ | ||
string scoped = p->scoped(); | ||
string type = getAbsolute(p, "_t_"); | ||
string classType = getAbsolute(p, "_t_", "Disp"); | ||
string abs = getAbsolute(p); | ||
string className = fixIdent(p->name()); | ||
|
@@ -977,7 +963,7 @@ Slice::Python::CodeVisitor::visitInterfaceDefStart(const InterfaceDefPtr& p) | |
// | ||
_out << sp << nl << "def __str__(self):"; | ||
_out.inc(); | ||
_out << nl << "return IcePy.stringify(self, _M_" << getAbsolute(p, "_t_", "Disp") << ")"; | ||
_out << nl << "return IcePy.stringify(self, _M_" << classType << ")"; | ||
_out.dec(); | ||
_out << sp << nl << "__repr__ = __str__"; | ||
|
||
|
@@ -1114,11 +1100,6 @@ Slice::Python::CodeVisitor::visitInterfaceDefStart(const InterfaceDefPtr& p) | |
registerName(className); | ||
_out.dec(); | ||
|
||
if (_classHistory.count(scoped) == 0) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same but for |
||
{ | ||
_classHistory.insert(scoped); // Avoid redundant declarations. | ||
} | ||
|
||
return false; | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -370,17 +370,6 @@ Slice::Ruby::CodeVisitor::visitClassDefStart(const ClassDefPtr& p) | |
_out.dec(); | ||
_out << nl << "end"; // End of class. | ||
|
||
// | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. All the exact same code is executed by And now that we're guaranteed to run |
||
// Emit type descriptions. | ||
// | ||
_out << sp << nl << "if not defined?(" << getAbsolute(p, IdentToUpper, "T_"); | ||
_out << ')'; | ||
_out.inc(); | ||
_out << nl << "T_" << name << " = ::Ice::__declareClass('" << scoped << "')"; | ||
_out.dec(); | ||
_out << nl << "end"; | ||
_classHistory.insert(scoped); // Avoid redundant declarations. | ||
|
||
_out << sp << nl << "T_" << name << ".defineClass(" << name << ", " << p->compactId() << ", " | ||
<< "false, "; | ||
if (!base) | ||
|
@@ -502,18 +491,6 @@ Slice::Ruby::CodeVisitor::visitInterfaceDefStart(const InterfaceDefPtr& p) | |
_out.dec(); | ||
_out << nl << "end"; // End of proxy class. | ||
|
||
// | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same but for |
||
// Emit type descriptions. | ||
// | ||
_out << sp << nl << "if not defined?(" << getAbsolute(p, IdentToUpper, "T_"); | ||
_out << "Prx"; | ||
_out << ')'; | ||
_out.inc(); | ||
_out << nl << "T_" << name << "Prx = ::Ice::__declareProxy('" << scoped << "')"; | ||
_out.dec(); | ||
_out << nl << "end"; | ||
_classHistory.insert(scoped); // Avoid redundant declarations. | ||
|
||
// | ||
// Define each operation. The arguments to __defineOperation are: | ||
// | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
InterfaceMismatch.ice:9: class 'Foo1' was previously declared as an interface | ||
InterfaceMismatch.ice:10: class 'Foo1' was previously declared as an interface | ||
InterfaceMismatch.ice:9: class 'Foo1' was previously defined as an interface | ||
InterfaceMismatch.ice:10: class 'Foo1' was previously defined as an interface | ||
InterfaceMismatch.ice:13: class 'Foo2' was previously defined as an interface | ||
InterfaceMismatch.ice:16: interface 'Foo3' was previously declared as a class | ||
InterfaceMismatch.ice:17: interface 'Foo3' was previously declared as a class | ||
InterfaceMismatch.ice:16: interface 'Foo3' was previously defined as a class | ||
InterfaceMismatch.ice:17: interface 'Foo3' was previously defined as a class | ||
InterfaceMismatch.ice:20: interface 'Foo4' was previously defined as a class |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,13 +22,13 @@ WarningInvalidMetadata.ice:31: warning: the 'cpp:no-default-include' metadata do | |
WarningInvalidMetadata.ice:34: warning: 'amd' metadata cannot be specified as file metadata | ||
WarningInvalidMetadata.ice:40: warning: the 'cpp:header-ext' metadata only accepts one argument but a list was provided | ||
WarningInvalidMetadata.ice:40: warning: 'cpp:header-ext' metadata cannot be applied to sequences | ||
WarningInvalidMetadata.ice:44: warning: ignoring duplicate metadata: 'deprecated:do not use this' does not match previously applied metadata of 'deprecated' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And finally, the original reason for doing this: |
||
WarningInvalidMetadata.ice:48: warning: ignoring unknown metadata: 'unknown' | ||
WarningInvalidMetadata.ice:48: warning: ignoring unknown metadata: 'cpp:unknown' | ||
WarningInvalidMetadata.ice:48: warning: ignoring unknown metadata: 'bad:unknown' | ||
WarningInvalidMetadata.ice:56: warning: the 'protected' metadata does not take any arguments | ||
WarningInvalidMetadata.ice:56: warning: the 'cpp:array' metadata does not take any arguments | ||
WarningInvalidMetadata.ice:56: warning: 'cpp:array' metadata can only be applied to operation parameters and return types | ||
WarningInvalidMetadata.ice:44: warning: ignoring duplicate metadata: 'deprecated:do not use this' does not match previously applied metadata of 'deprecated' | ||
WarningInvalidMetadata.ice:62: warning: 'cpp:type' metadata cannot be applied to operations with void return type | ||
WarningInvalidMetadata.ice:65: warning: 'cpp:array' metadata cannot be applied to operations with void return type | ||
WarningInvalidMetadata.ice:68: warning: invalid argument 'my_string' supplied to 'cpp:type' metadata in this context | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When discussing this before we decided to no longer emit
was previously declared
vswas previously defined
based on whether we hit a forward declaration. Now we always saywas previously defined
.