Skip to content

Commit

Permalink
Updates
Browse files Browse the repository at this point in the history
  • Loading branch information
Florin Braghis committed May 21, 2011
1 parent e571b2e commit 4ffade9
Show file tree
Hide file tree
Showing 4 changed files with 112 additions and 4 deletions.
16 changes: 14 additions & 2 deletions beautils.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

38 changes: 37 additions & 1 deletion classconvert.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 11 additions & 1 deletion src/beautils.coffee 100644 → 100755
Expand Up @@ -104,6 +104,11 @@ parseDeclaration = (str, namespace) ->
args = str.slice argsStart + 1, argsEnd args = str.slice argsStart + 1, argsEnd
decla = str.slice(0, argsStart); decla = str.slice(0, argsStart);


isPure = false
if /\s*=\s*0/.test decla
isPure = true
decla = decla.replace /\s*=\s*0;*/, ''

parseArgs = (args) -> parseArgs = (args) ->
if args.length == 0 then return [] if args.length == 0 then return []
ret = [] ret = []
Expand Down Expand Up @@ -141,8 +146,13 @@ parseDeclaration = (str, namespace) ->


fnArgs.push new Argument(arg, namespace) for arg in args fnArgs.push new Argument(arg, namespace) for arg in args


isVirtual = false
if /^virtual\s+/.test decla
decla = decla.replace /^virtual\s+/, ''
isVirtual = true

fnDec = new Argument decla, namespace fnDec = new Argument decla, namespace
_.extend fnDec, {args: fnArgs} _.extend fnDec, {args: fnArgs, virtual: isVirtual, pure: isPure}


isSameOverload = (overload1, overload2) -> isSameOverload = (overload1, overload2) ->
overload1.name == overload2.name && overload1.name == overload2.name &&
Expand Down
50 changes: 50 additions & 0 deletions src/classconvert.coffee
Expand Up @@ -22,6 +22,7 @@ class ClassConverter
@classFns = {} @classFns = {}
@className = "" @className = ""
@nativeClassName = "" @nativeClassName = ""
@virtual = false #has virtual functions
@exposed = true @exposed = true
@namespace = '' @namespace = ''
@nsBlock = null @nsBlock = null
Expand Down Expand Up @@ -53,6 +54,15 @@ class ClassConverter
#parse all functions #parse all functions
_.each cl.node.children, (child) => @processFunNode child _.each cl.node.children, (child) => @processFunNode child


#has virtual functions?
if @virtual
#generate derived class block
#change className to bea_className
#function call will be _this->bea_functionName(arguments)
derivedDecla = @createDerivedClass();



@globalBlock = new CodeBlock.CodeBlock @globalBlock = new CodeBlock.CodeBlock


if not @options.manual if not @options.manual
Expand Down Expand Up @@ -132,7 +142,9 @@ class ClassConverter
if not fn then return @warn "Cannot parse method declaration: '#{str}'. Ignoring.", node if not fn then return @warn "Cannot parse method declaration: '#{str}'. Ignoring.", node


if fn.type.rawType == @nativeClassName && fn.name == "" if fn.type.rawType == @nativeClassName && fn.name == ""
fn.orgName = fn.name
fn.name = '__constructor' fn.name = '__constructor'



if isManual then @logger.stats.manual++ if isManual then @logger.stats.manual++


Expand All @@ -142,6 +154,8 @@ class ClassConverter
fn.sublines = node.children fn.sublines = node.children
fn.node = node fn.node = node


if fn.virtual then @virtual = true

#check sublines for @call directive #check sublines for @call directive
callNode = _.detect fn.sublines, (subline) -> /^\@call/.test subline.text callNode = _.detect fn.sublines, (subline) -> /^\@call/.test subline.text


Expand Down Expand Up @@ -218,6 +232,42 @@ class ClassConverter


return decBlock return decBlock


createDerivedClass: ->

classBlock = new CodeBlock.ClassBlock "class bea_#{@classType} : public #{@classType}, public bea::DerivedClass"

public = classBlock.add (new CodeBlock.CodeBlock "public:", false)

#constructor
constructors = _.detect @classFns, (fn) -> fn.name == '__constructor'

_.each constructors, (constr) ->

#declaration arguments
dargs = _.map constr.args, (arg) arg.org
#call arguments
cargs = _.map constr.args, (arg) arg.name

#bea_Derived() : Derived(){}
#bea_Derived(int k, CClass* ptr): Derived(k, ptr){}
public.add "bea_#{@classType}(#{dargs.join ', '}) : #{@classType}(#{cargs.join(', ')}){}"

#add virtual functions

vfuncs = _.select @classFns, (fn) -> fn.virtual

public.add "//Virtual functions"
_.each vfuncs, (vfunc) ->
dargs = _.map vfunc.args, (arg) arg.org
cargs = _.map vfun.args, (arg) arg.name

ret = 'return'
if vfunc.type.rawType == 'void' then ret = ''

public.add "inline #{vfunc.type.fullType()} bea_#{vfunc.name}(#{dargs.join ', '}){#{ret} #{@classType}::#{vfunc.name}(#{cargs.join ', '});}"



#Create the InitJSObject function, to be added to the CPP file. #Create the InitJSObject function, to be added to the CPP file.
#This function will be called by the exposing function #This function will be called by the exposing function
createInitFn: -> createInitFn: ->
Expand Down

0 comments on commit 4ffade9

Please sign in to comment.