<html>
<head>
<style><!--
body {background-color:#ffffff;}
.file {border:1px solid #eeeeee;margin-top:1em;margin-bottom:1em;}
.pathname {font-family:monospace; float:right;}
.fileheader {margin-bottom:.5em;}
.diff {margin:0;}
.tasklist {padding:4px;border:1px dashed #000000;margin-top:1em;}
.tasklist ul {margin-top:0;margin-bottom:0;}
tr.alt {background-color:#eeeeee}
#added {background-color:#ddffdd;}
#addedchars {background-color:#99ff99;font-weight:bolder;}
tr.alt #added {background-color:#ccf7cc;}
#removed {background-color:#ffdddd;}
#removedchars {background-color:#ff9999;font-weight:bolder;}
tr.alt #removed {background-color:#f7cccc;}
#info {color:#888888;}
#context {background-color:#eeeeee;}
td {padding-left:.3em;padding-right:.3em;}
tr.head {border-bottom-width:1px;border-bottom-style:solid;}
tr.head td {padding:0;padding-top:.2em;}
.task {background-color:#ffff00;}
.comment {padding:4px;border:1px dashed #000000;background-color:#ffffdd}
.error {color:red;}
hr {border-width:0px;height:2px;background:black;}
--></style>
</head>
<body>
<table cellspacing="0" cellpadding="0" border="0" rules="cols">
<tr class="head"><td colspan="4">Commit in <b><tt>trunk/as2api</tt></b><span id="info"> on MAIN</span></td></tr>
<tr><td><tt><a href="#file1">api_loader.rb</a></tt></td><td align="right" id="added">+42</td><td align="right" id="removed">-23</td><td nowrap="nowrap" align="center">291 -> 292</td></tr>
</table>
<div class="tasklist"><ul>
<li><a href="#task1">TODO: this should be called TypeRef</a></li>
</ul></div>
<pre class="comment">
refactor #resolve_types logic into more manageable bits
</pre>
<hr /><a name="file1" /><div class="file">
<span class="pathname">trunk/as2api</span><br />
<div class="fileheader"><big><b>api_loader.rb</b></big> <small id="info">291 -> 292</small></div>
<pre class="diff"><small id="info">--- trunk/as2api/api_loader.rb        2006-03-07 23:36:22 UTC (rev 291)
+++ trunk/as2api/api_loader.rb        2006-03-08 00:06:29 UTC (rev 292)
@@ -324,6 +324,7 @@
</small></pre><pre class="diff" id="context"> # types pulled into the compilation unit by 'import com.example.*')
class TypeProxy
# TODO: this should be in api_model.rb
</pre><pre class="diff" id="added"><a name="task1" />+ # <span class="task">TODO</span>: this should be called TypeRef
</pre><pre class="diff" id="context">
def initialize(containing_type, name)
@name = name
</pre><pre class="diff"><small id="info">@@ -392,9 +393,6 @@
</small></pre><pre class="diff" id="context"> # ActionScript has been parsed, resolving the real types that the collected
# TypeProxy objects are standing in for.
class GlobalTypeAggregator
</pre><pre class="diff" id="removed">- # TODO: this structure sucks; responsibility for type resolution should be
- # entirely seperate from aggregation, not shoe-horned into this class
-
</pre><pre class="diff" id="context"> def initialize()
@types = []
@packages = {}
</pre><pre class="diff"><small id="info">@@ -444,33 +442,54 @@
</small></pre><pre class="diff" id="context"> end
def resolve_types(type_aggregator)
</pre><pre class="diff" id="removed">- # Eeek!...
- qname_map = {}
- qname_map[AS_VOID.qualified_name] = AS_VOID
</pre><pre class="diff" id="added">+ global_ns = create_default_global_namespace
+ add_fully_qualified_types_to_namespace(global_ns, type_aggregator)
+ resolve_each_type(global_ns, type_aggregator)
+ end
+
+ private
+
+ def create_default_global_namespace
+ ns = {}
+ ns[AS_VOID.qualified_name] = AS_VOID
+ ns
+ end
+
+ def add_fully_qualified_types_to_namespace(ns, type_aggregator)
</pre><pre class="diff" id="context"> type_aggregator.each_type do |type|
</pre><pre class="diff" id="removed">- <span id="removedchars">qname_map</span>[type.qualified_name] = type
</pre><pre class="diff" id="added">+ <span id="addedchars">ns</span>[type.qualified_name] = type
</pre><pre class="diff" id="context"> end
</pre><pre class="diff" id="added">+ end
+
+ def create_local_namespace(global_ns, type_aggregator, type)
+ ns = global_ns.dup
+ ns[type.unqualified_name] = type
+ import_types_into_namespace(type, ns)
+ import_packages_into_namespace(type_aggregator, type, ns)
+ ns
+ end
+
+ def resolve_each_type(global_ns, type_aggregator)
</pre><pre class="diff" id="context"> type_aggregator.each_type do |type|
</pre><pre class="diff" id="removed">- local_namespace = qname_map.dup
- local_namespace[type.unqualified_name] = type
- import_types_into_namespace(type, local_namespace)
- import_packages_into_namespace(type_aggregator, type, local_namespace)
- type.type_namespace.each do |type_proxy|
-        real_type = local_namespace[type_proxy.local_name]
-        unless real_type
-         real_type = maybe_parse_external_definition(type_proxy)
-        end
-        if real_type
-         type_proxy.resolved_type = real_type
-        else
-         $stderr.puts "#{type.input_filename}:#{type_proxy.lineno}: Found no definition of type known locally as #{type_proxy.local_name.inspect}"
-        end
</pre><pre class="diff" id="added">+ local_ns = create_local_namespace(global_ns, type_aggregator, type)
+ resolve_type_proxies(local_ns, type)
+ end
+ end
+
+ def resolve_type_proxies(local_ns, type)
+ type.type_namespace.each do |type_proxy|
+ real_type = local_ns[type_proxy.local_name]
+ unless real_type
+        real_type = maybe_parse_external_definition(type_proxy)
</pre><pre class="diff" id="context"> end
</pre><pre class="diff" id="added">+ if real_type
+        type_proxy.resolved_type = real_type
+ else
+        $stderr.puts "#{type.input_filename}:#{type_proxy.lineno}: Found no definition of type known locally as #{type_proxy.local_name.inspect}"
+ end
</pre><pre class="diff" id="context"> end
end
</pre><pre class="diff" id="removed">- private
-
</pre><pre class="diff" id="context"> def import_types_into_namespace(type, local_namespace)
type.import_list.each_type do |type_name|
import_type = local_namespace[type_name.join(".")]
</pre></div>
<center><small><a href="http://www.badgers-in-foil.co.uk/projects/cvsspam/" title="commit -> email">CVSspam</a> 0.2.11</small></center>
</body></html>