Skip to content

Commit

Permalink
Fix shadow warnings in slice2js and slice2matlab
Browse files Browse the repository at this point in the history
  • Loading branch information
pepone committed Jan 22, 2024
1 parent 9af8a37 commit 05382e3
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 81 deletions.
66 changes: 25 additions & 41 deletions cpp/src/slice2js/Gen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,6 @@
#include <algorithm>
#include <iterator>

// TODO: fix this warning!
#if defined(_MSC_VER)
# pragma warning(disable:4456) // shadow
# pragma warning(disable:4457) // shadow
# pragma warning(disable:4459) // shadow
#elif defined(__clang__)
# pragma clang diagnostic ignored "-Wshadow"
#elif defined(__GNUC__)
# pragma GCC diagnostic ignored "-Wshadow"
#endif

using namespace std;
using namespace Slice;
using namespace IceUtil;
Expand Down Expand Up @@ -748,18 +737,19 @@ Slice::Gen::generate(const UnitPtr& p)
_jsout.restoreIndent();
}
}
RequireVisitor requireVisitor(_jsout, _includePaths, icejs, es6module);
p->visit(&requireVisitor, false);
vector<string> seenModules = requireVisitor.writeRequires(p);

TypesVisitor typesVisitor(_jsout, seenModules, icejs);
p->visit(&typesVisitor, false);
{
RequireVisitor requireVisitor(_jsout, _includePaths, icejs, es6module);
p->visit(&requireVisitor, false);
vector<string> seenModules = requireVisitor.writeRequires(p);

//
// Export the top-level modules.
//
ExportVisitor exportVisitor(_jsout, icejs, es6module);
p->visit(&exportVisitor, false);
TypesVisitor typesVisitor(_jsout, seenModules, icejs);
p->visit(&typesVisitor, false);

// Export the top-level modules.
ExportVisitor exportVisitor(_jsout, icejs, es6module);
p->visit(&exportVisitor, false);
}

