gnash-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Gnash-commit] /srv/bzr/gnash/trunk r11201: Do namespace importing and c


From: Benjamin Wolsey
Subject: [Gnash-commit] /srv/bzr/gnash/trunk r11201: Do namespace importing and class lookup properly.
Date: Fri, 03 Jul 2009 10:52:04 +0200
User-agent: Bazaar (1.13.1)

------------------------------------------------------------
revno: 11201
committer: Benjamin Wolsey <address@hidden>
branch nick: trunk
timestamp: Fri 2009-07-03 10:52:04 +0200
message:
  Do namespace importing and class lookup properly.
renamed:
  libcore/parser/abc_block.cpp => libcore/parser/AbcBlock.cpp
  libcore/parser/abc_block.h => libcore/parser/AbcBlock.h
modified:
  libcore/asClass.h
  libcore/asNamespace.cpp
  libcore/parser/Makefile.am
  libcore/swf/DoABCTag.h
  libcore/vm/Machine.cpp
  libcore/vm/Machine.h
  libcore/parser/AbcBlock.cpp
  libcore/parser/AbcBlock.h
    ------------------------------------------------------------
    revno: 11200.1.1
    committer: Benjamin Wolsey <address@hidden>
    branch nick: work
    timestamp: Fri 2009-07-03 07:14:37 +0200
    message:
      Use abc block string pool for logging to make errors clearer.
    modified:
      libcore/parser/abc_block.cpp
    ------------------------------------------------------------
    revno: 11200.1.2
    committer: Benjamin Wolsey <address@hidden>
    branch nick: work
    timestamp: Fri 2009-07-03 07:15:25 +0200
    message:
      Move locateClass functions together.
    modified:
      libcore/parser/abc_block.cpp
    ------------------------------------------------------------
    revno: 11200.1.3
    committer: Benjamin Wolsey <address@hidden>
    branch nick: work
    timestamp: Fri 2009-07-03 09:49:03 +0200
    message:
      Always use global, not ABC names, for classes. Lookup package (currently
      all non-private) namespaces using the global name, which has the effect
      of "importing" external namespaces into the ABC block.
      
      This makes it possible to look up classes only using the ABC block's 
      resources. It also prevents potential name conflicts when adding classes 
to
      existing namespaces and makes it easier to locate classes using a global
      name.
    modified:
      libcore/asNamespace.cpp
      libcore/parser/abc_block.cpp
      libcore/vm/Machine.cpp
    ------------------------------------------------------------
    revno: 11200.1.4
    committer: Benjamin Wolsey <address@hidden>
    branch nick: work
    timestamp: Fri 2009-07-03 10:04:44 +0200
    message:
      Add some class documentation to abc_block.
    modified:
      libcore/parser/abc_block.h
    ------------------------------------------------------------
    revno: 11200.1.5
    committer: Benjamin Wolsey <address@hidden>
    branch nick: work
    timestamp: Fri 2009-07-03 10:19:37 +0200
    message:
      Rename abc_block to AbcBlock.
    renamed:
      libcore/parser/abc_block.cpp => libcore/parser/AbcBlock.cpp
      libcore/parser/abc_block.h => libcore/parser/AbcBlock.h
    modified:
      libcore/asClass.h
      libcore/parser/Makefile.am
      libcore/swf/DoABCTag.h
      libcore/vm/Machine.cpp
      libcore/vm/Machine.h
      libcore/parser/AbcBlock.cpp
      libcore/parser/AbcBlock.h
=== modified file 'libcore/asClass.h'
--- a/libcore/asClass.h 2009-06-29 09:42:53 +0000
+++ b/libcore/asClass.h 2009-07-03 08:19:37 +0000
@@ -33,7 +33,7 @@
 
 #ifdef ENABLE_AVM2
 # include "CodeStream.h"
-# include "abc_block.h"
+# include "AbcBlock.h"
 #endif
 
 namespace gnash {

=== modified file 'libcore/asNamespace.cpp'
--- a/libcore/asNamespace.cpp   2009-07-02 19:24:12 +0000
+++ b/libcore/asNamespace.cpp   2009-07-03 07:49:03 +0000
@@ -47,10 +47,11 @@
             i != e; ++i)
     {
         const string_table::key t = i->second->getName();
-        s << st.value(t) << "(" << t << "), ";
+        s << st.value(t) << "(URI: " << t << "), ";
     }
 
-    log_debug("Classes in namespace %s(%s): %s", st.value(_uri), _uri, 
s.str());
+    log_debug("Classes in namespace %s (URI: %s, ABC: %s): %s",
+            st.value(_uri), _uri, _abcURI, s.str());
 #endif
 }
 

