-
Notifications
You must be signed in to change notification settings - Fork 1
Adds support for basic structs #25
Changes from 5 commits
84a4fc8
1a69807
f51b924
c25e47a
9c7da31
c11c221
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import Hashable from './util/hashable'; | ||
import Qualifier from './qualifier'; | ||
import Type from './type'; | ||
import Variable from './variable'; | ||
|
||
export default class Interface implements Hashable { | ||
public readonly name: string; | ||
public readonly qualifier: Qualifier; | ||
public readonly kind: Type; | ||
private variable: Variable; | ||
|
||
// TODO: typecheck kind | ||
constructor(qualifier: Qualifier, variable: Variable) { | ||
this.qualifier = qualifier; | ||
this.name = variable.name; | ||
this.kind = variable.kind; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not just store the variable and read these off the variable? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I didn't want to expose the variable as part of the public interface (even if There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I can change it if we want, but it would propagate to a lot of changes in the current code which utilizes the old |
||
this.variable = variable; | ||
} | ||
|
||
public declaration(): string { | ||
return `${this.qualifier} ${this.variable.declaration()}`; | ||
} | ||
|
||
public hashCode(): string { | ||
return this.declaration(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import Interface from './interface'; | ||
import Qualifier from './qualifier'; | ||
import Set from './util/set'; | ||
import SyntaxNode from './syntaxnode'; | ||
import Variable from './variable'; | ||
|
||
/** | ||
* struct type-name { | ||
* members | ||
* } struct-name; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Correct me if I'm wrong but the
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oops, my bad - good catch There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. and also change the comment :) |
||
*/ | ||
export default class Struct implements SyntaxNode { | ||
public readonly name: string; | ||
public readonly qualifier: Qualifier; | ||
private members: Variable[]; | ||
|
||
constructor(qualifier: Qualifier, name: string, members: Variable[]) { | ||
this.qualifier = qualifier | ||
this.name = name; | ||
this.members = members; | ||
} | ||
|
||
public dependencies(): Set<Interface> { | ||
return new Set<Interface>(); | ||
} | ||
|
||
public source(): string { | ||
return `${this.qualifier} struct ${this.name} {` + | ||
this.members | ||
.map(member => member.declaration()) | ||
.join('\n') + | ||
'};'; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
import Variable from './variable'; | ||
import Interface from './interface'; | ||
import Set from './util/set'; | ||
|
||
export default interface SyntaxNode { | ||
dependencies(): Set<Variable>; | ||
dependencies(): Set<Interface>; | ||
source(): string; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,15 @@ | ||
import Qualifier from './qualifier'; | ||
import Type from './type'; | ||
import Hashable from './util/hashable'; | ||
|
||
export default class Variable implements Hashable { | ||
export default class Variable { | ||
public readonly name: string; | ||
public readonly qualifier: Qualifier; | ||
public readonly kind: Type; | ||
|
||
// TODO: typecheck kind | ||
constructor(qualifier: Qualifier, kind: Type, name: string) { | ||
constructor(kind: Type, name: string) { | ||
this.kind = kind; | ||
this.qualifier = qualifier; | ||
this.name = name; | ||
} | ||
|
||
public declaration(): string { | ||
return `${this.qualifier} ${this.kind} ${this.name};`; | ||
} | ||
|
||
public hashCode(): string { | ||
return this.declaration(); | ||
return `${this.kind} ${this.name};`; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we rename this class
InterfaceVariable
?Interface
is a really generic name.