Merge pull request #682 from elemoine/export-func

missing exports
This commit is contained in:
Éric Lemoine
2013-08-19 09:14:16 -07:00
24 changed files with 134 additions and 42 deletions

View File

@@ -120,11 +120,84 @@ class Class(Exportable):
return '%sExport' % self.name
class Function(Exportable):
def __init__(self, name, object_literal, return_type, objects):
Exportable.__init__(self, name)
self.object_literal = object_literal
self.return_type = return_type
self.objects = objects
__repr__ = simplerepr
def property_object_literal(self, object_literal, prop):
prop_object_literal = None
types = object_literal.prop_types[prop].split('|')
for t in types:
if t in self.objects:
o = self.objects[t]
if isinstance(o, ObjectLiteral):
if prop_object_literal:
raise RuntimeError('Multiple "literal" types found for '
'option %s.%s: %s, %s.' %
(object_literal.name, prop,
prop_object_literal.name, o.name))
prop_object_literal = o
return prop_object_literal
def recursive_export(self, lines, prop, object_literal, local_var=None, depth=1):
indent = ' ' * depth
if not local_var:
local_var = prop.split('.')[-1]
lines.append('%s/** @type {%s} */\n' % (indent, object_literal.name))
lines.append('%svar %s =\n' % (indent, local_var))
lines.append('%s /** @type {%s} */\n' % (indent, object_literal.name))
lines.append('%s (%s);\n' % (indent, prop))
lines.append('%sif (goog.isDefAndNotNull(%s)) {\n' % (indent, prop))
for key in sorted(object_literal.prop_types.keys()):
prop_object_literal = self.property_object_literal(object_literal, key)
if prop_object_literal:
lv = self.recursive_export(lines, '%s.%s' % (prop, key),
prop_object_literal, depth=depth + 1)
lines.append('%s %s.%s =\n%s %s;\n' %
(indent, local_var, key, indent, lv))
else:
lines.append('%s %s.%s =\n%s %s.%s;\n' %
(indent, local_var, key, indent, prop, key))
lines.append('%s}\n' % (indent,))
return local_var
def export(self):
lines = []
local_var = 'arg'
lines.append('\n\n')
lines.append('/**\n')
lines.append(' * @param {%s} options Options.\n' % (self.object_literal.extern_name(),))
if self.return_type:
lines.append(' * @return {%s} Return value.\n' % (self.return_type,))
lines.append(' */\n')
lines.append('%s = function(options) {\n' % (self.export_name(),))
self.recursive_export(lines, 'options', self.object_literal,
local_var=local_var)
if self.return_type:
lines.append(' return %s(%s);\n' % (self.name, local_var))
else:
lines.append(' %s(arg);\n' % (self.name,))
lines.append('};\n')
lines.append('goog.exportSymbol(\n')
lines.append(' \'%s\',\n' % (self.name,))
lines.append(' %s);\n' % (self.export_name(),))
return ''.join(lines)
def export_name(self):
return '%sExport' % self.name
class ObjectLiteral(Exportable):
def __init__(self, name):
def __init__(self, name, objects):
Exportable.__init__(self, name)
self.prop_types = {}
self.objects = objects
__repr__ = simplerepr
@@ -138,7 +211,12 @@ class ObjectLiteral(Exportable):
for prop in sorted(self.prop_types.keys()):
lines.append('\n\n')
lines.append('/**\n')
lines.append(' * @type {%s}\n' % (self.prop_types[prop],))
prop_types = self.prop_types[prop].split('|')
for i, t in enumerate(prop_types):
if t in self.objects and isinstance(self.objects[t], ObjectLiteral):
prop_types[i] = self.objects[t].extern_name()
prop_types = '|'.join(prop_types)
lines.append(' * @type {%s}\n' % (prop_types,))
lines.append(' */\n')
lines.append('%s.prototype.%s;\n' % (self.extern_name(), prop))
return ''.join(lines)
@@ -221,7 +299,7 @@ def main(argv):
name = m.group('name')
if name in objects:
raise RuntimeError(line) # Name already defined
object_literal = ObjectLiteral(name)
object_literal = ObjectLiteral(name, objects)
objects[name] = object_literal
continue
m = re.match(r'\*\s*@property\s*{(?P<type>.*)}\s*(?P<prop>\S+)', line)
@@ -262,6 +340,22 @@ def main(argv):
objects[name] = symbol
symbol.props.add(prop)
continue
m = re.match(r'@exportFunction\s+(?P<name>\S+)(?:\s+(?P<object_literal_name>\S+))?(?:\s+(?P<return_type>\S+))?\Z', line)
if m:
name = m.group('name')
if name in objects:
raise RuntimeError(line) # Name already defined
object_literal_name = m.group('object_literal_name')
if object_literal_name not in objects:
raise RuntimeError(line)
object_literal = objects[object_literal_name]
if not isinstance(object_literal, ObjectLiteral):
raise RuntimeError(line)
return_type = m.group('return_type')
function = Function(name, object_literal, return_type, objects)
objects[name] = function
requires.add(name)
continue
m = re.match(r'@exportSymbol\s+(?P<name>\S+)(?:\s+(?P<export_as>\S+))?\Z', line)
if m:
name = m.group('name')