=== renamed file 'libcore/parser/abc_block.cpp' => 'libcore/parser/AbcBlock.cpp'
--- a/libcore/parser/abc_block.cpp      2009-07-02 13:48:42 +0000
+++ b/libcore/parser/AbcBlock.cpp       2009-07-03 08:19:37 +0000
@@ -19,7 +19,7 @@
 //
 
 #include "gnashconfig.h"
-#include "abc_block.h"
+#include "AbcBlock.h"
 #include "SWFStream.h" // for use
 #include "VM.h"
 #include "log.h"
@@ -36,10 +36,10 @@
 namespace abc {
 
 bool
-Trait::finalize(abc_block *pBlock, asClass *pClass, bool do_static)
+Trait::finalize(AbcBlock *pBlock, asClass *pClass, bool do_static)
 {
        log_abc("Finalize class %s (%s), trait kind: %s", 
-            pBlock->_stringPool[pClass->getName()], pClass, _kind);
+            pBlock->_stringTable->value(pClass->getName()), pClass, _kind);
 
        switch (_kind)
        {
@@ -115,7 +115,7 @@
 }
 
 bool
-Trait::finalize_mbody(abc_block *pBlock, asMethod *pMethod)
+Trait::finalize_mbody(AbcBlock *pBlock, asMethod *pMethod)
 {
        log_abc("Finalizing method trait: kind %s", _kind);
        switch (_kind)
@@ -183,7 +183,7 @@
 
 /// Read an AS3 'trait'
 bool
-Trait::read(SWFStream* in, abc_block *pBlock)
+Trait::read(SWFStream* in, AbcBlock *pBlock)
 {
        boost::uint32_t name = in->read_V32();
        if (name >= pBlock->_multinamePool.size())
@@ -220,8 +220,8 @@
                     pBlock->_multinamePool[_typeIndex].getABCName()], vindex);
             
             if (vindex) {
-                const abc_block::PoolConstant c =
-                    static_cast<abc_block::PoolConstant>(in->read_u8());
+                const AbcBlock::PoolConstant c =
+                    static_cast<AbcBlock::PoolConstant>(in->read_u8());
 
                 if (!pBlock->pool_value(vindex, c, _value))
                     return false; // Message done by pool_value
@@ -251,9 +251,9 @@
             _slotID = in->read_V32();
             _classInfoIndex = in->read_V32();
             log_abc("Slot id: %u Class index: %u Class Name: %s", _slotID, 
-                    _classInfoIndex, 
-                    pBlock->_stringPool[pBlock->
-                            _classes[_classInfoIndex]->getName()]);
+                _classInfoIndex, 
+                pBlock->_stringTable->value(
+                    pBlock->_classes[_classInfoIndex]->getName()));
 
             if (_classInfoIndex >= pBlock->_classes.size()) {
                 log_error(_("Bad Class id in trait."));
@@ -318,7 +318,7 @@
 
 using namespace abc;
 
-abc_block::abc_block()
+AbcBlock::AbcBlock()
     :
     _stringTable(&VM::get().getStringTable())
 {
@@ -329,7 +329,7 @@
 }
 
 void
-abc_block::prepare(Machine* mach)
+AbcBlock::prepare(Machine* mach)
 {
 
     std::for_each(_classes.begin(), _classes.end(),
@@ -358,7 +358,7 @@
 }
 
 void
-abc_block::check_multiname_name(boost::uint32_t name)
+AbcBlock::check_multiname_name(boost::uint32_t name)
 {
 
        if (name >= _stringPool.size()) {
@@ -367,7 +367,7 @@
 }
 
 void
-abc_block::check_multiname_namespace(boost::uint32_t ns)
+AbcBlock::check_multiname_namespace(boost::uint32_t ns)
 {
        if (ns >= _namespacePool.size()) {
                throw ParserException("ABC: Out of bounds namespace for 
Multiname.");
@@ -375,7 +375,7 @@
 }
 
 void
-abc_block::check_multiname_namespaceset(boost::uint32_t nsset)
+AbcBlock::check_multiname_namespaceset(boost::uint32_t nsset)
 {
        if (!nsset)
     {
@@ -388,7 +388,7 @@
 }
 
 void
-abc_block::setMultinameNames(asName *n, string_table::key ABCName)
+AbcBlock::setMultinameNames(asName *n, string_table::key ABCName)
 {
        
        n->setABCName(ABCName);
@@ -401,7 +401,7 @@
 }
 
 void
-abc_block::setNamespaceURI(asNamespace *ns, string_table::key ABCName)
+AbcBlock::setNamespaceURI(asNamespace *ns, string_table::key ABCName)
 {
        ns->setAbcURI(ABCName);
        std::string name = _stringPool[ABCName];
@@ -410,14 +410,42 @@
        log_abc("Namespace: %s AbcURI=%u URI=%u.", name, ABCName, global_key);
 }
 
-asClass *
-abc_block::locateClass(asName& m)
+asClass*
+AbcBlock::locateClass(const std::string& className)
+{
+
+    const std::string::size_type pos = className.rfind(".");
+    
+    asName a;
+
+    const std::string& nsstr = (pos != std::string::npos) ? 
+        className.substr(0, pos) : "";
+
+    const std::string& clstr = (pos != std::string::npos) ? 
+        className.substr(pos + 1) : className;
+    
+    a.setGlobalName(_stringTable->find(clstr));
+
+    for (std::vector<asNamespace*>::iterator i = _namespacePool.begin();
+            i != _namespacePool.end(); ++i) {
+        if (_stringPool[(*i)->getAbcURI()] == nsstr) {
+            a.setNamespace(*i);
+            break;
+        }
+    }
+    
+    return locateClass(a);
+
+}
+
+asClass*
+AbcBlock::locateClass(asName& m)
 {
        asClass* found = 0;
 
        if (m.getNamespace())
        {
-               found = m.getNamespace()->getClass(m.getABCName());
+               found = m.getNamespace()->getClass(m.getGlobalName());
                if (found) return found;
        }
        if (m.namespaceSet() && !m.namespaceSet()->empty())
@@ -425,32 +453,20 @@
                std::vector<asNamespace*>::const_iterator i;
                for (i = m.namespaceSet()->begin(); i != 
m.namespaceSet()->end(); ++i) {
 
-                       found = (*i)->getClass(m.getABCName());
+                       found = (*i)->getClass(m.getGlobalName());
                        if (found) return found;
                }
        }
 
-    log_abc("Failed to locate class in ABC block, looking in Global");
-
-    // Look in known built-in classes.
-    asNamespace* nsToFind = m.getNamespace();
-
-    // If there is no namespace specified, look in global only.
-    // TODO: check if this is correct, or if there should always be
-    // a namespace.
-    if (!nsToFind) {
-        return mCH->getGlobalNs()->getClass(m.getGlobalName());
-    }
-
-    // Else look in the specified namespace only.
-    asNamespace* ns = mCH->findNamespace(nsToFind->getURI());
-    return ns ? ns->getClass(m.getGlobalName()) : 0;
+    log_abc("Could not locate class in ABC block resources!");
+
+    return 0;
 
 }
 
 /// Read the ActionBlock version number.
 bool
-abc_block::read_version()
+AbcBlock::read_version()
 {
        // Minor version, major version.
        mVersion = (_stream->read_u16()) | (_stream->read_u16() << 16);
@@ -461,7 +477,7 @@
 
 /// Read the pool of integer constants.
 bool
-abc_block::read_integer_constants()
+AbcBlock::read_integer_constants()
 {
        // count overestimates by 1.
        boost::uint32_t count = _stream->read_V32();
@@ -477,7 +493,7 @@
 
 /// Read the pool of unsigned integer constants.
 bool
-abc_block::read_unsigned_integer_constants()
+AbcBlock::read_unsigned_integer_constants()
 {
        // count overestimates by 1.
        boost::uint32_t count = _stream->read_V32();
@@ -493,7 +509,7 @@
 
 /// Read the pool of 64-bit double constants.
 bool
-abc_block::read_double_constants()
+AbcBlock::read_double_constants()
 {
        boost::uint32_t count = _stream->read_V32();
        _doublePool.resize(count);
@@ -509,7 +525,7 @@
 
 /// Read the pool of string constants.
 bool
-abc_block::read_string_constants()
+AbcBlock::read_string_constants()
 {
        log_abc("Begin reading string constants.");
        boost::uint32_t count = _stream->read_V32();
@@ -535,7 +551,7 @@
 /// Any two namespaces with the same uri here are the same namespace, 
 /// excepting private namespaces.
 bool
-abc_block::read_namespaces()
+AbcBlock::read_namespaces()
 {      
        log_abc("Begin reading namespaces.");
        boost::uint32_t count = _stream->read_V32();
@@ -566,8 +582,9 @@
                }
                else
                {
-                       asNamespace *n = mCH->findNamespace(nameIndex);
-                       if (!n) n = mCH->addNamespace(nameIndex);
+            string_table::key gn = _stringTable->find(_stringPool[nameIndex]);
+                       asNamespace *n = mCH->findNamespace(gn);
+                       if (!n) n = mCH->addNamespace(gn);
                        _namespacePool[i] = n;
                }
                if (kind == PROTECTED_NS) _namespacePool[i]->setProtected();
@@ -579,7 +596,7 @@
 
 /// Read the set of sets of namespaces.
 bool
-abc_block::read_namespace_sets()
+AbcBlock::read_namespace_sets()
 {
        boost::uint32_t count = _stream->read_V32();
        _namespaceSetPool.resize(count);
@@ -607,7 +624,7 @@
 
 /// Read the multinames.
 bool
-abc_block::read_multinames()
+AbcBlock::read_multinames()
 {
        boost::uint32_t count = _stream->read_V32();
        log_abc("There are %u multinames.", count);
@@ -687,7 +704,7 @@
 }
 
 bool
-abc_block::pool_value(boost::uint32_t index, PoolConstant type, as_value &v)
+AbcBlock::pool_value(boost::uint32_t index, PoolConstant type, as_value &v)
 {
        if (!index)
                return true;
@@ -771,7 +788,7 @@
 
 /// Read the method infos.
 bool
-abc_block::read_method_infos()
+AbcBlock::read_method_infos()
 {
        log_abc("Begin read_method_infos.");
 
@@ -898,7 +915,7 @@
 
 /// Skip the metadata, which is useless to us.
 bool
-abc_block::skip_metadata()
+AbcBlock::skip_metadata()
 {
        boost::uint32_t count = _stream->read_V32();
        for (unsigned int i = 0; i < count; ++i)
@@ -917,7 +934,7 @@
 
 /// Load the instances from the block.
 bool
-abc_block::read_instances()
+AbcBlock::read_instances()
 {
        boost::uint32_t count = _stream->read_V32();
        log_abc("There are %u instances.", count);
@@ -949,16 +966,23 @@
                
         if (!pClass) {
 
-            // Shouldn't this be the global name?
-            const string_table::key className = multiname.getABCName();
+            const string_table::key className = multiname.getGlobalName();
 
                        pClass = mCH->newClass();
+            pClass->setName(className);
 
                        if (!multiname.getNamespace()->addClass(className, 
pClass)) {
 
                                log_error(_("Duplicate class registration."));
                                return false;
                        }
+            log_debug("Adding class %s (%s) to namespace %s",
+                    _stringTable->value(multiname.getGlobalName()),
+                    _stringPool[multiname.getABCName()],
+                    _stringTable->value(multiname.getNamespace()->getURI()));
+            log_debug("Namespace now:");
+            multiname.getNamespace()->dump(*_stringTable);
+
                }
                pClass->setDeclared();
                _classes[i] = pClass;
@@ -976,9 +1000,8 @@
                        asClass *pSuper = 
locateClass(_multinamePool[super_index]);
                        if (!pSuper)
                        {
-                               log_error(_("ABC: Super type not found (%s), 
faking."), 
-                                       _stringTable->value(
-                        _multinamePool[super_index].getGlobalName()));
+                               log_error(_("ABC: Super type not found (%s)"), 
+                                       
_stringPool[_multinamePool[super_index].getABCName()]);
                            return false;
             }
 
@@ -1082,7 +1105,7 @@
 
 /// Read the class data
 bool
-abc_block::read_classes()
+AbcBlock::read_classes()
 {
        // Count was found in read_instances().
        log_abc("Begin reading classes.");
@@ -1122,7 +1145,7 @@
 /// Read the scripts (global functions)
 /// The final script is the entry point for the block.
 bool
-abc_block::read_scripts()
+AbcBlock::read_scripts()
 {
        log_abc("Begin reading scripts.");
        boost::uint32_t count = _stream->read_V32();
@@ -1172,7 +1195,7 @@
 
 /// Read the method bodies and attach them to the methods.
 bool
-abc_block::read_method_bodies()
+AbcBlock::read_method_bodies()
 {
        boost::uint32_t count = _stream->read_V32();
        log_abc("There are %u method bodies.", count);
@@ -1289,7 +1312,7 @@
 
 // Load up all of the data.
 bool
-abc_block::read(SWFStream& in)
+AbcBlock::read(SWFStream& in)
 {
     // This isn't very nice:
        _stream = &in;
@@ -1351,56 +1374,9 @@
        return true;
 }
 
-asClass*
-abc_block::locateClass(const std::string& className)
-{
-
-    // TODO: this is rubbish and should be done properly. Machine.cpp also
-    // has completeName for runtime names, so should probably use common
-    // code (construction of asName?).
-
-    const std::string::size_type pos = className.rfind(".");
-    
-    asName a;
-
-    if (pos != std::string::npos) {
-        const std::string& nsstr = className.substr(0, pos);
-        const std::string& clstr = className.substr(pos + 1);
-        std::vector<std::string>::iterator it = 
-            std::find(_stringPool.begin(), _stringPool.end(), clstr);
-
-        if (it == _stringPool.end()) return 0;
-        for (std::vector<asNamespace*>::iterator i = _namespacePool.begin();
-                i != _namespacePool.end(); ++i) {
-            if (_stringPool[(*i)->getAbcURI()] == nsstr) {
-                a.setNamespace(*i);
-                break;
-            }
-        }
-        a.setABCName(it - _stringPool.begin());
-    }
-    else {
-        std::vector<std::string>::iterator it = 
-            std::find(_stringPool.begin(), _stringPool.end(), className);
- 
-#if 1      
-        if (it == _stringPool.end()) return 0;
-        a.setABCName(it - _stringPool.begin());
-#else
-
-        if (it != _stringPool.end()) {
-            a.setABCName(it - _stringPool.begin());
-        }
-        a.setGlobalName(VM::get().getStringTable().find(className));
-#endif
-    }
-    
-    return locateClass(a);
-
-}
 
 void
-abc_block::update_global_name(unsigned int multiname_index)
+AbcBlock::update_global_name(unsigned int multiname_index)
 {
        
        asName* multiname = &_multinamePool[multiname_index];
@@ -1410,23 +1386,23 @@
 }
 
 std::ostream&
-operator<<(std::ostream& o, abc_block::NamespaceConstant c)
+operator<<(std::ostream& o, AbcBlock::NamespaceConstant c)
 {
     switch (c)
     {
-        case abc_block::PRIVATE_NS:
+        case AbcBlock::PRIVATE_NS:
             return o << "private namespace";
-        case abc_block::CONSTANT_NS:
+        case AbcBlock::CONSTANT_NS:
             return o << "constant namespace";
-        case abc_block::PACKAGE_NS:
+        case AbcBlock::PACKAGE_NS:
             return o << "package namespace";
-        case abc_block::PACKAGE_INTERNAL_NS:
+        case AbcBlock::PACKAGE_INTERNAL_NS:
             return o << "package internal namespace";
-        case abc_block::PROTECTED_NS:
+        case AbcBlock::PROTECTED_NS:
             return o << "protected namespace";
-        case abc_block::EXPLICIT_NS:
+        case AbcBlock::EXPLICIT_NS:
             return o << "explicit namespace";
-        case abc_block::STATIC_PROTECTED_NS:
+        case AbcBlock::STATIC_PROTECTED_NS:
             return o << "static protected namespace";
         default:
             return o << "invalid namespace constant";
@@ -1434,25 +1410,25 @@
 }
 
 std::ostream&
-operator<<(std::ostream& o, abc_block::MethodConstant c)
+operator<<(std::ostream& o, AbcBlock::MethodConstant c)
 {
     switch (c)
     {
-        case abc_block::METHOD_ARGS:
+        case AbcBlock::METHOD_ARGS:
             return o << "method arg";
-        case abc_block::METHOD_ACTIVATION:
+        case AbcBlock::METHOD_ACTIVATION:
             return o << "method activation";
-        case abc_block::METHOD_MORE:
+        case AbcBlock::METHOD_MORE:
             return o << "method more";
-        case abc_block::METHOD_OPTIONAL_ARGS:
+        case AbcBlock::METHOD_OPTIONAL_ARGS:
             return o << "method optional args";
-        case abc_block::METHOD_IGNORE:
+        case AbcBlock::METHOD_IGNORE:
             return o << "method ignore";
-        case abc_block::METHOD_NATIVE:
+        case AbcBlock::METHOD_NATIVE:
             return o << "method native";
-        case abc_block::METHOD_DEFAULT_NS:
+        case AbcBlock::METHOD_DEFAULT_NS:
             return o << "default namespace";
-        case abc_block::METHOD_ARG_NAMES:
+        case AbcBlock::METHOD_ARG_NAMES:
             return o << "method arg names";
         default:
             return o << "invalid method constant";
@@ -1460,19 +1436,19 @@
 }
 
 std::ostream&
-operator<<(std::ostream& o, abc_block::InstanceConstant c)
+operator<<(std::ostream& o, AbcBlock::InstanceConstant c)
 {
     switch (c)
     {
-        case abc_block::INSTANCE_SEALED:
+        case AbcBlock::INSTANCE_SEALED:
             return o << "instance sealed";
-        case abc_block::INSTANCE_FINAL:
+        case AbcBlock::INSTANCE_FINAL:
             return o << "instance final";
-        case abc_block::INSTANCE_INTERFACE:
+        case AbcBlock::INSTANCE_INTERFACE:
             return o << "instance interface";
-        case abc_block::INSTANCE_DYNAMIC:
+        case AbcBlock::INSTANCE_DYNAMIC:
             return o << "instance dynamic";
-        case abc_block::INSTANCE_PROTECTED_NS:
+        case AbcBlock::INSTANCE_PROTECTED_NS:
             return o << "instance protected namespace";
         default:
             return o << "invalid instance constant";
@@ -1480,25 +1456,25 @@
 }
 
 std::ostream&
-operator<<(std::ostream& o, abc_block::PoolConstant c)
+operator<<(std::ostream& o, AbcBlock::PoolConstant c)
 {
     switch (c)
     {
-        case abc_block::POOL_STRING:
+        case AbcBlock::POOL_STRING:
             return o << "pool string";
-        case abc_block::POOL_INTEGER:
+        case AbcBlock::POOL_INTEGER:
             return o << "pool integer";
-        case abc_block::POOL_UINTEGER:
+        case AbcBlock::POOL_UINTEGER:
             return o << "pool uinteger";
-        case abc_block::POOL_DOUBLE:
+        case AbcBlock::POOL_DOUBLE:
             return o << "pool double";
-        case abc_block::POOL_NAMESPACE:
+        case AbcBlock::POOL_NAMESPACE:
             return o << "pool namespace";
-        case abc_block::POOL_FALSE:
+        case AbcBlock::POOL_FALSE:
             return o << "pool false";
-        case abc_block::POOL_TRUE:
+        case AbcBlock::POOL_TRUE:
             return o << "pool true";
-        case abc_block::POOL_NULL:
+        case AbcBlock::POOL_NULL:
             return o << "pool null";
         default:
             return o << "invalid pool constant";

=== renamed file 'libcore/parser/abc_block.h' => 'libcore/parser/AbcBlock.h'
--- a/libcore/parser/abc_block.h        2009-07-02 13:05:53 +0000
+++ b/libcore/parser/AbcBlock.h 2009-07-03 08:19:37 +0000
@@ -37,7 +37,7 @@
 
 namespace gnash {
 
-class abc_block;
+class AbcBlock;
 class ClassHierarchy;
 class asMethod;
 class asClass;
@@ -94,11 +94,11 @@
         _static(false)
        {}
 
-       bool read(SWFStream* in, abc_block *pBlock);
-
-       bool finalize(abc_block* pBlock, asClass* pClass, bool do_static);
-
-       bool finalize_mbody(abc_block* pBlock, asMethod* pMethod);
+       bool read(SWFStream* in, AbcBlock *pBlock);
+
+       bool finalize(AbcBlock* pBlock, asClass* pClass, bool do_static);
+
+       bool finalize_mbody(AbcBlock* pBlock, asMethod* pMethod);
 
        void set_target(asClass* pClass, bool do_static) {
         _classTarget = pClass;
@@ -110,7 +110,7 @@
         _methodTarget = pMethod;
     }
 
-       bool finalize(abc_block* pBlock)
+       bool finalize(AbcBlock* pBlock)
        {
                if (_classTarget) {
                        return finalize(pBlock, _classTarget, _static);
@@ -136,7 +136,47 @@
 
 }
 
-class abc_block
+/// ABC blocks have their own "names" for all resources. In Gnash, these are
+/// a string table index. They are different from global names. These are used
+/// to locate resources inside the ABC block.
+// 
+/// Namespaces
+//
+/// ABC blocks have a set of "namespace" resources. Some namespaces are
+/// private. We make these into anonymous namespaces.
+// 
+/// We assume all non-private namespaces are public. Some are "package"
+/// namespaces; these seem to coincide with the built-in packages or 0,
+/// the global namespace.
+/// 
+/// We always search for these public namespaces by global URI in our
+/// ClassHierarchy. If we use ABC names, "flash.text" will not find the 
built-in
+/// flash.text namespace. Using the global name means that we 'import' the
+/// built-in namespace into our own resources.
+//
+/// Instances / Classes 
+//
+/// Likewise, classes are always given a global name, not an ABC name. This is
+/// because they become globally available, including (we assume) to other ABC
+/// blocks, so using an ABC name means they cannot be located externally.
+/// Even if ABC block resources should not be available to other blocks (which
+/// seems unlikely), using an ABC name for classes risks name conflicts with
+/// the built-in classes already in a namespace: ABC names and global names
+/// can have the same index even when the names are different.
+//
+/// Class lookup
+//
+/// This is particularly important for locateClass (called by instantiateClass
+/// from SymbolClass tag execution). The SymbolClass tag identifies a class
+/// using a global name, which may be qualified with a namespace. If it is
+/// not qualified, we look in the global namespace 0.
+// 
+/// When we call locateClass, we use global names, not ABC names, because
+/// classes are identified by global names (see above). However, we
+/// still look only in the ABC block's namespaces. The block's first namespace
+/// is always the global namespace; other package namespaces are imported
+/// according to the block's namespace constants.
+class AbcBlock
 {
 public:
     
@@ -186,7 +226,7 @@
     
     typedef std::vector<asNamespace*> NamespaceSet;
 
-       abc_block();
+       AbcBlock();
 
     asClass* locateClass(asName &m);
 
@@ -304,10 +344,10 @@
 
 };
 
-std::ostream& operator<<(std::ostream& o, abc_block::NamespaceConstant c);
-std::ostream& operator<<(std::ostream& o, abc_block::MethodConstant c);
-std::ostream& operator<<(std::ostream& o, abc_block::InstanceConstant c);
-std::ostream& operator<<(std::ostream& o, abc_block::PoolConstant c);
+std::ostream& operator<<(std::ostream& o, AbcBlock::NamespaceConstant c);
+std::ostream& operator<<(std::ostream& o, AbcBlock::MethodConstant c);
+std::ostream& operator<<(std::ostream& o, AbcBlock::InstanceConstant c);
+std::ostream& operator<<(std::ostream& o, AbcBlock::PoolConstant c);
 
 } 
 

=== modified file 'libcore/parser/Makefile.am'
--- a/libcore/parser/Makefile.am        2009-06-30 09:13:40 +0000
+++ b/libcore/parser/Makefile.am        2009-07-03 08:19:37 +0000
@@ -55,7 +55,7 @@
 
 if ENABLE_AVM2
 libgnashparser_la_SOURCES += \
-       abc_block.cpp
+       AbcBlock.cpp
 endif
 
 noinst_HEADERS = \
@@ -69,7 +69,7 @@
 
 if ENABLE_AVM2
 noinst_HEADERS += \
-       abc_block.h
+       AbcBlock.h
 endif
 
 EXTENSIONS_API = \

=== modified file 'libcore/swf/DoABCTag.h'
--- a/libcore/swf/DoABCTag.h    2009-07-01 15:51:21 +0000
+++ b/libcore/swf/DoABCTag.h    2009-07-03 08:19:37 +0000
@@ -23,7 +23,7 @@
 #include "action_buffer.h" // for composition
 #include "MovieClip.h" // for inlines
 #include "SWFStream.h" // for inlines
-#include "abc_block.h"
+#include "AbcBlock.h"
 #include "Machine.h"
 #include "VM.h"
 
@@ -57,7 +57,7 @@
                
         _abc->prepare(mach);
 
-               log_debug("Begin execute abc_block.");
+               log_debug("Begin execute AbcBlock.");
                mach->initMachine(_abc);
                log_debug("Executing machine...");
                mach->execute();
@@ -92,7 +92,7 @@
                        in.read_string(name);
                }
 
-        std::auto_ptr<abc_block> block(new abc_block());
+        std::auto_ptr<AbcBlock> block(new AbcBlock());
                if (!block->read(in)) {
             log_error("ABC parsing error while processing DoABCTag. This "
                     "tag will never be executed");
@@ -112,9 +112,9 @@
 
 private:
 
-       DoABCTag(abc_block* block) : _abc(block) {}
+       DoABCTag(AbcBlock* block) : _abc(block) {}
 
-       abc_block* _abc;
+       AbcBlock* _abc;
        
 };
 

=== modified file 'libcore/vm/Machine.cpp'
--- a/libcore/vm/Machine.cpp    2009-07-02 07:39:11 +0000
+++ b/libcore/vm/Machine.cpp    2009-07-03 08:19:37 +0000
@@ -22,7 +22,7 @@
 #include "ClassHierarchy.h"
 #include "namedStrings.h"
 #include "Array_as.h"
-#include "abc_block.h"
+#include "AbcBlock.h"
 #include "fn_call.h"
 #include "abc_function.h"
 #include "action.h"
@@ -63,7 +63,7 @@
 namespace {
 
 inline const std::string&
-pool_string(boost::uint32_t index, abc_block *pool)
+pool_string(boost::uint32_t index, AbcBlock *pool)
 {
        if (!pool) throw ASException();
     try {
@@ -75,7 +75,7 @@
 }
 
 inline int
-pool_int(boost::uint32_t index, abc_block *pool)
+pool_int(boost::uint32_t index, AbcBlock *pool)
 {
        if (!pool) throw ASException();
     try {
@@ -87,7 +87,7 @@
 }
 
 inline unsigned int
-pool_uint(boost::uint32_t index, abc_block *pool)
+pool_uint(boost::uint32_t index, AbcBlock *pool)
 {
        if (!pool) throw ASException();
     try {
@@ -99,7 +99,7 @@
 }
 
 inline double
-pool_double(boost::uint32_t index, abc_block *pool)
+pool_double(boost::uint32_t index, AbcBlock *pool)
 {
        if (!pool) throw ASException();
     try {
@@ -111,7 +111,7 @@
 }
 
 inline asNamespace*
-pool_namespace(boost::uint32_t index, abc_block *pool)
+pool_namespace(boost::uint32_t index, AbcBlock *pool)
 {
        if (!pool) throw ASException();
     try {
@@ -124,7 +124,7 @@
 }
 
 inline asMethod*
-pool_method(boost::uint32_t index, abc_block* pool)
+pool_method(boost::uint32_t index, AbcBlock* pool)
 {
        if (!pool) throw ASException();
     try {
@@ -136,7 +136,7 @@
 }
 
 inline asClass*
-pool_class(boost::uint32_t index, abc_block* pool)
+pool_class(boost::uint32_t index, AbcBlock* pool)
 {
        if (!pool) throw ASException();
     try {
@@ -149,7 +149,7 @@
 
 // Don't make this a reference or you'll taint the pool.
 inline asName
-pool_name(boost::uint32_t index, abc_block* pool)
+pool_name(boost::uint32_t index, AbcBlock* pool)
 {
        if (!pool) throw ASException();
        try {
@@ -1668,9 +1668,10 @@
                 case SWF::ABC_ACTION_NEWCLASS:
                 {
                     boost::uint32_t cid = mStream->read_V32();
+                    log_abc("Class index: %s", cid);
                     asClass *c = pool_class(cid, mPoolObject);
                     log_abc("Creating new class id=%u name=%s", c->getName(),
-                            pool_string(c->getName(), mPoolObject));
+                            mST.value(c->getName()));
                     
                     as_object* base_class = pop_stack().to_object().get();
                     as_object* new_class = c->getPrototype();
@@ -1703,7 +1704,7 @@
                             get_args(0));
 
                     log_abc("NEWCLASS(%2%) finished. Return: %1%", value,
-                            pool_string(c->getName(), mPoolObject));
+                            mST.value(c->getName()));
 
                     break;
                 }
@@ -2075,7 +2076,7 @@
 
                     // We use sindex + 1, because currently as_object sets
                     // a property at a slot index 1 higher than the
-                    // index the abc_block thinks the property is at.
+                    // index the AbcBlock thinks the property is at.
                     if ( ! obj->set_member_slot(sindex+1, value) )
                     {
                         log_abc("Failed to set property at "
@@ -3102,7 +3103,7 @@
 }
 
 void
-Machine::initMachine(abc_block* pool_block)
+Machine::initMachine(AbcBlock* pool_block)
 {
        mPoolObject = pool_block;
        log_debug("Getting entry script.");

=== modified file 'libcore/vm/Machine.h'
--- a/libcore/vm/Machine.h      2009-07-01 16:15:52 +0000
+++ b/libcore/vm/Machine.h      2009-07-03 08:19:37 +0000
@@ -32,7 +32,7 @@
 namespace gnash {
     class DisplayObject;
     class as_object;
-    class abc_block;
+    class AbcBlock;
     class asName;
     class Property;
     class CodeStream;
@@ -212,7 +212,7 @@
         immediateFunction(to_call, pthis, mIgnoreReturn, stack_in, stack_out);
     }
 
-       void initMachine(abc_block* pool_block);
+       void initMachine(AbcBlock* pool_block);
 
        as_value executeFunction(asMethod* function, const fn_call& fn);
 
@@ -380,7 +380,7 @@
        as_value mIgnoreReturn; // Throw away returns go here.
 
        bool mExitWithReturn;
-       abc_block* mPoolObject; // Where all of the pools are stored.
+       AbcBlock* mPoolObject; // Where all of the pools are stored.
 
        abc_function* mCurrentFunction;
 


reply via email to

[Prev in Thread] Current Thread [Next in Thread]