summaryrefslogtreecommitdiff
path: root/cpp/src
diff options
context:
space:
mode:
Diffstat (limited to 'cpp/src')
-rw-r--r--cpp/src/Slice/Parser.cpp100
-rw-r--r--cpp/src/slice2cpp/Gen.cpp53
-rw-r--r--cpp/src/slice2java/Gen.cpp52
3 files changed, 162 insertions, 43 deletions
diff --git a/cpp/src/Slice/Parser.cpp b/cpp/src/Slice/Parser.cpp
index 45ae1635d78..47a39dc5325 100644
--- a/cpp/src/Slice/Parser.cpp
+++ b/cpp/src/Slice/Parser.cpp
@@ -20,6 +20,17 @@ using namespace Slice;
extern FILE* slice_in;
extern int slice_debug;
+//
+// Operation attributes
+//
+// read + supports must be 0 (the default)
+//
+
+static string readWriteAttribute[] = { "read", "write" };
+static string txAttribute[] = { "supports", "mandatory", "required", "never" };
+enum { Supports, Mandatory, Required, Never };
+
+
namespace Slice
{
@@ -4565,6 +4576,95 @@ Slice::Operation::returnsData() const
return false;
}
+int
+Slice::Operation::attributes() const
+{
+ string freezeMD;
+
+ if(!findMetaData("freeze:", freezeMD))
+ {
+ ClassDefPtr classDef = ClassDefPtr::dynamicCast(container());
+ assert(classDef != 0);
+ classDef->findMetaData("freeze:", freezeMD);
+ }
+
+ if(freezeMD != "")
+ {
+ int result = 0;
+
+ freezeMD = freezeMD.substr(strlen("freeze:"));
+
+ int i = 0;
+ while(i < 2)
+ {
+ if(freezeMD.find(readWriteAttribute[i]) == 0)
+ {
+ result = i;
+ freezeMD = freezeMD.substr(readWriteAttribute[i].size());
+ break; // while
+ }
+ i++;
+ }
+ if(i == 2)
+ {
+ cout << definitionContext()->filename() << ":" << line()
+ << ": warning: invalid freeze metadata for operation" << endl;
+ }
+ else
+ {
+ if(freezeMD.size() == 0)
+ {
+ freezeMD = (result == 0) ? ":supports" : ":required";
+ }
+
+ //
+ // Remove ":"
+ //
+ freezeMD = freezeMD.substr(1);
+
+ int i = 0;
+ while(i < 4)
+ {
+ if(freezeMD.find(txAttribute[i]) == 0)
+ {
+ if(result != 0 && (i == int(Supports) || i == int(Never)))
+ {
+ cout << definitionContext()->filename() << ":" << line()
+ << ": warning: invalid freeze metadata for operation" << endl;
+ }
+ else
+ {
+ result |= (i << 1);
+ }
+ freezeMD = freezeMD.substr(txAttribute[i].size());
+ break; // while
+ }
+ i++;
+ }
+
+ if(i == 4)
+ {
+ cout << definitionContext()->filename() << ":" << line()
+ << ": warning: invalid freeze metadata for operation" << endl;
+
+ //
+ // Set default
+ //
+ if(result != 0)
+ {
+ result |= (int(Required) << 1);
+ }
+ }
+ }
+ return result;
+ }
+ else
+ {
+ return 0;
+ }
+}
+
+
string
Slice::Operation::kindOf() const
{
diff --git a/cpp/src/slice2cpp/Gen.cpp b/cpp/src/slice2cpp/Gen.cpp
index 539366963ed..5ac715b2d49 100644
--- a/cpp/src/slice2cpp/Gen.cpp
+++ b/cpp/src/slice2cpp/Gen.cpp
@@ -3148,41 +3148,47 @@ Slice::Gen::ObjectVisitor::visitClassDefEnd(const ClassDefPtr& p)
//
// Check if we need to generate ice_operationAttributes()
//
-
- StringList freezeWriteOpNames;
+ map<string, int> attributesMap;
for(OperationList::iterator r = allOps.begin(); r != allOps.end(); ++r)
{
- ClassDefPtr classDef = ClassDefPtr::dynamicCast((*r)->container());
- assert(classDef != 0);
-
- if((*r)->hasMetaData("freeze:write") ||
- (classDef->hasMetaData("freeze:write") && !(*r)->hasMetaData("freeze:read")))
+ int attributes = (*r)->attributes();
+ if(attributes != 0)
{
- freezeWriteOpNames.push_back((*r)->name());
+ attributesMap.insert(map<string, int>::value_type((*r)->name(), attributes));
}
}
- if(!freezeWriteOpNames.empty())
+ if(!attributesMap.empty())
{
- freezeWriteOpNames.sort();
-
H << sp;
H << nl
<< "virtual ::Ice::Int ice_operationAttributes(const ::std::string&) const;";
- flatName = p->flattenedScope() + p->name() + "_freezeWriteOperations";
+ string opAttrFlatName = p->flattenedScope() + p->name() + "_operationAttributes";
+
C << sp;
- C << nl << "static ::std::string " << flatName << "[] =";
+ C << nl << "static int " << opAttrFlatName << "[] = ";
C << sb;
- q = freezeWriteOpNames.begin();
- while(q != freezeWriteOpNames.end())
+
+ q = allOpNames.begin();
+ while(q != allOpNames.end())
{
- C << nl << '"' << *q << '"';
- if(++q != freezeWriteOpNames.end())
+ int attributes = 0;
+ string opName = *q;
+ map<string, int>::iterator it = attributesMap.find(opName);
+ if(it != attributesMap.end())
+ {
+ attributes = it->second;
+ }
+ C << nl << attributes;
+
+ if(++q != allOpNames.end())
{
C << ',';
}
+ C << " // " << opName;
}
+
C << eb << ';';
C << sp;
@@ -3190,10 +3196,15 @@ Slice::Gen::ObjectVisitor::visitClassDefEnd(const ClassDefPtr& p)
<< "::ice_operationAttributes(const ::std::string& opName) const";
C << sb;
- C << nl << "::std::string* end = " << flatName << " + " << freezeWriteOpNames.size() << ";";
- C << nl << "::std::string* r = ::std::find(" << flatName << ", end, opName);";
-
- C << nl << "return r == end ? 0 : 1;";
+ C << nl << "::std::pair< ::std::string*, ::std::string*> r = "
+ << "::std::equal_range(" << flatName << ", " << flatName << " + " << allOpNames.size()
+ << ", opName);";
+ C << nl << "if(r.first == r.second)";
+ C << sb;
+ C << nl << "return -1;";
+ C << eb;
+
+ C << nl << "return " << opAttrFlatName << "[r.first - " << flatName << "];";
C << eb;
}
}
diff --git a/cpp/src/slice2java/Gen.cpp b/cpp/src/slice2java/Gen.cpp
index fb07de4ca1c..c41701a79e5 100644
--- a/cpp/src/slice2java/Gen.cpp
+++ b/cpp/src/slice2java/Gen.cpp
@@ -910,42 +910,50 @@ Slice::JavaVisitor::writeDispatchAndMarshalling(Output& out, const ClassDefPtr&
//
// Check if we need to generate ice_operationAttributes()
//
-
- StringList freezeWriteOpNames;
+
+ map<string, int> attributesMap;
for(OperationList::iterator r = allOps.begin(); r != allOps.end(); ++r)
{
- ClassDefPtr classDef = ClassDefPtr::dynamicCast((*r)->container());
- assert(classDef != 0);
-
- if((*r)->hasMetaData("freeze:write") ||
- (classDef->hasMetaData("freeze:write") && !(*r)->hasMetaData("freeze:read")))
+ int attributes = (*r)->attributes();
+ if(attributes != 0)
{
- freezeWriteOpNames.push_back((*r)->name());
+ attributesMap.insert(map<string, int>::value_type((*r)->name(), attributes));
}
}
-
- if(!freezeWriteOpNames.empty())
+
+ if(!attributesMap.empty())
{
- freezeWriteOpNames.sort();
-
- StringList::iterator q;
-
- out << sp << nl << "private final static String[] __freezeWriteOperations =";
+ out << sp << nl << "private final static int[] __operationAttributes =";
out << sb;
- q = freezeWriteOpNames.begin();
- while(q != freezeWriteOpNames.end())
+
+ q = allOpNames.begin();
+ while(q != allOpNames.end())
{
- out << nl << '"' << *q << '"';
- if(++q != freezeWriteOpNames.end())
+ int attributes = 0;
+ string opName = *q;
+ map<string, int>::iterator it = attributesMap.find(opName);
+ if(it != attributesMap.end())
+ {
+ attributes = it->second;
+ }
+ out << nl << attributes;
+ if(++q != allOpNames.end())
{
out << ',';
}
- }
+ out << " // " << opName;
+ }
out << eb << ';';
- out << sp << nl << "public int ice_operationAttributes(String operation)";
+ out << sp << nl << "public int";
+ out << nl << "ice_operationAttributes(String operation)";
+ out << sb;
+ out << nl << "int pos = java.util.Arrays.binarySearch(__all, operation);";
+ out << nl << "if(pos < 0)";
out << sb;
- out << nl << "return (java.util.Arrays.binarySearch(__freezeWriteOperations, operation) >= 0) ? 1 : 0;";
+ out << nl << "return -1;";
+ out << eb;
+ out << sp << nl << "return __operationAttributes[pos];";
out << eb;
}
}