Skip to content

Commit

Permalink
Address Dead Code in the Slice Compilers (#3188)
Browse files Browse the repository at this point in the history
  • Loading branch information
InsertCreativityHere authored Nov 25, 2024
1 parent 0a6dc57 commit 77599a1
Show file tree
Hide file tree
Showing 10 changed files with 393 additions and 834 deletions.
688 changes: 337 additions & 351 deletions cpp/src/Slice/Grammar.cpp

Large diffs are not rendered by default.

78 changes: 32 additions & 46 deletions cpp/src/Slice/Grammar.y
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,6 @@ optional
{
auto scoped = dynamic_pointer_cast<StringTok>($2);
ContainerPtr cont = currentUnit->currentContainer();
assert(cont);
ContainedList cl = cont->lookupContained(scoped->v, false);
if (cl.empty())
{
Expand Down Expand Up @@ -790,7 +789,6 @@ class_id
auto scoped = dynamic_pointer_cast<StringTok>($3);

ContainerPtr cont = currentUnit->currentContainer();
assert(cont);
ContainedList cl = cont->lookupContained(scoped->v, false);
if (cl.empty())
{
Expand Down Expand Up @@ -1912,63 +1910,51 @@ type
{
auto scoped = dynamic_pointer_cast<StringTok>($1);
ContainerPtr cont = currentUnit->currentContainer();
if (cont)
{
TypeList types = cont->lookupType(scoped->v);
if (types.empty())
{
YYERROR; // Can't continue, jump to next yyerrok
}
TypePtr firstType = types.front();

auto interface = dynamic_pointer_cast<InterfaceDecl>(firstType);
if (interface)
{
string msg = "add a '*' after the interface name to specify its proxy type: '";
msg += scoped->v;
msg += "*'";
currentUnit->error(msg);
YYERROR; // Can't continue, jump to next yyerrok
}
cont->checkIntroduced(scoped->v);

$$ = firstType;
TypeList types = cont->lookupType(scoped->v);
if (types.empty())
{
YYERROR; // Can't continue, jump to next yyerrok
}
else
TypePtr firstType = types.front();

auto interface = dynamic_pointer_cast<InterfaceDecl>(firstType);
if (interface)
{
$$ = nullptr;
string msg = "add a '*' after the interface name to specify its proxy type: '";
msg += scoped->v;
msg += "*'";
currentUnit->error(msg);
YYERROR; // Can't continue, jump to next yyerrok
}
cont->checkIntroduced(scoped->v);

$$ = firstType;
}
| scoped_name '*'
{
auto scoped = dynamic_pointer_cast<StringTok>($1);
ContainerPtr cont = currentUnit->currentContainer();
if (cont)
{
TypeList types = cont->lookupType(scoped->v);
if (types.empty())
{
YYERROR; // Can't continue, jump to next yyerrok
}
TypePtr firstType = types.front();

auto interface = dynamic_pointer_cast<InterfaceDecl>(firstType);
if (!interface)
{
string msg = "`";
msg += scoped->v;
msg += "' must be an interface";
currentUnit->error(msg);
YYERROR; // Can't continue, jump to next yyerrok
}
cont->checkIntroduced(scoped->v);

$$ = firstType;
TypeList types = cont->lookupType(scoped->v);
if (types.empty())
{
YYERROR; // Can't continue, jump to next yyerrok
}
else
TypePtr firstType = types.front();

auto interface = dynamic_pointer_cast<InterfaceDecl>(firstType);
if (!interface)
{
$$ = nullptr;
string msg = "`";
msg += scoped->v;
msg += "' must be an interface";
currentUnit->error(msg);
YYERROR; // Can't continue, jump to next yyerrok
}
cont->checkIntroduced(scoped->v);

$$ = firstType;
}
;

Expand Down
113 changes: 3 additions & 110 deletions cpp/src/Slice/Parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -400,19 +400,6 @@ Slice::Type::usesClasses() const
// Builtin
// ----------------------------------------------------------------------

string
Slice::Builtin::typeId() const
{
if (usesClasses() || _kind == KindObjectProxy)
{
return "::Ice::" + kindAsString();
}
else
{
return kindAsString();
}
}

bool
Slice::Builtin::isClassType() const
{
Expand Down Expand Up @@ -447,6 +434,7 @@ Slice::Builtin::minWireSize() const
case KindValue:
return 1; // at least one byte (to marshal an index instead of an instance).
default:
// TODO remove after converting `kind` to an `enum class`.
throw logic_error("no min wire size");
}
}
Expand Down Expand Up @@ -475,6 +463,7 @@ Slice::Builtin::getOptionalFormat() const
case KindObjectProxy:
return "FSize";
default:
// TODO remove after converting `kind` to an `enum class`.
throw logic_error("no optional format");
}
}
Expand Down Expand Up @@ -1233,7 +1222,6 @@ Slice::Container::createClassDecl(const string& name)
}
}

_unit->currentContainer();
ClassDeclPtr decl = make_shared<ClassDecl>(shared_from_this(), name);
_unit->addContent(decl);
_contents.push_back(decl);
Expand Down Expand Up @@ -1383,7 +1371,6 @@ Slice::Container::createInterfaceDecl(const string& name)
}
}

