This repository has been archived by the owner on May 9, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Adds support for basic structs #25
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
84a4fc8
Added 'Struct' SyntaxNode.
armcburney 1a69807
Added tests for structs, fixed struct logic.
armcburney f51b924
Separated 'Variable' types to account for variables with and without …
armcburney c25e47a
Added qualifier for structs.
armcburney 9c7da31
Fixed struct source().
armcburney c11c221
Renamed 'Interface' to 'InterfaceVariable'.
armcburney File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 InterfaceVariable 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; | ||
this.variable = variable; | ||
} | ||
|
||
public declaration(): string { | ||
return `${this.qualifier} ${this.variable.declaration()}`; | ||
} | ||
|
||
public hashCode(): string { | ||
return this.declaration(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import InterfaceVariable from './interface'; | ||
import Qualifier from './qualifier'; | ||
import Set from './util/set'; | ||
import SyntaxNode from './syntaxnode'; | ||
import Variable from './variable'; | ||
|
||
/** | ||
* struct type-name { | ||
* members | ||
* }; | ||
*/ | ||
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<InterfaceVariable> { | ||
return new Set<InterfaceVariable>(); | ||
} | ||
|
||
public source(): string { | ||
return `${this.qualifier} struct ${this.name} {` + | ||
this.members | ||
.map(member => member.declaration()) | ||
.join('\n') + | ||
'};'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
import Variable from './variable'; | ||
import InterfaceVariable from './interface'; | ||
import Set from './util/set'; | ||
|
||
export default interface SyntaxNode { | ||
dependencies(): Set<Variable>; | ||
dependencies(): Set<InterfaceVariable>; | ||
source(): string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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};`; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
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 comment
The 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
readonly
). Also, I didn't want to breach the law of demeter.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.
I can change it if we want, but it would propagate to a lot of changes in the current code which utilizes the old
Variable
class. I was trying to go for "least amount of changes to other code" while creating this new class.