Skip to content

Commit

Permalink
Merge pull request #2 from dougm/enums
Browse files Browse the repository at this point in the history
Enum type related changes
  • Loading branch information
dougm committed Aug 14, 2014
2 parents 5a0e65e + 79f0006 commit 20da5be
Show file tree
Hide file tree
Showing 7 changed files with 3,819 additions and 3,751 deletions.
Empty file modified gen/gen.sh
100644 → 100755
Empty file.
16 changes: 8 additions & 8 deletions gen/gen_from_vmodl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -191,15 +191,15 @@ def managed
wsdl.validate_assumptions!
wsdl.peek()

mo_go = File.open(File.join(ARGV.first, "mo/mo.go"), "w")
io = mo_go
io.print "package mo\n\n"
File.open(File.join(ARGV.first, "mo/mo.go"), "w") do |io|
io.print WSDL.header("mo")

vmodl = Vmodl.new(read "vmodl.db")
vmodl = Vmodl.new(read "vmodl.db")

vmodl.
managed.
sort_by { |m| m.name }.
each { |m| m.dump(io) }
vmodl.
managed.
sort_by { |m| m.name }.
each { |m| m.dump(io) }
end

exit(0)
96 changes: 51 additions & 45 deletions gen/gen_from_wsdl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,50 +27,56 @@
ifs = Peek.types.keys.select { |name| Peek.base?(name) }.size()
puts "%d classes, %d interfaces" % [Peek.types.size(), ifs]

types_go = File.open(File.join(ARGV.first, "types/types.go"), "w")
io = types_go
io.print "package types\n\n"

wsdl.
types.
sort_by { |x| x.name }.
uniq { |x| x.name }.
select { |x| x.name[0] == x.name[0].upcase }. # Only capitalized methods for now...
select { |t| t.is_enum? }.
each { |e| e.dump(io); e.dump_init(io) }

wsdl.
types.
sort_by { |x| x.name }.
uniq { |x| x.name }.
select { |x| x.name[0] == x.name[0].upcase }. # Only capitalized methods for now...
select { |t| !t.is_enum? }.
each { |e| e.dump(io); e.dump_init(io) }

if_go = File.open(File.join(ARGV.first, "types/if.go"), "w")
io = if_go
io.print "package types\n\n"
Peek.dump_interfaces(io)

methods_go = File.open(File.join(ARGV.first, "methods/methods.go"), "w")
io = methods_go
io.print "package methods\n\n"

wsdl.
operations.
sort_by { |x| x.name }.
select { |x| x.name[0] == x.name[0].upcase }. # Only capitalized methods for now...
each { |e| e.dump(io) }

methods_go = File.open(File.join(ARGV.first, "tasks/tasks.go"), "w")
io = methods_go
io.print "package tasks\n\n"

wsdl.
operations.
sort_by { |x| x.name }.
select { |x| x.name[0] == x.name[0].upcase }. # Only capitalized methods for now...
select { |x| x.name =~ /_Task$/ }.
each { |e| e.dump_task(io) }
File.open(File.join(ARGV.first, "types/enum.go"), "w") do |io|
io.print WSDL.header("types")

wsdl.
types.
sort_by { |x| x.name }.
uniq { |x| x.name }.
select { |x| x.name[0] == x.name[0].upcase }. # Only capitalized methods for now...
select { |t| t.is_enum? }.
each { |e| e.dump(io); e.dump_init(io) }
end

File.open(File.join(ARGV.first, "types/types.go"), "w") do |io|
io.print WSDL.header("types")

wsdl.
types.
sort_by { |x| x.name }.
uniq { |x| x.name }.
select { |x| x.name[0] == x.name[0].upcase }. # Only capitalized methods for now...
select { |t| !t.is_enum? }.
each { |e| e.dump(io); e.dump_init(io) }
end

File.open(File.join(ARGV.first, "types/if.go"), "w") do |io|
io.print WSDL.header("types")

Peek.dump_interfaces(io)
end

File.open(File.join(ARGV.first, "methods/methods.go"), "w") do |io|
io.print WSDL.header("methods")

wsdl.
operations.
sort_by { |x| x.name }.
select { |x| x.name[0] == x.name[0].upcase }. # Only capitalized methods for now...
each { |e| e.dump(io) }
end


File.open(File.join(ARGV.first, "tasks/tasks.go"), "w") do |io|
io.print WSDL.header("tasks")

wsdl.
operations.
sort_by { |x| x.name }.
select { |x| x.name[0] == x.name[0].upcase }. # Only capitalized methods for now...
select { |x| x.name =~ /_Task$/ }.
each { |e| e.dump_task(io) }
end

exit(0)
49 changes: 46 additions & 3 deletions gen/vim_wsdl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ def base?

@@types = {}
@@refs = {}
@@enums = {}

def self.types
return @@types
Expand All @@ -43,10 +44,22 @@ def self.refs
return @@refs
end

def self.enums
return @@enums
end

def self.ref(type)
refs[type] = true
end

def self.enum(type)
enums[type] = true
end

def self.enum?(type)
enums[type]
end

def self.register(name)
raise unless name
types[name] ||= Type.new()
Expand Down Expand Up @@ -144,6 +157,10 @@ def base_type?
vim_type? && Peek.base?(vim_type)
end

def enum_type?
vim_type? && Peek.enum?(vim_type)
end

def any_type?
self.type == "xsd:anyType"
end
Expand Down Expand Up @@ -185,7 +202,7 @@ def var_type
if base_type?
prefix += "Base"
else
prefix += "*" if !slice? && optional?
prefix += "*" if !slice? && !enum_type? && optional?
end
end

Expand Down Expand Up @@ -294,7 +311,7 @@ def dump(io)
end

io.print "type %s string\n\n" % name
io.print "var (\n"
io.print "const (\n"
enums.each { |e| e.dump(io) }
io.print ")\n\n"
end
Expand All @@ -304,6 +321,10 @@ def dump_init(io)
io.print "t[\"%s\"] = reflect.TypeOf((*%s)(nil)).Elem()\n" % [name, name]
io.print "}\n\n"
end

def peek
Peek.enum(name)
end
end

class ComplexType < Simple
Expand Down Expand Up @@ -707,7 +728,29 @@ def peek
sort_by { |x| x.name }.
uniq { |x| x.name }.
select { |x| x.name[0] == x.name[0].upcase }. # Only capitalized methods for now...
select { |t| !t.is_enum? }.
each { |e| e.peek() }
end

def self.header(name)
return <<EOF
/*
Copyright (c) 2014 VMware, Inc. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package #{name}
EOF
end
end
Loading

0 comments on commit 20da5be

Please sign in to comment.