_unit->currentContainer();
InterfaceDeclPtr decl = make_shared<InterfaceDecl>(shared_from_this(), name);
_unit->addContent(decl);
_contents.push_back(decl);
Expand Down Expand Up @@ -1865,22 +1852,6 @@ Slice::Container::modules() const
return result;
}

ClassList
Slice::Container::classes() const
{
ClassList result;

for (const auto& p : _contents)
{
ClassDefPtr q = dynamic_pointer_cast<ClassDef>(p);
if (q)
{
result.push_back(q);
}
}
return result;
}

InterfaceList
Slice::Container::interfaces() const
{
Expand All @@ -1896,21 +1867,6 @@ Slice::Container::interfaces() const
return result;
}

ExceptionList
Slice::Container::exceptions() const
{
ExceptionList result;
for (const auto& p : _contents)
{
ExceptionPtr q = dynamic_pointer_cast<Exception>(p);
if (q)
{
result.push_back(q);
}
}
return result;
}

EnumList
Slice::Container::enums() const
{
Expand Down Expand Up @@ -2141,11 +2097,6 @@ Slice::Container::validateConstant(
{
// isConstant indicates whether a constant or a data member (with a default value) is being defined.

if (!type)
{
return false;
}

const string desc = isConstant ? "constant" : "data member";

// If valueType is a ConstPtr, it means the constant or data member being defined refers to another constant.
Expand Down Expand Up @@ -2395,12 +2346,6 @@ Slice::Module::Module(const ContainerPtr& container, const string& name)
// Constructed
// ----------------------------------------------------------------------

string
Slice::Constructed::typeId() const
{
return scoped();
}

Slice::Constructed::Constructed(const ContainerPtr& container, const string& name)
: SyntaxTreeBase(container->unit()),
Type(container->unit()),
Expand Down Expand Up @@ -2467,7 +2412,6 @@ Slice::ClassDecl::ClassDecl(const ContainerPtr& container, const string& name)
Contained(container, name),
Constructed(container, name)
{
_unit->currentContainer();
}

// ----------------------------------------------------------------------
Expand Down Expand Up @@ -2688,18 +2632,6 @@ Slice::ClassDef::canBeCyclic() const
return false;
}

bool
Slice::ClassDef::inheritsMetadata(string_view directive) const
{
return _base && (_base->hasMetadata(directive) || _base->inheritsMetadata(directive));
}

bool
Slice::ClassDef::hasBaseDataMembers() const
{
return _base && !_base->allDataMembers().empty();
}

string
Slice::ClassDef::kindOf() const
{
Expand Down Expand Up @@ -2826,7 +2758,6 @@ Slice::InterfaceDecl::InterfaceDecl(const ContainerPtr& container, const string&
Contained(container, name),
Constructed(container, name)
{
_unit->currentContainer();
}

// Return true if the interface definition `idp` is on one of the interface lists in `gpl`, false otherwise.
Expand Down Expand Up @@ -3037,7 +2968,6 @@ Slice::InterfaceDef::createOperation(
}
}

_hasOperations = true;
OperationPtr op = make_shared<Operation>(shared_from_this(), name, returnType, isOptional, tag, mode);
_unit->addContent(op);
_contents.push_back(op);
Expand Down Expand Up @@ -3116,25 +3046,6 @@ Slice::InterfaceDef::allOperations() const
return result;
}

bool
Slice::InterfaceDef::hasOperations() const
{
return _hasOperations;
}

bool
Slice::InterfaceDef::inheritsMetadata(string_view directive) const
{
for (const auto& p : _bases)
{
if (p->hasMetadata(directive) || p->inheritsMetadata(directive))
{
return true;
}
}
return false;
}

string
Slice::InterfaceDef::kindOf() const
{
Expand Down Expand Up @@ -3169,8 +3080,7 @@ Slice::InterfaceDef::InterfaceDef(const ContainerPtr& container, const string& n
: SyntaxTreeBase(container->unit()),
Container(container->unit()),
Contained(container, name),
_bases(bases),
_hasOperations(false)
_bases(bases)
{
}

Expand Down Expand Up @@ -3785,23 +3695,6 @@ Slice::Exception::usesClasses() const
return false;
}

bool
Slice::Exception::inheritsMetadata(string_view directive) const
{
if (_base && (_base->hasMetadata(directive) || _base->inheritsMetadata(directive)))
{
return true;
}

return false;
}

bool
Slice::Exception::hasBaseDataMembers() const
{
return _base && !_base->allDataMembers().empty();
}

string
Slice::Exception::kindOf() const
{
Expand Down
Loading

0 comments on commit 77599a1

Please sign in to comment.