[asterisk-scf-commits] asterisk-scf/release/slice-plugins.git branch "master" updated.

Commits to the Asterisk SCF project code repositories asterisk-scf-commits at lists.digium.com
Fri Feb 18 17:42:55 CST 2011


branch "master" has been updated
       via  7fcd8cfe5cd559fe63d98ee97f1c801558149ded (commit)
       via  5c55b89822a31119ed1176b44a8cdf9bc75ba34b (commit)
       via  63c1f9b14e6c608f9da618b6807d9fa643a714da (commit)
      from  70181d456c77ca222ba1202fccfda7cbce2ab99f (commit)

Summary of changes:
 src/CMakeLists.txt              |    4 ++
 src/SliceClassMemberDefault.cpp |   88 +++++++++++++++++++++++++++++++++++++++
 2 files changed, 92 insertions(+), 0 deletions(-)
 create mode 100644 src/SliceClassMemberDefault.cpp


- Log -----------------------------------------------------------------
commit 7fcd8cfe5cd559fe63d98ee97f1c801558149ded
Author: Kevin P. Fleming <kpfleming at digium.com>
Date:   Fri Feb 18 17:42:47 2011 -0600

    And now it actually works.

diff --git a/src/SliceClassMemberDefault.cpp b/src/SliceClassMemberDefault.cpp
index c305092..69c0785 100644
--- a/src/SliceClassMemberDefault.cpp
+++ b/src/SliceClassMemberDefault.cpp
@@ -33,6 +33,7 @@ ClassMemberDefaultVisitor::visitDataMember(const DataMemberPtr& p)
 	{
 		return;
 	}
+
 	BuiltinPtr builtin = BuiltinPtr::dynamicCast(p->type());
 	if(builtin)
 	{
@@ -44,8 +45,10 @@ ClassMemberDefaultVisitor::visitDataMember(const DataMemberPtr& p)
 		case Builtin::KindLong:
 		case Builtin::KindFloat:
 		case Builtin::KindDouble:
+			p->setDefaultValue("0");
 			break;
 		case Builtin::KindBool:
+			p->setDefaultValue("false");
 			break;
 		default:
 			break;
@@ -53,11 +56,13 @@ ClassMemberDefaultVisitor::visitDataMember(const DataMemberPtr& p)
 
 		return;
 	}
+
 	EnumPtr enumtype = EnumPtr::dynamicCast(p->type());
 	if(enumtype)
 	{
 		EnumeratorPtr enumerator = enumtype->getEnumerators().front();
-		cout << "would set " << p->name() << " to " << enumerator->name() << endl;
+		p->setDefaultValue(enumerator->name());
+		return;
 	}
 }
 