if(iifemodule)
{
Expand Down Expand Up @@ -1049,29 +1039,27 @@ Slice::Gen::RequireVisitor::writeRequires(const UnitPtr& p)

if(m1 != m2 && !m2.empty())
{
for(set<string>::const_iterator j = modules.begin(); j != modules.end(); ++j)
for(const auto& j : modules)
{
if(imports.find(m2) == imports.end())
{
set<string> mImports;
mImports.insert(*j);
imports[m2] = mImports;
imports[m2] = set<string> { j };
}
else
{
imports[m2].insert(*j);
imports[m2].insert(j);
}
}
}
else
{
set<string> newModules;
for(set<string>::const_iterator j = modules.begin(); j != modules.end(); ++j)
for (const auto& j : modules)
{
if(find(seenModules.begin(), seenModules.end(), *j) == seenModules.end())
if (find(seenModules.begin(), seenModules.end(), j) == seenModules.end())
{
seenModules.push_back(*j);
newModules.insert(*j);
seenModules.push_back(j);
newModules.insert(j);
}
}

Expand Down Expand Up @@ -1103,7 +1091,7 @@ Slice::Gen::RequireVisitor::writeRequires(const UnitPtr& p)

_out << nl << "const _ModuleRegistry = Ice._ModuleRegistry;";

for(map<string, set<string> >::const_iterator i = imports.begin(); i != imports.end(); ++i)
for (map<string, set<string> >::const_iterator i = imports.begin(); i != imports.end(); ++i)
{
if(i->first != "ice")
{
Expand All @@ -1112,10 +1100,10 @@ Slice::Gen::RequireVisitor::writeRequires(const UnitPtr& p)
if(!mImports.empty())
{
_out << "{ ";
for(set<string>::const_iterator i = mImports.begin(); i != mImports.end();)
for (set<string>::const_iterator j = mImports.begin(); j != mImports.end();)
{
_out << (*i);
if(++i != mImports.end())
_out << (*j);
if(++j != mImports.end())
{
_out << ", ";
}
Expand Down Expand Up @@ -1555,7 +1543,7 @@ Slice::Gen::TypesVisitor::visitInterfaceDefStart(const InterfaceDefPtr& p)
}

OperationPtr op = *q;
const string name = fixId(op->name());
const string opName = fixId(op->name());
const ParamDeclList paramList = op->parameters();
const TypePtr ret = op->returnType();
ParamDeclList inParams, outParams;
Expand Down Expand Up @@ -1590,9 +1578,9 @@ Slice::Gen::TypesVisitor::visitInterfaceDefStart(const InterfaceDefPtr& p)
//
_out << nl << "\"" << op->name() << "\": ["; // Operation name over-the-wire.

if(name != op->name())
if(opName != op->name())
{
_out << "\"" << name << "\""; // Native method name.
_out << "\"" << opName << "\""; // Native method name.
}
_out << ", ";

Expand Down Expand Up @@ -1709,11 +1697,7 @@ Slice::Gen::TypesVisitor::visitInterfaceDefStart(const InterfaceDefPtr& p)
ExceptionList throws = op->throws();
throws.sort();
throws.unique();
#if defined(__SUNPRO_CC)
throws.sort(derivedToBaseCompare);
#else
throws.sort(Slice::DerivedToBaseCompare());
#endif
if(throws.empty())
{
_out << " ";
Expand Down
64 changes: 24 additions & 40 deletions cpp/src/slice2matlab/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,6 @@ using namespace std;
using namespace Slice;
using namespace IceUtilInternal;

// TODO: fix this warning!
#if defined(_MSC_VER)
# pragma warning(disable:4456) // shadow
# pragma warning(disable:4457) // shadow
# pragma warning(disable:4459) // shadow
#elif defined(__clang__)
# pragma clang diagnostic ignored "-Wshadow"
#elif defined(__GNUC__)
# pragma GCC diagnostic ignored "-Wshadow"
#endif

namespace
{

Expand Down Expand Up @@ -1987,7 +1976,6 @@ CodeVisitor::visitInterfaceDefStart(const InterfaceDefPtr& p)
const string abs = getAbsolute(p);
InterfaceList bases = p->bases();
const OperationList allOps = p->allOperations();
const string self = name == "obj" ? "this" : "obj";

//
// Generate proxy class.
Expand Down Expand Up @@ -2158,18 +2146,18 @@ CodeVisitor::visitInterfaceDefStart(const InterfaceDefPtr& p)
{
if(r->param)
{
string name;
string param;
if(isClass(r->type))
{
out << nl << r->fixedName << "_h_ = IceInternal.ValueHolder();";
name = "@(v) " + r->fixedName + "_h_.set(v)";
param = "@(v) " + r->fixedName + "_h_.set(v)";
classParams.push_back(*r);
}
else
{
name = r->fixedName;
param = r->fixedName;
}
unmarshal(out, "is_", name, r->type, false, -1);
unmarshal(out, "is_", param, r->type, false, -1);

if(needsConversion(r->type))
{
Expand All @@ -2183,18 +2171,18 @@ CodeVisitor::visitInterfaceDefStart(const InterfaceDefPtr& p)
if(!requiredOutParams.empty() && !requiredOutParams.begin()->param)
{
ParamInfoList::const_iterator r = requiredOutParams.begin();
string name;
string param;
if(isClass(r->type))
{
out << nl << r->fixedName << "_h_ = IceInternal.ValueHolder();";
name = "@(v) " + r->fixedName + "_h_.set(v)";
param = "@(v) " + r->fixedName + "_h_.set(v)";
classParams.push_back(*r);
}
else
{
name = r->fixedName;
param = r->fixedName;
}
unmarshal(out, "is_", name, r->type, false, -1);
unmarshal(out, "is_", param, r->type, false, -1);

if(needsConversion(r->type))
{
Expand All @@ -2206,18 +2194,18 @@ CodeVisitor::visitInterfaceDefStart(const InterfaceDefPtr& p)
//
for(ParamInfoList::const_iterator r = optionalOutParams.begin(); r != optionalOutParams.end(); ++r)
{
string name;
string param;
if(isClass(r->type))
{
out << nl << r->fixedName << "_h_ = IceInternal.ValueHolder();";
name = "@(v) " + r->fixedName + "_h_.set(v)";
param = "@(v) " + r->fixedName + "_h_.set(v)";
classParams.push_back(*r);
}
else
{
name = r->fixedName;
param = r->fixedName;
}
unmarshal(out, "is_", name, r->type, r->optional, r->tag);
unmarshal(out, "is_", param, r->type, r->optional, r->tag);

if(needsConversion(r->type))
{
Expand Down Expand Up @@ -2303,17 +2291,17 @@ CodeVisitor::visitInterfaceDefStart(const InterfaceDefPtr& p)
{
if(r->param)
{
string name;
string param;
if(isClass(r->type))
{
out << nl << r->fixedName << " = IceInternal.ValueHolder();";
name = "@(v) " + r->fixedName + ".set(v)";
param = "@(v) " + r->fixedName + ".set(v)";
}
else
{
name = r->fixedName;
param = r->fixedName;
}
unmarshal(out, "is_", name, r->type, r->optional, r->tag);
unmarshal(out, "is_", param, r->type, r->optional, r->tag);
}
}
//
Expand All @@ -2322,34 +2310,34 @@ CodeVisitor::visitInterfaceDefStart(const InterfaceDefPtr& p)
if(!requiredOutParams.empty() && !requiredOutParams.begin()->param)
{
ParamInfoList::const_iterator r = requiredOutParams.begin();
string name;
string param;
if(isClass(r->type))
{
out << nl << r->fixedName << " = IceInternal.ValueHolder();";
name = "@(v) " + r->fixedName + ".set(v)";
param = "@(v) " + r->fixedName + ".set(v)";
}
else
{
name = r->fixedName;
param = r->fixedName;
}
unmarshal(out, "is_", name, r->type, false, -1);
unmarshal(out, "is_", param, r->type, false, -1);
}
//
// Now unmarshal all optional out parameters. They are already sorted by tag.
//
for(ParamInfoList::const_iterator r = optionalOutParams.begin(); r != optionalOutParams.end(); ++r)
{
string name;
string param;
if(isClass(r->type))
{
out << nl << r->fixedName << " = IceInternal.ValueHolder();";
name = "@(v) " + r->fixedName + ".set(v)";
param = "@(v) " + r->fixedName + ".set(v)";
}
else
{
name = r->fixedName;
param = r->fixedName;
}
unmarshal(out, "is_", name, r->type, r->optional, r->tag);
unmarshal(out, "is_", param, r->type, r->optional, r->tag);
}
if(op->returnsClasses(false))
{
Expand Down Expand Up @@ -2504,11 +2492,7 @@ CodeVisitor::visitInterfaceDefStart(const InterfaceDefPtr& p)
// handler, causing compiler warnings and resulting in the base exception
// being marshaled instead of the derived exception.
//
#if defined(__SUNPRO_CC)
exceptions.sort(Slice::derivedToBaseCompare);
#else
exceptions.sort(Slice::DerivedToBaseCompare());
#endif

if(!exceptions.empty())
{
Expand Down

0 comments on commit 05382e3

Please sign in to comment.