Skip to content

Commit

Permalink
Fix static field confusion; now statics work on classes but not pseud…
Browse files Browse the repository at this point in the history
…oclasses
  • Loading branch information
mcclure committed Aug 13, 2016
1 parent 1f23b01 commit d9dbbb6
Showing 1 changed file with 17 additions and 17 deletions.
34 changes: 17 additions & 17 deletions tools/dts2nim.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,9 +197,11 @@ interface TypeGen extends Gen {
typeString() : string
}

class IdentifierGen {
class IdentifierGen implements Gen {
constructor(public name:string, public type: TypeGen) {}

declString() : string { throw new Error("Tried to print declaration for abstract identifier base class") }

depends() { return arrayFilter(this.type.dependKey()) }
dependKey() { return this.name } // FIXME: Could variables live without these?
}
Expand All @@ -218,11 +220,9 @@ class ParameterGen extends IdentifierGen implements Gen {
}

class FieldGen extends IdentifierGen implements Gen {
declString(nameSpace: string = null) : string {
return `${identifierScrub(this.name, nameSpace)}*`
+ (nameSpace || needIdentifierScrub(this.name) ?
` {.importc:"${importIdentifier(this.name, nameSpace)}".}` :
"")
declString() : string {
return `${identifierScrub(this.name)}*`
+ (needIdentifierScrub(this.name) ? ` {.importc:"${importIdentifier(this.name)}".}` : "")
+ `: ${this.type.typeString()}`
}
}
Expand All @@ -242,12 +242,12 @@ class SignatureGen extends SignatureBase implements Gen { // Function signature
super(params, returnType)
}

declString() : string {
declString(nameSpace: string = null) : string {
let fullParams = (this.owner ? [new ParameterGen("self", this.owner)] : [])
.concat( this.params )
return `proc ${identifierScrub(this.name)}*(${params(fullParams)}) : `
return `proc ${identifierScrub(this.name, nameSpace)}*(${params(fullParams)}) : `
+ this.returnType.typeString()
+ ` {.${importDirective(this.name, !!this.owner)}.}`
+ ` {.${importDirective(this.name, !!this.owner, nameSpace)}.}`
}
dependKey() { return this.name }
}
Expand Down Expand Up @@ -298,7 +298,7 @@ class LiteralTypeGen implements TypeGen {
}

class MemberSpec {
constructor(public fields: FieldGen[], public methods: SignatureGen[]) {}
constructor(public fields: IdentifierGen[], public methods: SignatureGen[]) {}
}

class ClassGen implements TypeGen { // TODO: Make name optional?
Expand All @@ -311,7 +311,7 @@ class ClassGen implements TypeGen { // TODO: Make name optional?
invalid: boolean // Cannot be instantiated; do not store anywhere except the cache
suppress: boolean // Can and maybe has been instantiated, but shouldn't be output to file
constructor(public name: string, public abstract: boolean) {}
init(inherit:ClassGen, constructors: ConstructorGen[], fields: FieldGen[], methods: SignatureGen[], staticFields: FieldGen[], staticMethods: SignatureGen[]) {
init(inherit:ClassGen, constructors: ConstructorGen[], fields: IdentifierGen[], methods: SignatureGen[], staticFields: IdentifierGen[], staticMethods: SignatureGen[]) {
this.inherit = inherit
this.constructors = constructors
this.members = new MemberSpec(fields, methods)
Expand All @@ -332,7 +332,7 @@ class ClassGen implements TypeGen { // TODO: Make name optional?
+ (this.inherit ? identifierScrub(this.inherit.name) : "RootObj")
+ genJoinPrefixed(this.members.fields, "\n ")
+ genJoinPrefixed(fullMethods, "\n")
+ genJoinPrefixed(this.statics.fields, "\n ", this.name)
+ genJoinPrefixed(this.statics.fields, "\n", this.name)
+ genJoinPrefixed(this.statics.methods, "\n", this.name)
}
typeString() {
Expand Down Expand Up @@ -440,14 +440,14 @@ class GenVendor {
return spec
}

field(member: ts.Symbol, memberType: ts.Type, ownerName: string, inherit: ClassGen, isStatic = false) : FieldGen[] {
let fields : FieldGen[] = []
field(member: ts.Symbol, memberType: ts.Type, ownerName: string, inherit: ClassGen, isStatic = false) : IdentifierGen[] {
let fields : IdentifierGen[] = []
let staticTag = isStatic ? "static " : ""
try {
if (blacklisted("field", ownerName + "." + member.name))
warn(`Refusing to translate blacklisted ${staticTag}field ${member.name} of class ${ownerName}`)
else if (!(inherit && chainHasField(inherit, member.name)))
fields.push(new FieldGen(member.name, this.typeGen(memberType)))
fields.push(new (isStatic ? VariableGen : FieldGen)(member.name, this.typeGen(memberType)))
} catch (_e) {
let e:{} = _e
if (e instanceof UnusableType)
Expand Down Expand Up @@ -504,9 +504,9 @@ class GenVendor {
this.classes[name] = result

try {
let fields : FieldGen[] = []
let fields : IdentifierGen[] = []
let methods: SignatureGen[] = []
let staticFields : FieldGen [] = withStatics ? withStatics.fields.slice() : []
let staticFields : IdentifierGen [] = withStatics ? withStatics.fields.slice() : []
let staticMethods : SignatureGen [] = withStatics ? withStatics.methods.slice() : []
let constructors: ConstructorGen[] = withConstructors ? withConstructors.constructors.slice() : []
let foundConstructors = withConstructors ? withConstructors.foundConstructors : 0
Expand Down

0 comments on commit d9dbbb6

Please sign in to comment.