@@ -69,7 +74,7 @@ extern "C"
 		VisitorList* result = new VisitorList();
 		switch(language)
 		{
-		case LanguagePython:
+		case LanguageCPlusPlus:
 			result->push_back(new ClassMemberDefaultVisitor());
 			break;
 		default:

commit 5c55b89822a31119ed1176b44a8cdf9bc75ba34b
Author: Kevin P. Fleming <kpfleming at digium.com>
Date:   Fri Feb 18 17:19:21 2011 -0600

    No need to handle data members with default values already provided.

diff --git a/src/SliceClassMemberDefault.cpp b/src/SliceClassMemberDefault.cpp
index 27a5749..c305092 100644
--- a/src/SliceClassMemberDefault.cpp
+++ b/src/SliceClassMemberDefault.cpp
@@ -29,6 +29,10 @@ public:
 void
 ClassMemberDefaultVisitor::visitDataMember(const DataMemberPtr& p)
 {
+	if(p->hasDefaultValue())
+	{
+		return;
+	}
 	BuiltinPtr builtin = BuiltinPtr::dynamicCast(p->type());
 	if(builtin)
 	{

commit 63c1f9b14e6c608f9da618b6807d9fa643a714da
Author: Kevin P. Fleming <kpfleming at digium.com>
Date:   Fri Feb 18 17:17:56 2011 -0600

    Initial code for a plugin to automagically provide default values for
    class/struct/exception members of non-class type when mapped into C++ (since
    C++ does not provide default values for such class members).

diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 788343c..5c759c6 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -1,3 +1,7 @@
 add_library(SliceVisitorPattern MODULE SliceVisitorPattern.cpp)
 target_link_libraries(SliceVisitorPattern ${ICE_ICEUTIL_LIBRARY} ${ICE_SLICE_LIBRARY})
 install(TARGETS SliceVisitorPattern LIBRARY DESTINATION "${SLICE_PLUGINS_DIR}" RUNTIME DESTINATION "${SLICE_PLUGINS_DIR}")
+
+add_library(SliceClassMemberDefault MODULE SliceClassMemberDefault.cpp)
+target_link_libraries(SliceClassMemberDefault ${ICE_ICEUTIL_LIBRARY} ${ICE_SLICE_LIBRARY})
+install(TARGETS SliceClassMemberDefault LIBRARY DESTINATION "${SLICE_PLUGINS_DIR}" RUNTIME DESTINATION "${SLICE_PLUGINS_DIR}")
diff --git a/src/SliceClassMemberDefault.cpp b/src/SliceClassMemberDefault.cpp
new file mode 100644
index 0000000..27a5749
--- /dev/null
+++ b/src/SliceClassMemberDefault.cpp
@@ -0,0 +1,79 @@
+/*
+ * SliceClassMemberDefault - a Slice translator plugin to supply
+ * default values for POD-type class members when needed.
+ *
+ * Copyright (C) 2011, Digium, Inc.
+ *
+ * This program is free software, distributed under the terms of
+ * the GNU General Public License Version 2. See the LICENSE.txt file
+ * at the top of the source tree.
+ */
+
+#include <Slice/Parser.h>
+#include <Slice/Util.h>
+#include <Slice/Plugin.h>
+#include <Slice/CPlusPlusUtil.h>
+#include <Slice/JavaUtil.h>
+#include <Slice/CsUtil.h>
+
+using namespace std;
+using namespace Slice;
+using namespace Slice::Plugin;
+
+class ICE_DECLSPEC_EXPORT ClassMemberDefaultVisitor : public ParserVisitor
+{
+public:
+	virtual void visitDataMember(const DataMemberPtr&);
+};
+
+void
+ClassMemberDefaultVisitor::visitDataMember(const DataMemberPtr& p)
+{
+	BuiltinPtr builtin = BuiltinPtr::dynamicCast(p->type());
+	if(builtin)
+	{
+		switch(builtin->kind())
+		{
+		case Builtin::KindByte:
+		case Builtin::KindShort:
+		case Builtin::KindInt:
+		case Builtin::KindLong:
+		case Builtin::KindFloat:
+		case Builtin::KindDouble:
+			break;
+		case Builtin::KindBool:
+			break;
+		default:
+			break;
+		}
+
+		return;
+	}
+	EnumPtr enumtype = EnumPtr::dynamicCast(p->type());
+	if(enumtype)
+	{
+		EnumeratorPtr enumerator = enumtype->getEnumerators().front();
+		cout << "would set " << p->name() << " to " << enumerator->name() << endl;
+	}
+}
+
+extern "C"
+{
+	ICE_DECLSPEC_EXPORT VisitorList*
+	create(Language language)
+	{
+		VisitorList* result = new VisitorList();
+		switch(language)
+		{
+		case LanguagePython:
+			result->push_back(new ClassMemberDefaultVisitor());
+			break;
+		default:
+			cerr << "SliceClassMemberDefault plugin does not support language " << language << "." << endl;
+			delete result;
+			result = 0;
+			break;
+		}
+		return result;
+	}
+}

-----------------------------------------------------------------------


-- 
asterisk-scf/release/slice-plugins.git



More information about the asterisk-scf-commits mailing list