[asterisk-scf-commits] asterisk-scf/release/ice.git branch "visitor-generators" updated.

Commits to the Asterisk SCF project code repositories asterisk-scf-commits at lists.digium.com
Mon Jan 3 13:29:26 UTC 2011


branch "visitor-generators" has been updated
       via  fa1f86fe0bf7a54b28ee87b1920adae595bf5186 (commit)
      from  b8b576837c74d551ee9f349014a18578a291ce30 (commit)

Summary of changes:
 cpp/include/Slice/VisitorPatternVisitor.h |    2 +-
 cpp/src/Slice/VisitorPatternVisitor.cpp   |   32 +++++++++++++++++-----------
 2 files changed, 20 insertions(+), 14 deletions(-)


- Log -----------------------------------------------------------------
commit fa1f86fe0bf7a54b28ee87b1920adae595bf5186
Author: Kevin P. Fleming <kpfleming at digium.com>
Date:   Mon Jan 3 07:28:29 2011 -0600

    Clean up logic that parses metadata and handles classes without metadata
    directives to close up some loopholes and ensure that derived visitor
    classes still work properly.

diff --git a/cpp/include/Slice/VisitorPatternVisitor.h b/cpp/include/Slice/VisitorPatternVisitor.h
index f8525b9..6251b06 100644
--- a/cpp/include/Slice/VisitorPatternVisitor.h
+++ b/cpp/include/Slice/VisitorPatternVisitor.h
@@ -14,7 +14,7 @@ protected:
     virtual StringList generateVisitFunctionBody(const std::string&, const ClassDefPtr&, const ClassDefPtr&, const std::string&) = 0;
 
 private:
-    std::map<std::string, ClassDefPtr> _visitorInterfaces;
+    std::map<std::string, ClassDefPtr> _visitorClasses;
     std::map<std::string, std::pair<ClassDefPtr, ClassDefPtr> > _visitableBases;
 };
 
diff --git a/cpp/src/Slice/VisitorPatternVisitor.cpp b/cpp/src/Slice/VisitorPatternVisitor.cpp
index d31682d..82ec11f 100644
--- a/cpp/src/Slice/VisitorPatternVisitor.cpp
+++ b/cpp/src/Slice/VisitorPatternVisitor.cpp
@@ -37,18 +37,20 @@ Slice::VisitorPatternVisitor::visitClassDefStart(const ClassDefPtr& p)
             if(!p->isLocal())
             {
                 ostr << "ignoring invalid metadata `visitor`: directive can only be applied "
-                     << "to local interfaces but `" << p->name() << "` is not local";
+                     << "to local classes but `" << p->name() << "` is not local";
                 emitWarning(p->file(), p->line(), ostr.str());
+                return false;
             }
             else if(p->isInterface())
             {
                 ostr << "ignoring invalid metadata `visitor`: directive can only be applied "
                      << "to local classes but `" << p->name() << "` is an interface";
                 emitWarning(p->file(), p->line(), ostr.str());
+                return false;
             }
             else
             {
-                _visitorInterfaces[p->scoped()] = p;
+                _visitorClasses[p->scoped()] = p;
                 return false;
             }
         }
@@ -59,31 +61,34 @@ Slice::VisitorPatternVisitor::visitClassDefStart(const ClassDefPtr& p)
                 ostr << "ignoring invalid `" << *q << "` metadata: directive can only be applied "
                      << "to classes, but `" << p->name() << "` is an interface";
                 emitWarning(p->file(), p->line(), ostr.str());
+                return false;
             }
             else if(p->isAbstract())
             {
                 ostr << "ignoring invalid `" << *q << "` metadata: directive can only be applied "
                      << "to concrete classes, but `" << p->name() << "` is abstract";
                 emitWarning(p->file(), p->line(), ostr.str());
+                return false;
             }
             else
             {
                 const string visitor = (*q).substr(8);
-                map<string, ClassDefPtr>::const_iterator it = _visitorInterfaces.find(visitor);
-                if(it != _visitorInterfaces.end())
+                map<string, ClassDefPtr>::const_iterator it = _visitorClasses.find(visitor);
+                if(it != _visitorClasses.end())
                 {
                     ClassDefPtr baseVisitor = it->second, derivedVisitor;
                     findVisitableBase(_visitableBases, p, baseVisitor, derivedVisitor);
-                    _visitableBases[p->scoped()] = make_pair(baseVisitor, it->second);
-                    if(it->second->includeLevel() == 0)
+                    derivedVisitor = it->second;
+                    _visitableBases[p->scoped()] = make_pair(baseVisitor, derivedVisitor);
+                    if(derivedVisitor->includeLevel() == 0)
                     {
-                        GeneratedOperationPtr gop = it->second->createGeneratedOperation("visit" + p->name(), 0, StringList());
+                        GeneratedOperationPtr gop = derivedVisitor->createGeneratedOperation("visit" + p->name(), 0, StringList());
                         gop->createParamDecl("item", p->declaration(), false);
                     }
                     if(p->includeLevel() == 0)
                     {
                         GeneratedOperationPtr gop = p->createGeneratedOperation("visit", 0,
-                                                                                generateVisitFunctionBody("visitor", baseVisitor, it->second, "visit" + p->name()));
+                                                                                generateVisitFunctionBody("visitor", baseVisitor, derivedVisitor, "visit" + p->name()));
                         gop->createParamDecl("visitor", baseVisitor->declaration(), false);
                     }
                     return false;
@@ -94,6 +99,7 @@ Slice::VisitorPatternVisitor::visitClassDefStart(const ClassDefPtr& p)
                          << "class `" << p->name() << "` but specified interface '" << visitor << "` was "
                          << "not marked with `visitor` metadata directive";
                     emitWarning(p->file(), p->line(), ostr.str());
+                    return false;
                 }
             }
         }
@@ -116,19 +122,19 @@ Slice::VisitorPatternVisitor::visitClassDefStart(const ClassDefPtr& p)
                                                                         generateVisitFunctionBody("visitor", baseVisitor, derivedVisitor, "visit" + p->name()));
                 gop->createParamDecl("visitor", baseVisitor->declaration(), false);
             }
-            return false;
         }
+        return false;
     }
 
-    if(p->isInterface())
+    if(!p->isInterface())
     {
         ClassList bases = p->allBases();
         for(ClassList::const_iterator q = bases.begin(); q != bases.end(); q++)
         {
-            map<string, ClassDefPtr>::const_iterator it = _visitorInterfaces.find((*q)->scoped());
-            if(it != _visitorInterfaces.end())
+            map<string, ClassDefPtr>::const_iterator it = _visitorClasses.find((*q)->scoped());
+            if(it != _visitorClasses.end())
             {
-                _visitorInterfaces[p->scoped()] = p;
+                _visitorClasses[p->scoped()] = p;
                 return false;
             }
         }

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


-- 
asterisk-scf/release/ice.git



More information about the asterisk-scf-commits mailing list