View File

@@ -1,7 +1,9 @@
goog.require('ol.Map');
goog.require('ol.RendererHints');
goog.require('ol.View2D');
goog.require('ol.animation');
goog.require('ol.animation.bounce');
goog.require('ol.animation.pan');
goog.require('ol.animation.rotate');
goog.require('ol.easing');
goog.require('ol.layer.TileLayer');
goog.require('ol.proj');

View File

@@ -64,7 +64,7 @@ ol.inherits(app.RotateNorthControl, ol.control.Control);
var map = new ol.Map({
controls: ol.control.defaults({}, [
controls: ol.control.defaults().extend([
new app.RotateNorthControl()
]),
layers: [

View File

@@ -8,7 +8,7 @@ goog.require('ol.source.MapQuestOpenAerial');
var map = new ol.Map({
interactions: ol.interaction.defaults({}, [
interactions: ol.interaction.defaults().extend([
new ol.interaction.DragRotateAndZoom()
]),
layers: [

View File

@@ -22,7 +22,7 @@ var layers = [
];
var map = new ol.Map({
controls: ol.control.defaults({}, [
controls: ol.control.defaults().extend([
new ol.control.ScaleLine({
units: ol.control.ScaleLineUnits.DEGREES
})

View File

@@ -10,10 +10,10 @@ goog.require('ol.source.BingMaps');
var map = new ol.Map({
controls: ol.control.defaults({}, [
controls: ol.control.defaults().extend([
new ol.control.FullScreen()
]),
interactions: ol.interaction.defaults({}, [
interactions: ol.interaction.defaults().extend([
new ol.interaction.DragRotateAndZoom()
]),
layers: [

View File

@@ -13,7 +13,7 @@ var view = new ol.View2D({
});
var map = new ol.Map({
controls: ol.control.defaults({}, [
controls: ol.control.defaults().extend([
new ol.control.FullScreen()
]),
layers: [

View File

@@ -20,7 +20,7 @@ var mousePositionControl = new ol.control.MousePosition({
});
var map = new ol.Map({
controls: ol.control.defaults({}, [mousePositionControl]),
controls: ol.control.defaults().extend([mousePositionControl]),
layers: [
new ol.layer.TileLayer({
source: new ol.source.OSM()

View File

@@ -8,7 +8,7 @@ goog.require('ol.source.OSM');
var map = new ol.Map({
controls: ol.control.defaults({}, [
controls: ol.control.defaults().extend([
new ol.control.ZoomToExtent({
extent: [
813079.7791264898,

View File

@@ -11,7 +11,7 @@ goog.require('ol.source.OSM');
var scaleLineControl = new ol.control.ScaleLine();
var map = new ol.Map({
controls: ol.control.defaults({}, [
controls: ol.control.defaults().extend([
scaleLineControl
]),
layers: [

View File

@@ -42,7 +42,7 @@ var lineStringCollection = ol.geom2.LineStringCollection.pack([
]);
var map = new ol.Map({
controls: ol.control.defaults({}, [
controls: ol.control.defaults().extend([
new ol.control.MousePosition({
undefinedHTML: '&nbsp;'
})

View File

@@ -47,7 +47,7 @@ var layers = [
];
var map = new ol.Map({
controls: ol.control.defaults({}, [
controls: ol.control.defaults().extend([
new ol.control.ScaleLine({
units: ol.control.ScaleLineUnits.METRIC
})

View File

@@ -1,4 +1,4 @@
@exportSymbol ol.animation.bounce
@exportSymbol ol.animation.pan
@exportSymbol ol.animation.rotate
@exportSymbol ol.animation.zoom
@exportFunction ol.animation.bounce ol.animation.BounceOptions ol.PreRenderFunction
@exportFunction ol.animation.pan ol.animation.PanOptions ol.PreRenderFunction
@exportFunction ol.animation.rotate ol.animation.RotateOptions ol.PreRenderFunction
@exportFunction ol.animation.zoom ol.animation.ZoomOptions ol.PreRenderFunction

View File

@@ -1,6 +1,9 @@
// FIXME works for View2D only
goog.provide('ol.animation');
goog.provide('ol.animation.bounce');
goog.provide('ol.animation.pan');
goog.provide('ol.animation.rotate');
goog.provide('ol.animation.zoom');
goog.require('ol.PreRenderFunction');
goog.require('ol.ViewHint');

View File

@@ -1,5 +1,6 @@
@exportSymbol ol.Collection
@exportProperty ol.Collection.prototype.clear
@exportProperty ol.Collection.prototype.extend
@exportProperty ol.Collection.prototype.forEach
@exportProperty ol.Collection.prototype.getAt
@exportProperty ol.Collection.prototype.getLength

View File

@@ -86,12 +86,14 @@ ol.Collection.prototype.clear = function() {
/**
* @param {Array} arr Array.
* @return {ol.Collection} This collection.
*/
ol.Collection.prototype.extend = function(arr) {
var i, ii;
for (i = 0, ii = arr.length; i < ii; ++i) {
this.push(arr[i]);
}
return this;
};

View File

@@ -1 +1 @@
@exportSymbol ol.control.defaults ol.control.defaults
@exportFunction ol.control.defaults ol.control.DefaultsOptions ol.Collection

View File

@@ -8,10 +8,9 @@ goog.require('ol.control.Zoom');
/**
* @param {ol.control.DefaultsOptions=} opt_options Defaults options.
* @param {Array.<ol.control.Control>=} opt_controls Additional controls.
* @return {ol.Collection} Controls.
*/
ol.control.defaults = function(opt_options, opt_controls) {
ol.control.defaults = function(opt_options) {
var options = goog.isDef(opt_options) ? opt_options : {};
@@ -36,15 +35,11 @@ ol.control.defaults = function(opt_options, opt_controls) {
var zoomControl = goog.isDef(options.zoom) ?
options.zoom : true;
if (zoomControl) {
var zoomControlOptions = goog.isDef(options.zoomControlOptions) ?
options.zoomControlOptions : undefined;
var zoomControlOptions = goog.isDef(options.zoomOptions) ?
options.zoomOptions : undefined;
controls.push(new ol.control.Zoom(zoomControlOptions));
}
if (goog.isDef(opt_controls)) {
controls.extend(opt_controls);
}
return controls;
};

View File

@@ -6,7 +6,7 @@ goog.require('goog.dom');
goog.require('goog.dom.TagName');
goog.require('goog.events');
goog.require('goog.events.EventType');
goog.require('ol.animation');
goog.require('ol.animation.zoom');
goog.require('ol.control.Control');
goog.require('ol.css');
goog.require('ol.easing');

View File

@@ -15,7 +15,7 @@ goog.require('goog.fx.Dragger.EventType');
goog.require('goog.math');
goog.require('goog.math.Rect');
goog.require('goog.style');
goog.require('ol.animation');
goog.require('ol.animation.zoom');
goog.require('ol.control.Control');
goog.require('ol.css');
goog.require('ol.easing');

View File

@@ -3,7 +3,9 @@
goog.provide('ol.interaction.Interaction');
goog.require('ol.MapBrowserEvent');
goog.require('ol.animation');
goog.require('ol.animation.pan');
goog.require('ol.animation.rotate');
goog.require('ol.animation.zoom');
goog.require('ol.easing');

View File

@@ -1 +1 @@
@exportSymbol ol.interaction.defaults ol.interaction.defaults
@exportFunction ol.interaction.defaults ol.interaction.DefaultsOptions ol.Collection

View File

@@ -6,7 +6,6 @@ goog.require('ol.interaction.DoubleClickZoom');
goog.require('ol.interaction.DragPan');
goog.require('ol.interaction.DragRotate');
goog.require('ol.interaction.DragZoom');
goog.require('ol.interaction.Interaction');
goog.require('ol.interaction.KeyboardPan');
goog.require('ol.interaction.KeyboardZoom');
goog.require('ol.interaction.MouseWheelZoom');
@@ -17,11 +16,9 @@ goog.require('ol.interaction.TouchZoom');
/**
* @param {ol.interaction.DefaultsOptions=} opt_options Defaults options.
* @param {Array.<ol.interaction.Interaction>=} opt_interactions Additional
* interactions.
* @return {ol.Collection} Interactions.
*/
ol.interaction.defaults = function(opt_options, opt_interactions) {
ol.interaction.defaults = function(opt_options) {
var options = goog.isDef(opt_options) ? opt_options : {};
@@ -92,10 +89,6 @@ ol.interaction.defaults = function(opt_options, opt_interactions) {
interactions.push(new ol.interaction.DragZoom());
}
if (goog.isDef(opt_interactions)) {
interactions.extend(opt_interactions);
}
return interactions;
};

View File

@@ -3,7 +3,7 @@ goog.provide('ol.Kinetic');
goog.require('ol.Coordinate');
goog.require('ol.PreRenderFunction');
goog.require('ol.animation');
goog.require('ol.animation.pan');