-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add global variable declarations
- Loading branch information
Showing
5 changed files
with
28 additions
and
3 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
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
18 changes: 18 additions & 0 deletions
18
NewSource/SocordiaC/Compilation/Listeners/CollectGlobalVariablesListener.cs
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,18 @@ | ||
namespace SocordiaC.Compilation.Listeners; | ||
|
||
public class CollectGlobalVariablesListener : Listeners<Driver, AstNode, VariableStatement> | ||
{ | ||
protected override void ListenToNode(Driver context, VariableStatement node) | ||
{ | ||
var type = context.GetFunctionType(context.GetNamespaceOf(node)); | ||
var varType = Utils.GetTypeFromNode(node.Type, type); | ||
var field = type.CreateField(node.Name, varType, FieldAttributes.Public | FieldAttributes.Static); | ||
|
||
Mappings.Variables.Add(node, field); | ||
} | ||
|
||
protected override bool ShouldListenToChildren(Driver context, VariableStatement node) | ||
{ | ||
return false; | ||
} | ||
} |
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 |
---|---|---|
|
@@ -5,6 +5,8 @@ public enum Color { | |
Blue | ||
} | ||
|
||
let defaultColor: Color; | ||
|
||
func main() | ||
{ | ||
let mut x = 12; | ||
|