Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
96c0284e
Commit
96c0284e
authored
Jun 23, 2016
by
Tim Hockin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
go2idl: clarify comments wrt get-or-create
This is just comment clarity.
parent
42805f53
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
11 deletions
+19
-11
types.go
cmd/libs/go2idl/types/types.go
+19
-11
No files found.
cmd/libs/go2idl/types/types.go
View file @
96c0284e
...
@@ -118,7 +118,9 @@ func (p *Package) Has(name string) bool {
...
@@ -118,7 +118,9 @@ func (p *Package) Has(name string) bool {
return
has
return
has
}
}
// Get (or add) the given type
// Type gets the given Type in this Package. If the Type is not already
// defined, this will add it and return the new Type value. The caller is
// expected to finish initialization.
func
(
p
*
Package
)
Type
(
typeName
string
)
*
Type
{
func
(
p
*
Package
)
Type
(
typeName
string
)
*
Type
{
if
t
,
ok
:=
p
.
Types
[
typeName
];
ok
{
if
t
,
ok
:=
p
.
Types
[
typeName
];
ok
{
return
t
return
t
...
@@ -135,9 +137,10 @@ func (p *Package) Type(typeName string) *Type {
...
@@ -135,9 +137,10 @@ func (p *Package) Type(typeName string) *Type {
return
t
return
t
}
}
// Get (or add) the given function. If a function is added, it's the caller's
// Function gets the given function Type in this Package. If the function is
// responsibility to finish construction of the function by setting Underlying
// not already defined, this will add it. If a function is added, it's the
// to the correct type.
// caller's responsibility to finish construction of the function by setting
// Underlying to the correct type.
func
(
p
*
Package
)
Function
(
funcName
string
)
*
Type
{
func
(
p
*
Package
)
Function
(
funcName
string
)
*
Type
{
if
t
,
ok
:=
p
.
Functions
[
funcName
];
ok
{
if
t
,
ok
:=
p
.
Functions
[
funcName
];
ok
{
return
t
return
t
...
@@ -148,7 +151,8 @@ func (p *Package) Function(funcName string) *Type {
...
@@ -148,7 +151,8 @@ func (p *Package) Function(funcName string) *Type {
return
t
return
t
}
}
// Get (or add) the given varaible. If a variable is added, it's the caller's
// Variable gets the given varaible Type in this Package. If the variable is
// not already defined, this will add it. If a variable is added, it's the caller's
// responsibility to finish construction of the variable by setting Underlying
// responsibility to finish construction of the variable by setting Underlying
// to the correct type.
// to the correct type.
func
(
p
*
Package
)
Variable
(
varName
string
)
*
Type
{
func
(
p
*
Package
)
Variable
(
varName
string
)
*
Type
{
...
@@ -169,19 +173,20 @@ func (p *Package) HasImport(packageName string) bool {
...
@@ -169,19 +173,20 @@ func (p *Package) HasImport(packageName string) bool {
}
}
// Universe is a map of all packages. The key is the package name, but you
// Universe is a map of all packages. The key is the package name, but you
// should use Get() or Package() instead of direct access.
// should use Package(), Type(), Function(), or Variable() instead of direct
// access.
type
Universe
map
[
string
]
*
Package
type
Universe
map
[
string
]
*
Package
//
Get
returns the canonical type for the given fully-qualified name. Builtin
//
Type
returns the canonical type for the given fully-qualified name. Builtin
// types will always be found, even if they haven't been explicitly added to
// types will always be found, even if they haven't been explicitly added to
// the map. If a non-existing type is requested,
u
will create (a marker for)
// the map. If a non-existing type is requested,
this
will create (a marker for)
// it.
// it.
func
(
u
Universe
)
Type
(
n
Name
)
*
Type
{
func
(
u
Universe
)
Type
(
n
Name
)
*
Type
{
return
u
.
Package
(
n
.
Package
)
.
Type
(
n
.
Name
)
return
u
.
Package
(
n
.
Package
)
.
Type
(
n
.
Name
)
}
}
// Function returns the canonical function for the given fully-qualified name.
// Function returns the canonical function for the given fully-qualified name.
// If a non-existing function is requested,
u
will create (a marker for) it.
// If a non-existing function is requested,
this
will create (a marker for) it.
// If a marker is created, it's the caller's responsibility to finish
// If a marker is created, it's the caller's responsibility to finish
// construction of the function by setting Underlying to the correct type.
// construction of the function by setting Underlying to the correct type.
func
(
u
Universe
)
Function
(
n
Name
)
*
Type
{
func
(
u
Universe
)
Function
(
n
Name
)
*
Type
{
...
@@ -189,7 +194,7 @@ func (u Universe) Function(n Name) *Type {
...
@@ -189,7 +194,7 @@ func (u Universe) Function(n Name) *Type {
}
}
// Variable returns the canonical variable for the given fully-qualified name.
// Variable returns the canonical variable for the given fully-qualified name.
// If a non-existing variable is requested,
u
will create (a marker for) it.
// If a non-existing variable is requested,
this
will create (a marker for) it.
// If a marker is created, it's the caller's responsibility to finish
// If a marker is created, it's the caller's responsibility to finish
// construction of the variable by setting Underlying to the correct type.
// construction of the variable by setting Underlying to the correct type.
func
(
u
Universe
)
Variable
(
n
Name
)
*
Type
{
func
(
u
Universe
)
Variable
(
n
Name
)
*
Type
{
...
@@ -205,7 +210,10 @@ func (u Universe) AddImports(packagePath string, importPaths ...string) {
...
@@ -205,7 +210,10 @@ func (u Universe) AddImports(packagePath string, importPaths ...string) {
}
}
}
}
// Get (create if needed) the package.
// Package returns the Package for the given path.
// If a non-existing package is requested, this will create (a marker for) it.
// If a marker is created, it's the caller's responsibility to finish
// construction of the package.
func
(
u
Universe
)
Package
(
packagePath
string
)
*
Package
{
func
(
u
Universe
)
Package
(
packagePath
string
)
*
Package
{
if
p
,
ok
:=
u
[
packagePath
];
ok
{
if
p
,
ok
:=
u
[
packagePath
];
ok
{
return
p
return
p
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment