Permalink
Browse files

Advances towards finish

  • Loading branch information...
1 parent 5212b15 commit 092f0eeb9873c3d7d2bbd4950adc42cbc2d9c66c @codeboost committed May 25, 2011
Showing with 94 additions and 74 deletions.
  1. +8 −2 beautils.js
  2. +20 −6 classconvert.js
  3. +11 −29 mgr.js
  4. +5 −0 snippets.js
  5. +6 −1 src/beautils.coffee
  6. +22 −7 src/classconvert.coffee
  7. +18 −27 src/mgr.coffee
  8. +4 −2 src/snippets.coffee
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
View
40 mgr.js
@@ -11,45 +11,27 @@
this.namespaces = namespaces;
this.types = [];
}
- TypeManager.prototype.addWrapped = function(type, baseType) {
+ TypeManager.prototype.addClassType = function(type) {
type.wrapped = true;
type.manual = false;
- if (!this.isWrapped(type)) {
- this.types.push(type);
- }
- if (baseType) {
- this.types.push(baseType);
- baseType.alias = type.fullType();
- baseType.manual = false;
- return baseType.wrapped = true;
- }
+ this.dropType(type);
+ return this.types.push(type);
};
TypeManager.prototype.addClassNode = function(classNode, namespace) {
var cl, cltype;
cl = beautils.parseClassDirective(classNode);
cltype = new beautils.Type(cl.className, namespace);
- cltype.wrapped = true;
- cltype.manual = false;
- if (!this.findWrapped(cltype)) {
- return this.types.push(cltype);
- }
+ return this.addClassType(cltype);
};
- TypeManager.prototype.isWrapped = function(type) {
- var wrapped;
- wrapped = _.filter(this.types, function(t) {
- return t.wrapped;
- });
- return _.any(wrapped, function(wt) {
- return wt.rawType === type.rawType && wt.namespace === type.namespace;
+ TypeManager.prototype.dropType = function(type) {
+ this.types = _.reject(this.types, function(t) {
+ return t.wrapped === type.wrapped && t.rawType === type.rawType && t.namespace === type.namespace;
});
+ return this.types;
};
- TypeManager.prototype.findWrapped = function(type) {
- var wrapped;
- wrapped = _.filter(this.types, function(t) {
- return t.wrapped;
- });
- return _.detect(wrapped, function(wt) {
- return wt.rawType === type.rawType && wt.namespace === type.namespace;
+ TypeManager.prototype.isWrapped = function(type) {
+ return _.any(this.types, function(wt) {
+ return wt.wrapped && wt.rawType === type.rawType && wt.namespace === type.namespace;
});
};
TypeManager.prototype.knownType = function(type) {
View
@@ -114,4 +114,9 @@
struct.ToJS = struct.add(new CodeBlock.FunctionBlock("static v8::Handle<v8::Value> ToJS(" + (fixt(type)) + " const& v)"));
return struct;
};
+ exports.FromJSPointer = function(type, name, v, i) {
+ var vtype;
+ vtype = "std::vector<" + (fixt(type)) + ">";
+ return ("" + vtype + " v_" + name + " = ") + exports.FromJS(vtype, v, i);
+ };
}).call(this);
View
@@ -152,8 +152,13 @@ parseDeclaration = (str, namespace) ->
decla = decla.replace /^virtual\s+/, ''
isVirtual = true
+ isStatic = false
+ if /^static\s+/.test decla
+ decla = decla.replace /^static\s+/, ''
+ isStatic = true
+
fnDec = new Argument decla, namespace
- _.extend fnDec, {args: fnArgs, virtual: isVirtual, pure: isPure}
+ _.extend fnDec, {args: fnArgs, virtual: isVirtual, pure: isPure, static: isStatic}
isSameOverload = (overload1, overload2) ->
overload1.name == overload2.name &&
View
@@ -108,10 +108,12 @@ class ClassConverter
if not @isStatic
- @options.typeManager.addWrapped @classType, @baseType
-
-
-
+ @options.typeManager.addClassType @classType
+ if @baseType
+ @baseType.alias = @classType.fullType() #means return from this type
+ @options.typeManager.addClassType @baseType
+
+
@globalBlock = new CodeBlock.CodeBlock
#produce destructor
@@ -502,9 +504,18 @@ class ClassConverter
#Create conversion code for a function argument
convertArg: (arg, narg) ->
nativeType = @nativeType arg.type
- if arg.type.rawType == 'void' then @warn 'Type #{arg.type.fullType()} used as argument type.'
+
+ if arg.type.rawType == 'void'
+ @warn "Type #{arg.type.fullType()} used as argument type."
+ return ""
+
if not arg.value
- return "#{nativeType} #{arg.name} = " + snippets.FromJS nativeType, "args[#{narg}]", narg
+ if 0 && arg.type.isPointer && !@typeManager.isWrapped arg.type && arg.type.isConst
+ ret = snippets.FromJSPointer nativeType, arg.name, "args[#{narg}]", narg
+ arg.name = "&v_" + arg.name + "[0]"
+ return ret
+ else
+ return "#{nativeType} #{arg.name} = " + snippets.FromJS nativeType, "args[#{narg}]", narg
else
#value can be:
#someArg = integer
@@ -551,8 +562,10 @@ class ClassConverter
return block
@convertArguments block, overload.args
+
+ isStatic = overload.static | @isStatic
- if !@isStatic && overload.name != "__constructor"
+ if !isStatic && overload.name != "__constructor"
block.add "#{@classType.fullType()}* _this = " + snippets.FromJS @classType.fullType() + '*', "args.This()", 0
if overload.name == '__postAllocator' && @virtualCount > 0
@@ -586,6 +599,8 @@ class ClassConverter
fnName = overload.callAs ? overload.name
if @isStatic
fnName = @namespace + '::' + fnName
+ else if overload.static
+ fnName = @nativeClassName + '::' + fnName
else
if overload.name == '__postAllocator'
fnName = ''
View
@@ -8,43 +8,34 @@ fixt = snippets.fixt
class TypeManager
constructor: (@logger, @namespaces) ->
@types = []
-
- #add a 'wrapped' or exposed class to the list
- addWrapped: (type, baseType) ->
+ #adds a type which represents an exposed class: I call them 'wrapped' types
+ #These types will have different conversions generated (basically, returning from bea::ExposedClass<Type>)
+ addClassType: (type) ->
type.wrapped = true
type.manual = false
+ @dropType(type)
+ @types.push type
- if not @isWrapped type then @types.push type
-
- if baseType
- #tmp = @findWrapped baseType
- #make sure it doesn't already exists in the list
- #possibly added by the pre-parse step
- @types.push baseType
- #if tmp then baseType = tmp else
- baseType.alias = type.fullType()
- baseType.manual = false
- baseType.wrapped = true
-
-
#parse class node and create a 'wrapped' type from the declaraiton
addClassNode: (classNode, namespace) ->
cl = beautils.parseClassDirective classNode
cltype = new beautils.Type cl.className, namespace
- cltype.wrapped = true
- cltype.manual = false
- if not @findWrapped cltype then @types.push cltype
-
+ @addClassType cltype
+
+ dropType: (type) ->
+ @types = _.reject @types, (t) ->
+ t.wrapped == type.wrapped &&
+ t.rawType == type.rawType &&
+ t.namespace == type.namespace
+ @types
+
#Check if a type is 'Wrapped', eg. is an exposed class
isWrapped: (type) ->
- wrapped = _.filter @types, (t) -> t.wrapped
- _.any wrapped, (wt) -> wt.rawType == type.rawType && wt.namespace == type.namespace
-
- findWrapped: (type) ->
- wrapped = _.filter @types, (t) -> t.wrapped
- _.detect wrapped, (wt) -> wt.rawType == type.rawType && wt.namespace == type.namespace
-
+ _.any @types, (wt) ->
+ wt.wrapped &&
+ wt.rawType == type.rawType &&
+ wt.namespace == type.namespace
#Check if a type is native or is in the list of declared types
knownType: (type) ->
View
@@ -102,5 +102,7 @@ exports.ConvertStruct = (type) ->
struct.FromJS = struct.add new CodeBlock.FunctionBlock "static #{type} FromJS(v8::Handle<v8::Value> v, int nArg)"
struct.ToJS = struct.add new CodeBlock.FunctionBlock "static v8::Handle<v8::Value> ToJS(#{fixt type} const& v)"
return struct
-
-
+
+exports.FromJSPointer = (type, name, v, i) ->
+ vtype = "std::vector<#{fixt type}>"
+ "#{vtype} v_#{name} = " + exports.FromJS vtype, v, i

0 comments on commit 092f0ee

Please sign in to comment.