Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Simplify Scope class hierarchy by favoring composition over inheritance.
- Loading branch information
Showing
3 changed files
with
166 additions
and
77 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
using System.Collections.Generic; | ||
using Rook.Compiling.Syntax; | ||
using Rook.Compiling.Types; | ||
|
||
namespace Rook.Compiling | ||
{ | ||
public class BindingDictionary | ||
{ | ||
private readonly IDictionary<string, DataType> bindings; | ||
|
||
public BindingDictionary() | ||
{ | ||
bindings = new Dictionary<string, DataType>(); | ||
} | ||
|
||
public DataType this[string identifier] | ||
{ | ||
set { bindings[identifier] = value; } | ||
} | ||
|
||
public bool TryIncludeUniqueBinding(Binding binding) | ||
{ | ||
if (Contains(binding.Identifier)) | ||
return false; | ||
|
||
bindings[binding.Identifier] = binding.Type; | ||
return true; | ||
} | ||
|
||
public bool TryGet(string identifier, out DataType type) | ||
{ | ||
if (Contains(identifier)) | ||
{ | ||
type = bindings[identifier]; | ||
return true; | ||
} | ||
|
||
type = null; | ||
return false; | ||
} | ||
|
||
public bool Contains(string identifier) | ||
{ | ||
return bindings.ContainsKey(identifier); | ||
} | ||
} | ||
} |
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