Permalink
Browse files

Attempt to add properties

  • Loading branch information...
1 parent 43d99c9 commit 9c13a3ad9ae83a952224b46ae3754c95c099057c @shamanas committed May 6, 2012
Showing with 45 additions and 6 deletions.
  1. +5 −2 source/FunctionVisitor.ooc
  2. +38 −2 source/ObjectVisitor.ooc
  3. +2 −2 source/Utils.ooc
@@ -13,10 +13,11 @@ FunctionVisitor: class extends Visitor {
write: func(writer: OocWriter) {
name := info getName()
isStatic? := false
+ isConstructor? := info getFlags() & FunctionInfoFlags isConstructor?
suffix: String = null
// This is pretty naive but at the moment only constructors are detected as static, I have found no other way to do it D:
- if(parent && info getFlags() & FunctionInfoFlags isConstructor?) {
+ if(parent && isConstructor?) {
isStatic? = true
suffix = name toString()
name = "new" toCString() // c"new"
@@ -45,7 +46,9 @@ FunctionVisitor: class extends Visitor {
if(!first) writer uw(")")
returnType := info getReturnType()
- if(returnType && (str := returnType toString()) != "Void") {
+ if(isConstructor? && parent) {
+ writer uw(" -> This")
+ } else if(returnType && (str := returnType toString()) != "Void") {
writer uw(" -> %s" format(str))
}
writer uw("\n")
View
@@ -1,6 +1,7 @@
use gi
-import gi/[FunctionInfo, ObjectInfo, ArgInfo, InterfaceInfo]
-import OocWriter, Visitor, FunctionVisitor, Utils
+import gi/[FunctionInfo, ObjectInfo, ArgInfo, InterfaceInfo, PropertyInfo]
+import OocWriter, Visitor, FunctionVisitor, PropertyVisitor, Utils
+import structs/ArrayList
ObjectVisitor: class extends Visitor {
info: ObjectInfo
@@ -31,11 +32,46 @@ ObjectVisitor: class extends Visitor {
writer uw(" {\n\n") . indent()
+ // Create an array of PropertyVisitors that will be filled when iterating through methods
+ properties := ArrayList<PropertyVisitor> new(info getNProperties())
+ // Write our methods
for(i in 0 .. info getNMethods()) {
method := info getMethod(i)
+
+ if(method getFlags() & FunctionInfoFlags isGetter?) {
+ // If this function is a getter, we try to find a property in our array that matches it else we add it
+ prop := visitorFor(properties, method getProperty())
+ if(prop) {
+ prop getter = info getMethod(i)
+ } else {
+ prop := PropertyVisitor new(method getProperty())
+ prop getter = info getMethod(i)
+ properties add(prop)
+ }
+ } else if(method getFlags() & FunctionInfoFlags isSetter?) {
+ // Same here
+ prop := visitorFor(properties, method getProperty())
+ if(prop) {
+ prop setter = info getMethod(i)
+ } else {
+ prop := PropertyVisitor new(method getProperty())
+ prop setter = info getMethod(i)
+ properties add(prop)
+ }
+ }
+
FunctionVisitor new(method, info) write(writer)
method unref()
}
+ // Write our properties (they call methods under the hood)
+ properties each(|visitor|
+ visitor write(writer)
+ visitor info unref()
+ visitor getter unref()
+ visitor setter unref()
+ gc_free(visitor)
+ )
+ gc_free(properties)
writer uw('\n') . dedent() . w("}\n\n")
}
View
@@ -47,10 +47,10 @@ extend String {
}
}
- toCamelCase: func -> This {
+ toCamelCase: func(delim := '_') -> This {
ret := ""
first := true
- this split('_') each(|str|
+ this split(delim) each(|str|
if(first) first = false
else if(str size > 0) {
str _buffer data[0] = str[0] toUpper()

0 comments on commit 9c13a3a

Please sign in to comment.