Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

fix accessor parsing

  • Loading branch information...
commit 0005ef45618c07c76560b74e4b74b3dd2cb5796d 1 parent 7fef8bb
@codeboost authored
Showing with 74 additions and 39 deletions.
  1. +34 −21 classconvert.js
  2. +40 −18 src/classconvert.coffee
View
55 classconvert.js
@@ -166,7 +166,7 @@
return ret;
};
ClassConverter.prototype.processFunNode = function(node) {
- var accType, callNode, existing, fn, fspace, isManual, nodeText, str, _accName;
+ var callNode, existing, fn, isManual, nodeText, str;
if (/^\/\//.test(node.text)) {
return false;
}
@@ -202,25 +202,7 @@
}
str = str.replace(/;\s*$/, '');
if (str.indexOf("(") === -1 && /\s+/.test(str)) {
- str = str.replace(/\s+/g, ' ');
- fspace = str.indexOf(' ');
- accType = str.slice(0, fspace);
- _accName = str.slice(fspace);
- _.each(_accName.split(','), __bind(function(accName) {
- var accessor;
- accName = beautils.trim(accName);
- if (!accName.length) {
- return false;
- }
- accessor = {
- type: new beautils.Type(accType, this.namespace),
- name: accName,
- read: "_this->" + accName,
- write: "_this->" + accName + " = _accValue;"
- };
- return this.addAccessor(accessor, node);
- }, this));
- return true;
+ return this.parseAsAccessor(str, node);
}
if (/\s+operator\s*[=\+\/\\\*<>\^\-]*/.test(str)) {
return this.warn('Operator overloading not supported. Declaration ignored', node);
@@ -267,6 +249,37 @@
}
return true;
};
+ ClassConverter.prototype.parseAsAccessor = function(str, node) {
+ var accType, ar1, tmp, _accName;
+ str = str.replace(/\s+/g, ' ');
+ tmp = str.split(',');
+ ar1 = beautils.parseArg(tmp[0]);
+ accType = ar1.type;
+ _accName = tmp.slice(1);
+ _accName.push(ar1.name);
+ _.each(_accName, __bind(function(accName) {
+ var accessor, read, type, write;
+ accName = beautils.trim(accName);
+ if (!accName.length) {
+ return false;
+ }
+ type = new beautils.Type(accType, this.namespace);
+ read = "_this->" + accName;
+ write = "_this->" + accName + " = _accValue;";
+ if (this.typeManager.isWrapped(type)) {
+ read = "&" + read;
+ write = "_this->" + accName + " = *_accValue;";
+ }
+ accessor = {
+ type: type,
+ name: accName,
+ read: read,
+ write: write
+ };
+ return this.addAccessor(accessor, node);
+ }, this));
+ return true;
+ };
ClassConverter.prototype.addAccessor = function(accessor, node) {
if (this.accessors[accessor.name]) {
return this.warn("Accessor: '" + accessor.name + "': accessor already defined. Second definition ignored", node);
@@ -557,7 +570,7 @@
fnRet = '';
retVal = 'return args.This();';
argList = names.join(', ');
- if (overload.type.rawType !== 'void') {
+ if (overload.type.type !== 'void') {
nativeType = this.nativeType(overload.type);
fnRet = nativeType + ' fnRetVal';
retVal = "return " + snippets.ToJS(nativeType, "fnRetVal");
View
58 src/classconvert.coffee
@@ -88,7 +88,7 @@ class ClassConverter
@warn 'Private and protected members ignored.', child
else
@processFunNode child
-
+
#save raw processed class in the global 'environ' thing
#we may revisit this class if another class derives from it
if !@environ[@namespace]
@@ -210,21 +210,7 @@ class ClassConverter
#If string doesn't look like a function call, but has a space,
#we assume that it is in the form Type name and we generate a r/w accessor for it
if str.indexOf("(") == -1 && /\s+/.test str
- str = str.replace /\s+/g, ' '
- fspace = str.indexOf ' '
- accType = str.slice 0, fspace
- _accName = str.slice fspace
- #declared as int x, y
- _.each _accName.split(','), (accName) =>
- accName = beautils.trim(accName)
- return false unless accName.length
- accessor =
- type: new beautils.Type accType, @namespace
- name: accName
- read: "_this->#{accName}"
- write: "_this->#{accName} = _accValue;"
- @addAccessor accessor, node
- return true
+ return @parseAsAccessor str, node
if /\s+operator\s*[=\+\/\\\*<>\^\-]*/.test str
return @warn 'Operator overloading not supported. Declaration ignored', node
@@ -278,7 +264,43 @@ class ClassConverter
@classFns[fn.name].type = fn.type
return true
-
+
+ #parse a string as accessor declaration
+ #eg. int value1, value2, etc..
+ parseAsAccessor: (str, node) ->
+ str = str.replace /\s+/g, ' '
+ #split by , --> we can have multiple variables declared as
+ #type var1, var2, var3
+ tmp = str.split ','
+ #first element is the argument type/name
+ ar1 = beautils.parseArg tmp[0]
+ accType = ar1.type
+ #the rest of the array are other variables
+ _accName = tmp.slice 1
+ _accName.push ar1.name
+ _.each _accName, (accName) =>
+ accName = beautils.trim(accName)
+ return false unless accName.length
+
+ type = new beautils.Type accType, @namespace
+ read = "_this->#{accName}"
+ write = "_this->#{accName} = _accValue;"
+
+ #cast to/back from pointer if type is wrapped
+ if @typeManager.isWrapped(type)
+ read = "&" + read
+ write = "_this->#{accName} = *_accValue;"
+
+ accessor =
+ type: type
+ name: accName
+ read: read
+ write: write
+
+ @addAccessor accessor, node
+ return true
+
+ #add accessors to the list of accessors
addAccessor: (accessor, node) ->
if @accessors[accessor.name] then return @warn "Accessor: '#{accessor.name}': accessor already defined. Second definition ignored", node
@accessors[accessor.name] = accessor
@@ -589,7 +611,7 @@ class ClassConverter
argList = names.join(', ')
- if overload.type.rawType != 'void'
+ if overload.type.type != 'void'
nativeType = @nativeType(overload.type)
fnRet = nativeType + ' fnRetVal'
retVal = "return " + snippets.ToJS(nativeType, "fnRetVal")
Please sign in to comment.
Something went wrong with that request. Please try again.