Skip to content
Browse files

Merge pull request #229 from nikhilk/cc

cc branch
  • Loading branch information...
2 parents 38c79ea + d913500 commit 8e728ba46645200a48cdffb8b11fde0835aa62f2 @nikhilk committed Sep 6, 2012
Showing with 9,084 additions and 8 deletions.
  1. +1 −0 .gitignore
  2. BIN bin/ref/ScriptSharp.dll
  3. +4 −4 src/Core/App/App.csproj
  4. +4 −3 src/Core/Build/Build.csproj
  5. +1 −1 src/Core/Build/Generators/ResXCodeBuilder.cs
  6. +30 −0 src/Core/Compiler/CodeModel/Attributes/AttributeBlockNode.cs
  7. +67 −0 src/Core/Compiler/CodeModel/Attributes/AttributeNode.cs
  8. +33 −0 src/Core/Compiler/CodeModel/Attributes/AttributeTargets.cs
  9. +101 −0 src/Core/Compiler/CodeModel/CodeModelBuilder.cs
  10. +117 −0 src/Core/Compiler/CodeModel/CodeModelProcessor.cs
  11. +35 −0 src/Core/Compiler/CodeModel/Expressions/AnonymousMethodNode.cs
  12. +27 −0 src/Core/Compiler/CodeModel/Expressions/ArrayInitializerNode.cs
  13. +45 −0 src/Core/Compiler/CodeModel/Expressions/ArrayNewNode.cs
  14. +17 −0 src/Core/Compiler/CodeModel/Expressions/BaseNode.cs
  15. +42 −0 src/Core/Compiler/CodeModel/Expressions/BinaryExpressionNode.cs
  16. +34 −0 src/Core/Compiler/CodeModel/Expressions/CastNode.cs
  17. +42 −0 src/Core/Compiler/CodeModel/Expressions/ConditionalNode.cs
  18. +21 −0 src/Core/Compiler/CodeModel/Expressions/DefaultValueNode.cs
  19. +26 −0 src/Core/Compiler/CodeModel/Expressions/ExpressionListNode.cs
  20. +29 −0 src/Core/Compiler/CodeModel/Expressions/ExpressionNode.cs
  21. +45 −0 src/Core/Compiler/CodeModel/Expressions/LiteralNode.cs
  22. +37 −0 src/Core/Compiler/CodeModel/Expressions/NewNode.cs
  23. +21 −0 src/Core/Compiler/CodeModel/Expressions/SizeofNode.cs
  24. +23 −0 src/Core/Compiler/CodeModel/Expressions/StackAllocNode.cs
  25. +17 −0 src/Core/Compiler/CodeModel/Expressions/ThisNode.cs
  26. +26 −0 src/Core/Compiler/CodeModel/Expressions/TypeofNode.cs
  27. +32 −0 src/Core/Compiler/CodeModel/Expressions/UnaryExpressionNode.cs
  28. +34 −0 src/Core/Compiler/CodeModel/Expressions/VariableInitializerNode.cs
  29. +22 −0 src/Core/Compiler/CodeModel/IParseNodeHandler.cs
  30. +51 −0 src/Core/Compiler/CodeModel/Members/AccessorNode.cs
  31. +16 −0 src/Core/Compiler/CodeModel/Members/AccessorType.cs
  32. +22 −0 src/Core/Compiler/CodeModel/Members/ConstantFieldDeclarationNode.cs
  33. +42 −0 src/Core/Compiler/CodeModel/Members/ConstructorDeclarationNode.cs
  34. +23 −0 src/Core/Compiler/CodeModel/Members/DestructorDeclarationNode.cs
  35. +83 −0 src/Core/Compiler/CodeModel/Members/EnumerationFieldNode.cs
  36. +98 −0 src/Core/Compiler/CodeModel/Members/EventDeclarationNode.cs
  37. +82 −0 src/Core/Compiler/CodeModel/Members/FieldDeclarationNode.cs
  38. +40 −0 src/Core/Compiler/CodeModel/Members/IndexerDeclarationNode.cs
  39. +33 −0 src/Core/Compiler/CodeModel/Members/MemberNode.cs
  40. +98 −0 src/Core/Compiler/CodeModel/Members/MethodDeclarationNode.cs
  41. +27 −0 src/Core/Compiler/CodeModel/Members/OperatorDeclarationNode.cs
  42. +23 −0 src/Core/Compiler/CodeModel/Members/ParameterFlags.cs
  43. +54 −0 src/Core/Compiler/CodeModel/Members/ParameterNode.cs
  44. +99 −0 src/Core/Compiler/CodeModel/Members/PropertyDeclarationNode.cs
  45. +54 −0 src/Core/Compiler/CodeModel/Modifiers.cs
  46. +30 −0 src/Core/Compiler/CodeModel/Names/AliasQualifiedNameNode.cs
  47. +37 −0 src/Core/Compiler/CodeModel/Names/AtomicNameNode.cs
  48. +27 −0 src/Core/Compiler/CodeModel/Names/GenericNameNode.cs
  49. +27 −0 src/Core/Compiler/CodeModel/Names/MultiPartNameNode.cs
  50. +42 −0 src/Core/Compiler/CodeModel/Names/NameNode.cs
  51. +64 −0 src/Core/Compiler/CodeModel/ParseNode.cs
  52. +119 −0 src/Core/Compiler/CodeModel/ParseNodeList.cs
  53. +92 −0 src/Core/Compiler/CodeModel/ParseNodeType.cs
  54. +26 −0 src/Core/Compiler/CodeModel/Statements/BlockStatementNode.cs
  55. +17 −0 src/Core/Compiler/CodeModel/Statements/BreakNode.cs
  56. +26 −0 src/Core/Compiler/CodeModel/Statements/CaseLabelNode.cs
  57. +44 −0 src/Core/Compiler/CodeModel/Statements/CatchNode.cs
  58. +21 −0 src/Core/Compiler/CodeModel/Statements/CheckedNode.cs
  59. +21 −0 src/Core/Compiler/CodeModel/Statements/ConstantDeclarationNode.cs
  60. +17 −0 src/Core/Compiler/CodeModel/Statements/ContinueNode.cs
  61. +17 −0 src/Core/Compiler/CodeModel/Statements/DefaultLabelNode.cs
  62. +36 −0 src/Core/Compiler/CodeModel/Statements/DoWhileNode.cs
  63. +17 −0 src/Core/Compiler/CodeModel/Statements/EmptyStatementNode.cs
  64. +26 −0 src/Core/Compiler/CodeModel/Statements/ExpressionStatementNode.cs
  65. +25 −0 src/Core/Compiler/CodeModel/Statements/FixedNode.cs
  66. +54 −0 src/Core/Compiler/CodeModel/Statements/ForNode.cs
  67. +55 −0 src/Core/Compiler/CodeModel/Statements/ForeachNode.cs
  68. +21 −0 src/Core/Compiler/CodeModel/Statements/GotoNode.cs
  69. +45 −0 src/Core/Compiler/CodeModel/Statements/IfElseNode.cs
  70. +23 −0 src/Core/Compiler/CodeModel/Statements/LabeledStatementNode.cs
  71. +25 −0 src/Core/Compiler/CodeModel/Statements/LockNode.cs
  72. +26 −0 src/Core/Compiler/CodeModel/Statements/ReturnNode.cs
  73. +17 −0 src/Core/Compiler/CodeModel/Statements/StatementNode.cs
  74. +36 −0 src/Core/Compiler/CodeModel/Statements/SwitchNode.cs
  75. +36 −0 src/Core/Compiler/CodeModel/Statements/SwitchSectionNode.cs
  76. +26 −0 src/Core/Compiler/CodeModel/Statements/ThrowNode.cs
  77. +45 −0 src/Core/Compiler/CodeModel/Statements/TryNode.cs
  78. +21 −0 src/Core/Compiler/CodeModel/Statements/UncheckedNode.cs
  79. +21 −0 src/Core/Compiler/CodeModel/Statements/UnsafeNode.cs
  80. +25 −0 src/Core/Compiler/CodeModel/Statements/UsingNode.cs
  81. +66 −0 src/Core/Compiler/CodeModel/Statements/VariableDeclarationNode.cs
  82. +36 −0 src/Core/Compiler/CodeModel/Statements/WhileNode.cs
  83. +18 −0 src/Core/Compiler/CodeModel/Statements/YieldBreakNode.cs
  84. +21 −0 src/Core/Compiler/CodeModel/Statements/YieldReturnNode.cs
  85. +37 −0 src/Core/Compiler/CodeModel/Tokens/BooleanToken.cs
  86. +37 −0 src/Core/Compiler/CodeModel/Tokens/CharToken.cs
  87. +35 −0 src/Core/Compiler/CodeModel/Tokens/CommentToken.cs
  88. +18 −0 src/Core/Compiler/CodeModel/Tokens/CommentTokenType.cs
  89. +37 −0 src/Core/Compiler/CodeModel/Tokens/DecimalToken.cs
  90. +37 −0 src/Core/Compiler/CodeModel/Tokens/DoubleToken.cs
  91. +37 −0 src/Core/Compiler/CodeModel/Tokens/FloatToken.cs
  92. +47 −0 src/Core/Compiler/CodeModel/Tokens/IdentifierToken.cs
  93. +37 −0 src/Core/Compiler/CodeModel/Tokens/IntToken.cs
  94. +31 −0 src/Core/Compiler/CodeModel/Tokens/LiteralToken.cs
  95. +23 −0 src/Core/Compiler/CodeModel/Tokens/LiteralTokenType.cs
  96. +37 −0 src/Core/Compiler/CodeModel/Tokens/LongToken.cs
  97. +34 −0 src/Core/Compiler/CodeModel/Tokens/NullToken.cs
  98. +37 −0 src/Core/Compiler/CodeModel/Tokens/StringToken.cs
  99. +237 −0 src/Core/Compiler/CodeModel/Tokens/Token.cs
  100. +21 −0 src/Core/Compiler/CodeModel/Tokens/TokenFlags.cs
  101. +64 −0 src/Core/Compiler/CodeModel/Tokens/TokenInfo.cs
  102. +153 −0 src/Core/Compiler/CodeModel/Tokens/TokenType.cs
  103. +37 −0 src/Core/Compiler/CodeModel/Tokens/UIntToken.cs
  104. +37 −0 src/Core/Compiler/CodeModel/Tokens/ULongToken.cs
  105. +34 −0 src/Core/Compiler/CodeModel/Types/ArrayTypeNode.cs
  106. +68 −0 src/Core/Compiler/CodeModel/Types/CompilationUnitNode.cs
  107. +49 −0 src/Core/Compiler/CodeModel/Types/CustomTypeNode.cs
  108. +42 −0 src/Core/Compiler/CodeModel/Types/DelegateTypeNode.cs
  109. +21 −0 src/Core/Compiler/CodeModel/Types/ExternAliasNode.cs
  110. +35 −0 src/Core/Compiler/CodeModel/Types/IntrinsicTypeNode.cs
  111. +71 −0 src/Core/Compiler/CodeModel/Types/NamespaceNode.cs
  112. +21 −0 src/Core/Compiler/CodeModel/Types/PointerTypeNode.cs
  113. +17 −0 src/Core/Compiler/CodeModel/Types/TypeNode.cs
  114. +26 −0 src/Core/Compiler/CodeModel/Types/TypeParameterConstraintNode.cs
  115. +24 −0 src/Core/Compiler/CodeModel/Types/TypeParameterNode.cs
  116. +86 −0 src/Core/Compiler/CodeModel/Types/UserTypeNode.cs
  117. +35 −0 src/Core/Compiler/CodeModel/Types/UsingAliasNode.cs
  118. +27 −0 src/Core/Compiler/CodeModel/Types/UsingNamespaceNode.cs
  119. +490 −0 src/Core/Compiler/Compiler.csproj
  120. +190 −0 src/Core/Compiler/Compiler/CodeBuilder.cs
  121. +1,487 −0 src/Core/Compiler/Compiler/ExpressionBuilder.cs
  122. +248 −0 src/Core/Compiler/Compiler/ImplementationBuilder.cs
  123. +900 −0 src/Core/Compiler/Compiler/MetadataBuilder.cs
  124. +86 −0 src/Core/Compiler/Compiler/ResourcesBuilder.cs
  125. +399 −0 src/Core/Compiler/Compiler/StatementBuilder.cs
  126. +237 −0 src/Core/Compiler/CompilerOptions.cs
  127. +68 −0 src/Core/Compiler/Generator/CodeGenerator.cs
  128. +264 −0 src/Core/Compiler/Generator/DocCommentGenerator.cs
Sorry, we could not display the entire diff because too many files (594) changed.
View
1 .gitignore
@@ -6,3 +6,4 @@ obj/
*.trx
Scripts/
packages/
+TestResults/
View
BIN bin/ref/ScriptSharp.dll
Binary file not shown.
View
8 src/Core/App/App.csproj
@@ -40,10 +40,10 @@
<Reference Include="System" />
<Reference Include="Microsoft.Build.Framework" />
<Reference Include="Microsoft.Build.Utilities" />
- <Reference Include="ScriptSharp">
- <HintPath>..\..\..\bin\ref\ScriptSharp.dll</HintPath>
- <Private>True</Private>
- </Reference>
+ <ProjectReference Include="..\Compiler\Compiler.csproj">
+ <Project>{9f14036f-673f-418e-b817-7e2289d7f3f6}</Project>
+ <Name>Compiler</Name>
+ </ProjectReference>
</ItemGroup>
<ItemGroup>
<Compile Include="..\FileInputStreamSource.cs">
View
7 src/Core/Build/Build.csproj
@@ -38,9 +38,10 @@
<Reference Include="System.XML" />
<Reference Include="Microsoft.Build.Framework" />
<Reference Include="Microsoft.Build.Utilities" />
- <Reference Include="ScriptSharp">
- <HintPath>..\..\..\bin\ref\ScriptSharp.dll</HintPath>
- </Reference>
+ <ProjectReference Include="..\Compiler\Compiler.csproj">
+ <Project>{9f14036f-673f-418e-b817-7e2289d7f3f6}</Project>
+ <Name>Compiler</Name>
+ </ProjectReference>
</ItemGroup>
<ItemGroup>
<Compile Include="Properties\AssemblyInfo.cs" />
View
2 src/Core/Build/Generators/ResXCodeBuilder.cs
@@ -10,7 +10,7 @@
namespace ScriptSharp.Generators {
- internal sealed class ResXCodeBuilder {
+ public sealed class ResXCodeBuilder {
private static readonly string ResourcesHeader =
@"//------------------------------------------------------------------------------
View
30 src/Core/Compiler/CodeModel/Attributes/AttributeBlockNode.cs
@@ -0,0 +1,30 @@
+// AttributeBlockNode.cs
+// Script#/Core/Compiler
+// This source code is subject to terms and conditions of the Apache License, Version 2.0.
+//
+
+using System;
+using System.Diagnostics;
+
+namespace ScriptSharp.CodeModel {
+
+ internal sealed class AttributeBlockNode : ParseNode {
+
+ private AttributeTargets _location;
+ private ParseNodeList _attributes;
+
+ public AttributeBlockNode(Token token,
+ AttributeTargets location,
+ ParseNodeList attributes)
+ : base(ParseNodeType.AttributeBlock, token) {
+ _location = location;
+ _attributes = GetParentedNodeList(attributes);
+ }
+
+ public ParseNodeList Attributes {
+ get {
+ return _attributes;
+ }
+ }
+ }
+}
View
67 src/Core/Compiler/CodeModel/Attributes/AttributeNode.cs
@@ -0,0 +1,67 @@
+// AttributeNode.cs
+// Script#/Core/Compiler
+// This source code is subject to terms and conditions of the Apache License, Version 2.0.
+//
+
+using System;
+using System.Diagnostics;
+
+namespace ScriptSharp.CodeModel {
+
+ internal sealed class AttributeNode : ParseNode {
+
+ private NameNode _typeName;
+ private ParseNode _arguments;
+
+ public AttributeNode(NameNode typeName, ParseNode arguments)
+ : base(ParseNodeType.Attribute, typeName.token) {
+ _typeName = (NameNode)GetParentedNode(typeName);
+ _arguments = GetParentedNode(arguments);
+ }
+
+ public ParseNodeList Arguments {
+ get {
+ if (_arguments != null) {
+ return ((ExpressionListNode)_arguments).Expressions;
+ }
+ return null;
+ }
+ }
+
+ public string TypeName {
+ get {
+ return _typeName.Name;
+ }
+ }
+
+ public static AttributeNode FindAttribute(ParseNodeList attributeNodes, string attributeName) {
+ if ((attributeNodes == null) || (attributeNodes.Count == 0)) {
+ return null;
+ }
+
+ foreach (AttributeNode attrNode in attributeNodes) {
+ if (attrNode.TypeName.Equals(attributeName, StringComparison.Ordinal)) {
+ return attrNode;
+ }
+ }
+
+ return null;
+ }
+
+ public static ParseNodeList GetAttributeList(ParseNodeList attributeBlocks) {
+ if ((attributeBlocks == null) || (attributeBlocks.Count == 0)) {
+ return attributeBlocks;
+ }
+
+ ParseNodeList attributes = new ParseNodeList();
+ foreach (AttributeBlockNode attributeBlock in attributeBlocks) {
+ ParseNodeList localAttributes = attributeBlock.Attributes;
+ if (localAttributes.Count != 0) {
+ attributes.Append(localAttributes);
+ }
+ }
+
+ return attributes;
+ }
+ }
+}
View
33 src/Core/Compiler/CodeModel/Attributes/AttributeTargets.cs
@@ -0,0 +1,33 @@
+// AttributeTargets.cs
+// Script#/Core/Compiler
+// This source code is subject to terms and conditions of the Apache License, Version 2.0.
+//
+
+using System;
+
+namespace ScriptSharp.CodeModel {
+
+ /// <summary>
+ /// Locations which an attribute section can target.
+ /// </summary>
+ internal enum AttributeTargets {
+
+ Assembly,
+
+ Field,
+
+ Event,
+
+ Method,
+
+ Module,
+
+ Param,
+
+ Property,
+
+ Return,
+
+ Type
+ }
+}
View
101 src/Core/Compiler/CodeModel/CodeModelBuilder.cs
@@ -0,0 +1,101 @@
+// CodeModelBuilder.cs
+// Script#/Core/Compiler
+// This source code is subject to terms and conditions of the Apache License, Version 2.0.
+//
+
+using System;
+using System.Collections;
+using System.Collections.Generic;
+using System.Diagnostics;
+using System.IO;
+using ScriptSharp;
+using ScriptSharp.Parser;
+
+namespace ScriptSharp.CodeModel {
+
+ internal sealed class CodeModelBuilder {
+
+ private CompilerOptions _options;
+ private IErrorHandler _errorHandler;
+
+ private bool _hasErrors;
+
+ public CodeModelBuilder(CompilerOptions options, IErrorHandler errorHandler) {
+ _options = options;
+ _errorHandler = errorHandler;
+ }
+
+ public CompilationUnitNode BuildCodeModel(IStreamSource source) {
+ _hasErrors = false;
+
+ string filePath = source.FullName;
+#if DEBUG
+ if (_options.InternalTestMode) {
+ // This ensures in file paths are just file names in test output.
+ filePath = Path.GetFileName(filePath);
+ }
+#endif // DEBUG
+ char[] buffer = GetBuffer(source);
+ if (buffer == null) {
+ _errorHandler.ReportError("Unable to read from file " + filePath, filePath);
+ return null;
+ }
+
+ IDictionary definesTable = new Hashtable();
+ if ((_options.Defines != null) && (_options.Defines.Count != 0)) {
+ foreach (string s in _options.Defines) {
+ definesTable[s] = null;
+ }
+ }
+
+ NameTable nameTable = new NameTable();
+ LineMap lineMap = new LineMap(filePath);
+
+ FileLexer lexer = new FileLexer(nameTable, filePath);
+ lexer.OnError += new FileErrorEventHandler(OnError);
+ Token[] tokens = lexer.Lex(buffer, definesTable, lineMap, /* includeComments */ false);
+
+ if (_hasErrors == false) {
+ FileParser parser = new FileParser(nameTable, filePath);
+ parser.OnError += new FileErrorEventHandler(OnError);
+
+ CompilationUnitNode compilationUnit = parser.Parse(tokens, lineMap);
+ foreach (ParseNode node in compilationUnit.Members) {
+ NamespaceNode namespaceNode = node as NamespaceNode;
+ if (namespaceNode != null) {
+ namespaceNode.IncludeCompilationUnitUsingClauses();
+ }
+ }
+
+ if (_hasErrors == false) {
+ return compilationUnit;
+ }
+ }
+
+ return null;
+ }
+
+ private char[] GetBuffer(IStreamSource source) {
+ char[] buffer = null;
+
+ Stream stream = source.GetStream();
+ if (stream != null) {
+ StreamReader reader = new StreamReader(stream);
+ string text = reader.ReadToEnd();
+
+ buffer = text.ToCharArray();
+ source.CloseStream(stream);
+ }
+ return buffer;
+ }
+
+ private void OnError(object sender, FileErrorEventArgs e) {
+ _hasErrors = true;
+
+ string location = e.Position.ToString();
+ string message = String.Format(e.Error.Message, e.Args);
+
+ _errorHandler.ReportError(message, location);
+ }
+ }
+}
View
117 src/Core/Compiler/CodeModel/CodeModelProcessor.cs
@@ -0,0 +1,117 @@
+// CodeModelProcessor.cs
+// Script#/Core/Compiler
+// This source code is subject to terms and conditions of the Apache License, Version 2.0.
+//
+
+using System;
+using System.Diagnostics;
+using System.Reflection;
+
+namespace ScriptSharp.CodeModel {
+
+ internal sealed class CodeModelProcessor {
+
+ private IParseNodeHandler _nodeHandler;
+ private object _context;
+ private bool _notifyChildren;
+
+ public CodeModelProcessor(IParseNodeHandler nodeHandler, object context) {
+ _nodeHandler = nodeHandler;
+ _context = context;
+ _notifyChildren = nodeHandler.RequiresChildrenGrouping;
+ }
+
+ private void EndChildren() {
+ if (_notifyChildren) {
+ _nodeHandler.EndChildren();
+ }
+ }
+
+ public void Process(ParseNode node) {
+ Visit(node);
+ }
+
+ private bool ProcessNode(ParseNode node) {
+ return _nodeHandler.HandleNode(node, _context);
+ }
+
+ private void StartChildren(string identifier) {
+ if (_notifyChildren) {
+ _nodeHandler.StartChildren(identifier);
+ }
+ }
+
+ private void Visit(ParseNode node) {
+ bool recurse = ProcessNode(node);
+
+ if (recurse) {
+ StartChildren(String.Empty);
+
+ Type nodeType = node.GetType();
+ foreach (PropertyInfo propertyInfo in nodeType.GetProperties()) {
+ string propertyName = propertyInfo.Name;
+ if (propertyName.Equals("NodeType")) {
+ continue;
+ }
+ if (propertyName.Equals("Parent")) {
+ continue;
+ }
+ if (propertyName.Equals("Token")) {
+ continue;
+ }
+
+ Visit(node, propertyInfo);
+ }
+
+ EndChildren();
+ }
+ }
+
+ private void Visit(ParseNode node, PropertyInfo propertyInfo) {
+ string name = propertyInfo.Name;
+ object value = propertyInfo.GetValue(node, null);
+
+ string text = name + " (" + propertyInfo.PropertyType.Name + ")";
+
+ if (value != null) {
+ if (value is ParseNodeList) {
+ ParseNodeList nodeList = (ParseNodeList)value;
+
+ if (nodeList.Count == 0) {
+ text += " : Empty";
+ }
+ else {
+ text += " : " + nodeList.Count.ToString();
+ }
+
+ StartChildren(text);
+ foreach (ParseNode nodeItem in nodeList) {
+ Visit(nodeItem);
+ }
+ EndChildren();
+ }
+ else if (value is ParseNode) {
+ StartChildren(text);
+ Visit((ParseNode)value);
+ EndChildren();
+ }
+ else {
+ if (value is string) {
+ text += " : \"" + (string)value + "\"";
+ }
+ else {
+ text += " : " + value.ToString();
+ }
+
+ StartChildren(text);
+ EndChildren();
+ }
+ }
+ else {
+ text += " : null";
+ StartChildren(text);
+ EndChildren();
+ }
+ }
+ }
+}
View
35 src/Core/Compiler/CodeModel/Expressions/AnonymousMethodNode.cs
@@ -0,0 +1,35 @@
+// AnonymousMethodNode.cs
+// Script#/Core/Compiler
+// This source code is subject to terms and conditions of the Apache License, Version 2.0.
+//
+
+using System;
+using System.Diagnostics;
+
+namespace ScriptSharp.CodeModel {
+
+ // NOTE: Not supported in conversion
+ internal sealed class AnonymousMethodNode : ExpressionNode {
+
+ private ParseNodeList _parameterList;
+ private BlockStatementNode _block;
+
+ public AnonymousMethodNode(Token token, ParseNodeList parameterList, BlockStatementNode block)
+ : base(ParseNodeType.AnonymousMethod, token) {
+ _parameterList = GetParentedNodeList(parameterList);
+ _block = (BlockStatementNode)GetParentedNode(block);
+ }
+
+ public BlockStatementNode Implementation {
+ get {
+ return _block;
+ }
+ }
+
+ public ParseNodeList Parameters {
+ get {
+ return _parameterList;
+ }
+ }
+ }
+}
View
27 src/Core/Compiler/CodeModel/Expressions/ArrayInitializerNode.cs
@@ -0,0 +1,27 @@
+// ArrayInitializerNode.cs
+// Script#/Core/Compiler
+// This source code is subject to terms and conditions of the Apache License, Version 2.0.
+//
+
+using System;
+using System.Diagnostics;
+
+namespace ScriptSharp.CodeModel {
+
+ internal sealed class ArrayInitializerNode : ExpressionNode {
+
+ private ParseNodeList _values;
+
+ public ArrayInitializerNode(Token token,
+ ParseNodeList values)
+ : base(ParseNodeType.ArrayInitializer, token) {
+ _values = GetParentedNodeList(values);
+ }
+
+ public ParseNodeList Values {
+ get {
+ return _values;
+ }
+ }
+ }
+}
View
45 src/Core/Compiler/CodeModel/Expressions/ArrayNewNode.cs
@@ -0,0 +1,45 @@
+// ArrayNewNode.cs
+// Script#/Core/Compiler
+// This source code is subject to terms and conditions of the Apache License, Version 2.0.
+//
+
+using System;
+using System.Diagnostics;
+
+namespace ScriptSharp.CodeModel {
+
+ internal sealed class ArrayNewNode : ExpressionNode {
+
+ private ParseNode _typeReference;
+ private ParseNode _expressionList;
+ private ParseNode _initializerExpression;
+
+ public ArrayNewNode(Token token,
+ ParseNode typeReference,
+ ParseNode expressionList,
+ ParseNode initializerExpression)
+ : base(ParseNodeType.ArrayNew, token) {
+ _typeReference = GetParentedNode(typeReference);
+ _expressionList = GetParentedNode(expressionList);
+ _initializerExpression = GetParentedNode(initializerExpression);
+ }
+
+ public ParseNode ExpressionList {
+ get {
+ return _expressionList;
+ }
+ }
+
+ public ParseNode InitializerExpression {
+ get {
+ return _initializerExpression;
+ }
+ }
+
+ public ParseNode TypeReference {
+ get {
+ return _typeReference;
+ }
+ }
+ }
+}
View
17 src/Core/Compiler/CodeModel/Expressions/BaseNode.cs
@@ -0,0 +1,17 @@
+// BaseNode.cs
+// Script#/Core/Compiler
+// This source code is subject to terms and conditions of the Apache License, Version 2.0.
+//
+
+using System;
+using System.Diagnostics;
+
+namespace ScriptSharp.CodeModel {
+
+ internal sealed class BaseNode : ExpressionNode {
+
+ public BaseNode(Token token)
+ : base(ParseNodeType.Base, token) {
+ }
+ }
+}
View
42 src/Core/Compiler/CodeModel/Expressions/BinaryExpressionNode.cs
@@ -0,0 +1,42 @@
+// ExpressionNode.cs
+// Script#/Core/Compiler
+// This source code is subject to terms and conditions of the Apache License, Version 2.0.
+//
+
+using System;
+using System.Diagnostics;
+
+namespace ScriptSharp.CodeModel {
+
+ internal sealed class BinaryExpressionNode : ExpressionNode {
+
+ private TokenType _operatorType;
+ private ParseNode _leftChild;
+ private ParseNode _rightChild;
+
+ public BinaryExpressionNode(ParseNode leftChild, TokenType operatorType, ParseNode rightChild)
+ : base(ParseNodeType.BinaryExpression, leftChild.token) {
+ _leftChild = GetParentedNode(leftChild);
+ _operatorType = operatorType;
+ _rightChild = GetParentedNode(rightChild);
+ }
+
+ public ParseNode LeftChild {
+ get {
+ return _leftChild;
+ }
+ }
+
+ public TokenType Operator {
+ get {
+ return _operatorType;
+ }
+ }
+
+ public ParseNode RightChild {
+ get {
+ return _rightChild;
+ }
+ }
+ }
+}
View
34 src/Core/Compiler/CodeModel/Expressions/CastNode.cs
@@ -0,0 +1,34 @@
+// CastNode.cs
+// Script#/Core/Compiler
+// This source code is subject to terms and conditions of the Apache License, Version 2.0.
+//
+
+using System;
+using System.Diagnostics;
+
+namespace ScriptSharp.CodeModel {
+
+ internal sealed class CastNode : ExpressionNode {
+
+ private ParseNode _typeReference;
+ private ParseNode _child;
+
+ public CastNode(Token token, ParseNode typeReference, ParseNode child)
+ : base(ParseNodeType.Cast, token) {
+ _typeReference = GetParentedNode(typeReference);
+ _child = GetParentedNode(child);
+ }
+
+ public ParseNode Child {
+ get {
+ return _child;
+ }
+ }
+
+ public ParseNode TypeReference {
+ get {
+ return _typeReference;
+ }
+ }
+ }
+}
View
42 src/Core/Compiler/CodeModel/Expressions/ConditionalNode.cs
@@ -0,0 +1,42 @@
+// ConditionalNode.cs
+// Script#/Core/Compiler
+// This source code is subject to terms and conditions of the Apache License, Version 2.0.
+//
+
+using System;
+using System.Diagnostics;
+
+namespace ScriptSharp.CodeModel {
+
+ internal sealed class ConditionalNode : ExpressionNode {
+
+ private ParseNode _condition;
+ private ParseNode _trueValue;
+ private ParseNode _falseValue;
+
+ public ConditionalNode(ParseNode condition, ParseNode trueValue, ParseNode falseValue)
+ : base(ParseNodeType.Conditional, condition.token) {
+ _condition = GetParentedNode(condition);
+ _trueValue = GetParentedNode(trueValue);
+ _falseValue = GetParentedNode(falseValue);
+ }
+
+ public ParseNode Condition {
+ get {
+ return _condition;
+ }
+ }
+
+ public ParseNode FalseValue {
+ get {
+ return _falseValue;
+ }
+ }
+
+ public ParseNode TrueValue {
+ get {
+ return _trueValue;
+ }
+ }
+ }
+}
View
21 src/Core/Compiler/CodeModel/Expressions/DefaultValueNode.cs
@@ -0,0 +1,21 @@
+// ExpressionNode.cs
+// Script#/Core/Compiler
+// This source code is subject to terms and conditions of the Apache License, Version 2.0.
+//
+
+using System;
+using System.Diagnostics;
+
+namespace ScriptSharp.CodeModel {
+
+ // NOTE: Not supported in conversion
+ internal sealed class DefaultValueNode : ExpressionNode {
+
+ public ParseNode _expression;
+
+ public DefaultValueNode(ParseNode expression)
+ : base(ParseNodeType.DefaultValueExpression, expression.token) {
+ _expression = expression;
+ }
+ }
+}
View
26 src/Core/Compiler/CodeModel/Expressions/ExpressionListNode.cs
@@ -0,0 +1,26 @@
+// ExpressionListNode.cs
+// Script#/Core/Compiler
+// This source code is subject to terms and conditions of the Apache License, Version 2.0.
+//
+
+using System;
+using System.Diagnostics;
+
+namespace ScriptSharp.CodeModel {
+
+ internal sealed class ExpressionListNode : ParseNode {
+
+ private ParseNodeList _expressions;
+
+ public ExpressionListNode(Token token, ParseNodeList expressions)
+ : base(ParseNodeType.ExpressionList, token) {
+ _expressions = GetParentedNodeList(expressions);
+ }
+
+ public ParseNodeList Expressions {
+ get {
+ return _expressions;
+ }
+ }
+ }
+}
View
29 src/Core/Compiler/CodeModel/Expressions/ExpressionNode.cs
@@ -0,0 +1,29 @@
+// ExpressionNode.cs
+// Script#/Core/Compiler
+// This source code is subject to terms and conditions of the Apache License, Version 2.0.
+//
+
+using System;
+using System.Diagnostics;
+
+namespace ScriptSharp.CodeModel {
+
+ internal abstract class ExpressionNode : ParseNode {
+
+ private bool _parenthesized;
+
+ protected ExpressionNode(ParseNodeType nodeType, Token token)
+ : base(nodeType, token) {
+ }
+
+ public bool Parenthesized {
+ get {
+ return _parenthesized;
+ }
+ }
+
+ public void AddParenthesisHint() {
+ _parenthesized = true;
+ }
+ }
+}
View
45 src/Core/Compiler/CodeModel/Expressions/LiteralNode.cs
@@ -0,0 +1,45 @@
+// LiteralNode.cs
+// Script#/Core/Compiler
+// This source code is subject to terms and conditions of the Apache License, Version 2.0.
+//
+
+using System;
+using System.Diagnostics;
+
+namespace ScriptSharp.CodeModel {
+
+ internal sealed class LiteralNode : ExpressionNode {
+
+ public LiteralNode(Token token)
+ : base(ParseNodeType.Literal, CreateLiteralToken(token)) {
+ }
+
+ public LiteralToken Literal {
+ get {
+ return (LiteralToken)Token;
+ }
+ }
+
+ public object Value {
+ get {
+ return ((LiteralToken)Token).LiteralValue;
+ }
+ }
+
+ private static LiteralToken CreateLiteralToken(Token token) {
+ if (token.Type == TokenType.Null) {
+ return new NullToken(token.SourcePath, token.Position);
+ }
+ else if (token.Type == TokenType.True) {
+ return new BooleanToken(true, token.SourcePath, token.Position);
+ }
+ else if (token.Type == TokenType.False) {
+ return new BooleanToken(false, token.SourcePath, token.Position);
+ }
+ else {
+ Debug.Assert(token is LiteralToken);
+ return (LiteralToken)token;
+ }
+ }
+ }
+}
View
37 src/Core/Compiler/CodeModel/Expressions/NewNode.cs
@@ -0,0 +1,37 @@
+// NewNode.cs
+// Script#/Core/Compiler
+// This source code is subject to terms and conditions of the Apache License, Version 2.0.
+//
+
+using System;
+using System.Diagnostics;
+
+namespace ScriptSharp.CodeModel {
+
+ internal sealed class NewNode : ExpressionNode {
+
+ private ParseNode _typeReference;
+ private ParseNode _arguments;
+
+ public NewNode(Token token, ParseNode typeReference, ParseNode arguments)
+ : base(ParseNodeType.New, token) {
+ _typeReference = GetParentedNode(typeReference);
+ _arguments = GetParentedNode(arguments);
+ }
+
+ public ParseNode Arguments {
+ get {
+ return _arguments;
+ }
+ }
+
+ public ParseNode TypeReference {
+ get {
+ return _typeReference;
+ }
+ set {
+ _typeReference = value;
+ }
+ }
+ }
+}
View
21 src/Core/Compiler/CodeModel/Expressions/SizeofNode.cs
@@ -0,0 +1,21 @@
+// ExpressionNode.cs
+// Script#/Core/Compiler
+// This source code is subject to terms and conditions of the Apache License, Version 2.0.
+//
+
+using System;
+using System.Diagnostics;
+
+namespace ScriptSharp.CodeModel {
+
+ // NOTE: Not supported in conversion
+ internal class SizeofNode : ExpressionNode {
+
+ private ParseNode _typeNode;
+
+ public SizeofNode(Token op, ParseNode typeNode)
+ : base(ParseNodeType.Sizeof, op) {
+ _typeNode = GetParentedNode(typeNode);
+ }
+ }
+}
View
23 src/Core/Compiler/CodeModel/Expressions/StackAllocNode.cs
@@ -0,0 +1,23 @@
+// StackAllocNode.cs
+// Script#/Core/Compiler
+// This source code is subject to terms and conditions of the Apache License, Version 2.0.
+//
+
+using System;
+using System.Diagnostics;
+
+namespace ScriptSharp.CodeModel {
+
+ // NOTE: Not supported in conversion
+ internal sealed class StackAllocNode : ExpressionNode {
+
+ private ParseNode _type;
+ private ParseNode _numberOfElements;
+
+ public StackAllocNode(Token token, ParseNode type, ParseNode numberOfElements)
+ : base(ParseNodeType.StackAlloc, token) {
+ _type = GetParentedNode(type);
+ _numberOfElements = GetParentedNode(numberOfElements);
+ }
+ }
+}
View
17 src/Core/Compiler/CodeModel/Expressions/ThisNode.cs
@@ -0,0 +1,17 @@
+// ThisNode.cs
+// Script#/Core/Compiler
+// This source code is subject to terms and conditions of the Apache License, Version 2.0.
+//
+
+using System;
+using System.Diagnostics;
+
+namespace ScriptSharp.CodeModel {
+
+ internal sealed class ThisNode : ExpressionNode {
+
+ public ThisNode(Token token)
+ : base(ParseNodeType.This, token) {
+ }
+ }
+}
View
26 src/Core/Compiler/CodeModel/Expressions/TypeofNode.cs
@@ -0,0 +1,26 @@
+// TypeofNode.cs
+// Script#/Core/Compiler
+// This source code is subject to terms and conditions of the Apache License, Version 2.0.
+//
+
+using System;
+using System.Diagnostics;
+
+namespace ScriptSharp.CodeModel {
+
+ internal sealed class TypeofNode : ExpressionNode {
+
+ private ParseNode _typeReference;
+
+ public TypeofNode(Token op, ParseNode typeReference)
+ : base(ParseNodeType.Typeof, op) {
+ _typeReference = GetParentedNode(typeReference);
+ }
+
+ public ParseNode TypeReference {
+ get {
+ return _typeReference;
+ }
+ }
+ }
+}
View
32 src/Core/Compiler/CodeModel/Expressions/UnaryExpressionNode.cs
@@ -0,0 +1,32 @@
+// UnaryExpressionNode.cs
+// Script#/Core/Compiler
+// This source code is subject to terms and conditions of the Apache License, Version 2.0.
+//
+
+using System;
+using System.Diagnostics;
+
+namespace ScriptSharp.CodeModel {
+
+ internal sealed class UnaryExpressionNode : ExpressionNode {
+
+ private ParseNode _child;
+
+ public UnaryExpressionNode(Token op, ParseNode child)
+ : base(ParseNodeType.UnaryExpression, op) {
+ _child = GetParentedNode(child);
+ }
+
+ public ParseNode Child {
+ get {
+ return _child;
+ }
+ }
+
+ public TokenType Operator {
+ get {
+ return Token.Type;
+ }
+ }
+ }
+}
View
34 src/Core/Compiler/CodeModel/Expressions/VariableInitializerNode.cs
@@ -0,0 +1,34 @@
+// VariableInitializerNode.cs
+// Script#/Core/Compiler
+// This source code is subject to terms and conditions of the Apache License, Version 2.0.
+//
+
+using System;
+using System.Diagnostics;
+
+namespace ScriptSharp.CodeModel {
+
+ internal sealed class VariableInitializerNode : ExpressionNode {
+
+ private AtomicNameNode _name;
+ private ParseNode _value;
+
+ public VariableInitializerNode(AtomicNameNode name, ParseNode value)
+ : base(ParseNodeType.VariableDeclarator, name.token) {
+ _name = (AtomicNameNode)GetParentedNode(name);
+ _value = GetParentedNode(value);
+ }
+
+ public AtomicNameNode Name {
+ get {
+ return _name;
+ }
+ }
+
+ public ParseNode Value {
+ get {
+ return _value;
+ }
+ }
+ }
+}
View
22 src/Core/Compiler/CodeModel/IParseNodeHandler.cs
@@ -0,0 +1,22 @@
+// IParseNodeHandler.cs
+// Script#/Core/Compiler
+// This source code is subject to terms and conditions of the Apache License, Version 2.0.
+//
+
+using System;
+
+namespace ScriptSharp.CodeModel {
+
+ internal interface IParseNodeHandler {
+
+ bool RequiresChildrenGrouping {
+ get;
+ }
+
+ bool HandleNode(ParseNode node, object context);
+
+ void StartChildren(string identifier);
+
+ void EndChildren();
+ }
+}
View
51 src/Core/Compiler/CodeModel/Members/AccessorNode.cs
@@ -0,0 +1,51 @@
+// AccessorNode.cs
+// Script#/Core/Compiler
+// This source code is subject to terms and conditions of the Apache License, Version 2.0.
+//
+
+using System;
+using System.Diagnostics;
+
+namespace ScriptSharp.CodeModel {
+
+ internal sealed class AccessorNode : ParseNode {
+
+ private AtomicNameNode _name;
+ private BlockStatementNode _implementation;
+ private ParseNodeList _attributes;
+ private Modifiers _modifiers;
+
+ public AccessorNode(Token token,
+ ParseNodeList attributes,
+ AtomicNameNode name,
+ BlockStatementNode body,
+ Modifiers modifiers)
+ : base(ParseNodeType.AccessorDeclaration, token) {
+ _name = (AtomicNameNode)GetParentedNode(name);
+ _implementation = (BlockStatementNode)GetParentedNode(body);
+ _attributes = GetParentedNodeList(attributes);
+ _modifiers = modifiers;
+ }
+
+ public BlockStatementNode Implementation {
+ get {
+ return _implementation;
+ }
+ }
+
+ public Modifiers Modifiers {
+ get {
+ return _modifiers;
+ }
+ }
+
+ public AccessorType Type {
+ get {
+ if (_name.Name.Equals("get")) {
+ return AccessorType.Get;
+ }
+ return AccessorType.Set;
+ }
+ }
+ }
+}
View
16 src/Core/Compiler/CodeModel/Members/AccessorType.cs
@@ -0,0 +1,16 @@
+// Accessor.cs
+// Script#/Core/Compiler
+// This source code is subject to terms and conditions of the Apache License, Version 2.0.
+//
+
+using System;
+
+namespace ScriptSharp.CodeModel {
+
+ internal enum AccessorType {
+
+ Get = 0,
+
+ Set = 1
+ }
+}
View
22 src/Core/Compiler/CodeModel/Members/ConstantFieldDeclarationNode.cs
@@ -0,0 +1,22 @@
+// ConstantFieldDeclarationNode.cs
+// Script#/Core/Compiler
+// This source code is subject to terms and conditions of the Apache License, Version 2.0.
+//
+
+using System;
+using System.Collections;
+using System.Diagnostics;
+
+namespace ScriptSharp.CodeModel {
+
+ internal class ConstantFieldDeclarationNode : FieldDeclarationNode {
+
+ public ConstantFieldDeclarationNode(Token token,
+ ParseNodeList attributes,
+ Modifiers modifiers,
+ ParseNode type,
+ ParseNodeList initializers)
+ : base(ParseNodeType.ConstFieldDeclaration, token, attributes, modifiers, type, initializers, false) {
+ }
+ }
+}
View
42 src/Core/Compiler/CodeModel/Members/ConstructorDeclarationNode.cs
@@ -0,0 +1,42 @@
+// ConstructorDeclarationNode.cs
+// Script#/Core/Compiler
+// This source code is subject to terms and conditions of the Apache License, Version 2.0.
+//
+
+using System;
+using System.Collections;
+using System.Diagnostics;
+
+namespace ScriptSharp.CodeModel {
+
+ internal sealed class ConstructorDeclarationNode : MethodDeclarationNode {
+
+ private bool _callBase;
+ private ParseNode _baseArguments;
+
+ public ConstructorDeclarationNode(Token token,
+ ParseNodeList attributes,
+ Modifiers modifiers,
+ AtomicNameNode name,
+ ParseNodeList formals,
+ bool callBase,
+ ParseNode baseArguments,
+ BlockStatementNode body)
+ : base(ParseNodeType.ConstructorDeclaration, token, attributes, modifiers, /* return type */ null, name, formals, body) {
+ _callBase = callBase;
+ _baseArguments = GetParentedNode(baseArguments);
+ }
+
+ public ParseNode BaseArguments {
+ get {
+ return _baseArguments;
+ }
+ }
+
+ public bool CallBase {
+ get {
+ return _callBase;
+ }
+ }
+ }
+}
View
23 src/Core/Compiler/CodeModel/Members/DestructorDeclarationNode.cs
@@ -0,0 +1,23 @@
+// DestructorDeclarationNode.cs
+// Script#/Core/Compiler
+// This source code is subject to terms and conditions of the Apache License, Version 2.0.
+//
+
+using System;
+using System.Collections;
+using System.Diagnostics;
+
+namespace ScriptSharp.CodeModel {
+
+ // NOTE: Not supported in conversion
+ internal sealed class DestructorDeclarationNode : MethodDeclarationNode {
+
+ public DestructorDeclarationNode(Token token,
+ ParseNodeList attributes,
+ Modifiers modifiers,
+ AtomicNameNode name,
+ BlockStatementNode body)
+ : base(ParseNodeType.DestructorDeclaration, token, attributes, modifiers, /* return type */ null, name, new ParseNodeList(), body) {
+ }
+ }
+}
View
83 src/Core/Compiler/CodeModel/Members/EnumerationFieldNode.cs
@@ -0,0 +1,83 @@
+// EnumerationFieldNode.cs
+// Script#/Core/Compiler
+// This source code is subject to terms and conditions of the Apache License, Version 2.0.
+//
+
+using System;
+using System.Collections;
+using System.Diagnostics;
+
+namespace ScriptSharp.CodeModel {
+
+ internal class EnumerationFieldNode : MemberNode {
+
+ private ParseNodeList _attributes;
+ private AtomicNameNode _name;
+ private object _value;
+
+ public EnumerationFieldNode(ParseNodeList attributes, AtomicNameNode name,
+ ParseNode value)
+ : base(ParseNodeType.EnumerationFieldDeclaration, name.token) {
+ _attributes = GetParentedNodeList(AttributeNode.GetAttributeList(attributes));
+ _name = (AtomicNameNode)GetParentedNode(name);
+
+ if (value is LiteralNode) {
+ LiteralNode literalNode = (LiteralNode)value;
+ _value = ((LiteralToken)literalNode.Token).LiteralValue;
+ }
+ else {
+ // TODO: Clearly we need something more general...
+ // C# allows expressions. Likely expressions to be used
+ // include negative values, binary OR'd values,
+ // expressions involving other enum members (esp. hard to deal with)
+ // For now, just adding support for negative numbers, as
+ // everything else can be worked around in source code.
+
+ UnaryExpressionNode expressionNode = value as UnaryExpressionNode;
+ if ((expressionNode != null) && (expressionNode.Operator == TokenType.Minus) &&
+ (expressionNode.Child is LiteralNode)) {
+
+ try {
+ LiteralToken literalToken =
+ (LiteralToken)((LiteralNode)expressionNode.Child).Token;
+ int numericValue = (int)Convert.ChangeType(literalToken.LiteralValue, typeof(int));
+
+ _value = -numericValue;
+ }
+ catch {
+ }
+ }
+ }
+ }
+
+ public override ParseNodeList Attributes {
+ get {
+ return _attributes;
+ }
+ }
+
+ public override Modifiers Modifiers {
+ get {
+ return Modifiers.Public;
+ }
+ }
+
+ public override string Name {
+ get {
+ return _name.Name;
+ }
+ }
+
+ public override ParseNode Type {
+ get {
+ return null;
+ }
+ }
+
+ public object Value {
+ get {
+ return _value;
+ }
+ }
+ }
+}
View
98 src/Core/Compiler/CodeModel/Members/EventDeclarationNode.cs
@@ -0,0 +1,98 @@
+// EventDeclarationNode.cs
+// Script#/Core/Compiler
+// This source code is subject to terms and conditions of the Apache License, Version 2.0.
+//
+
+using System;
+using System.Collections;
+using System.Diagnostics;
+
+namespace ScriptSharp.CodeModel {
+
+ internal sealed class EventDeclarationNode : MemberNode {
+
+ private ParseNodeList _attributes;
+ private ParseNode _implementationMember;
+
+ public EventDeclarationNode(Token token, ParseNodeList attributes, ParseNode backingMember)
+ : base(ParseNodeType.EventDeclaration, token) {
+ _attributes = GetParentedNodeList(AttributeNode.GetAttributeList(attributes));
+ _implementationMember = GetParentedNode(backingMember);
+ }
+
+ public override ParseNodeList Attributes {
+ get {
+ return _attributes;
+ }
+ }
+
+ public bool IsField {
+ get {
+ return (_implementationMember is VariableDeclarationNode);
+ }
+ }
+
+ public FieldDeclarationNode Field {
+ get {
+ VariableDeclarationNode variableNode = _implementationMember as VariableDeclarationNode;
+ if (variableNode != null) {
+ return new FieldDeclarationNode(variableNode.Token, new ParseNodeList(), variableNode.Modifiers, variableNode.Type, variableNode.Initializers, false);
+ }
+ return null;
+ }
+ }
+
+ public override Modifiers Modifiers {
+ get {
+ if (_implementationMember is VariableDeclarationNode) {
+ VariableDeclarationNode variableNode = (VariableDeclarationNode)_implementationMember;
+ return variableNode.Modifiers;
+ }
+ else {
+ Debug.Assert(_implementationMember is PropertyDeclarationNode);
+
+ return ((PropertyDeclarationNode)_implementationMember).Modifiers;
+ }
+ }
+ }
+
+ public override string Name {
+ get {
+ if (_implementationMember is VariableDeclarationNode) {
+ VariableDeclarationNode variableNode = (VariableDeclarationNode)_implementationMember;
+
+ Debug.Assert(variableNode.Initializers.Count == 1);
+ Debug.Assert(variableNode.Initializers[0] is VariableInitializerNode);
+ VariableInitializerNode initializerNode = (VariableInitializerNode)variableNode.Initializers[0];
+
+ return initializerNode.Name.Name;
+ }
+ else {
+ Debug.Assert(_implementationMember is PropertyDeclarationNode);
+
+ return ((PropertyDeclarationNode)_implementationMember).Name;
+ }
+ }
+ }
+
+ public PropertyDeclarationNode Property {
+ get {
+ return _implementationMember as PropertyDeclarationNode;
+ }
+ }
+
+ public override ParseNode Type {
+ get {
+ if (_implementationMember is VariableDeclarationNode) {
+ VariableDeclarationNode variableNode = (VariableDeclarationNode)_implementationMember;
+ return variableNode.Type;
+ }
+ else {
+ Debug.Assert(_implementationMember is PropertyDeclarationNode);
+
+ return ((PropertyDeclarationNode)_implementationMember).Type;
+ }
+ }
+ }
+ }
+}
View
82 src/Core/Compiler/CodeModel/Members/FieldDeclarationNode.cs
@@ -0,0 +1,82 @@
+// FieldDeclarationNode.cs
+// Script#/Core/Compiler
+// This source code is subject to terms and conditions of the Apache License, Version 2.0.
+//
+
+using System;
+using System.Diagnostics;
+
+namespace ScriptSharp.CodeModel {
+
+ internal class FieldDeclarationNode : MemberNode {
+
+ private ParseNodeList _attributes;
+ private Modifiers _modifiers;
+ private ParseNode _type;
+ private ParseNodeList _initializers;
+ private bool _isFixed;
+
+ public FieldDeclarationNode(Token token,
+ ParseNodeList attributes,
+ Modifiers modifiers,
+ ParseNode type,
+ ParseNodeList initializers,
+ bool isFixed)
+ : this(ParseNodeType.FieldDeclaration, token, attributes, modifiers, type, initializers, isFixed) {
+ }
+
+ protected FieldDeclarationNode(ParseNodeType nodeType, Token token,
+ ParseNodeList attributes,
+ Modifiers modifiers,
+ ParseNode type,
+ ParseNodeList initializers,
+ bool isFixed)
+ : base(nodeType, token) {
+ _attributes = GetParentedNodeList(AttributeNode.GetAttributeList(attributes));
+ _modifiers = modifiers;
+ _type = GetParentedNode(type);
+ _initializers = GetParentedNodeList(initializers);
+ _isFixed = isFixed;
+ }
+
+ public override ParseNodeList Attributes {
+ get {
+ return _attributes;
+ }
+ }
+
+ public ParseNodeList Initializers {
+ get {
+ return _initializers;
+ }
+ }
+
+ public bool IsFixed {
+ get {
+ return _isFixed;
+ }
+ }
+
+ public override Modifiers Modifiers {
+ get {
+ return _modifiers;
+ }
+ }
+
+ public override string Name {
+ get {
+ Debug.Assert(_initializers.Count == 1);
+ Debug.Assert(_initializers[0] is VariableInitializerNode);
+
+ VariableInitializerNode variableNode = (VariableInitializerNode)_initializers[0];
+ return variableNode.Name.Name;
+ }
+ }
+
+ public override ParseNode Type {
+ get {
+ return _type;
+ }
+ }
+ }
+}
View
40 src/Core/Compiler/CodeModel/Members/IndexerDeclarationNode.cs
@@ -0,0 +1,40 @@
+// IndexerDeclarationNode.cs
+// Script#/Core/Compiler
+// This source code is subject to terms and conditions of the Apache License, Version 2.0.
+//
+
+using System;
+using System.Diagnostics;
+
+namespace ScriptSharp.CodeModel {
+
+ internal sealed class IndexerDeclarationNode : PropertyDeclarationNode {
+
+ private ParseNodeList _parameters;
+
+ public IndexerDeclarationNode(Token token,
+ ParseNodeList attributes,
+ Modifiers modifiers,
+ ParseNode type,
+ NameNode interfaceType,
+ ParseNodeList parameters,
+ AccessorNode get,
+ AccessorNode set)
+ : base(ParseNodeType.IndexerDeclaration, token, attributes, modifiers, type, interfaceType, get, set) {
+
+ _parameters = GetParentedNodeList(parameters);
+ }
+
+ public override string Name {
+ get {
+ return "Item";
+ }
+ }
+
+ public ParseNodeList Parameters {
+ get {
+ return _parameters;
+ }
+ }
+ }
+}
View
33 src/Core/Compiler/CodeModel/Members/MemberNode.cs
@@ -0,0 +1,33 @@
+// MemberNode.cs
+// Script#/Core/Compiler
+// This source code is subject to terms and conditions of the Apache License, Version 2.0.
+//
+
+using System;
+using System.Diagnostics;
+
+namespace ScriptSharp.CodeModel {
+
+ internal abstract class MemberNode : ParseNode {
+
+ protected MemberNode(ParseNodeType nodeType, Token token)
+ : base(nodeType, token) {
+ }
+
+ public abstract ParseNodeList Attributes {
+ get;
+ }
+
+ public abstract Modifiers Modifiers {
+ get;
+ }
+
+ public abstract string Name {
+ get;
+ }
+
+ public abstract ParseNode Type {
+ get;
+ }
+ }
+}
View
98 src/Core/Compiler/CodeModel/Members/MethodDeclarationNode.cs
@@ -0,0 +1,98 @@
+// MethodDeclarationNode.cs
+// Script#/Core/Compiler
+// This source code is subject to terms and conditions of the Apache License, Version 2.0.
+//
+
+using System;
+using System.Collections;
+using System.Diagnostics;
+
+namespace ScriptSharp.CodeModel {
+
+ internal class MethodDeclarationNode : MemberNode {
+
+ private ParseNodeList _attributes;
+ private Modifiers _modifiers;
+ private ParseNode _returnType;
+ private NameNode _interfaceType;
+ private AtomicNameNode _name;
+ private ParseNodeList _typeParameters;
+ private ParseNodeList _parameters;
+ private ParseNodeList _constraints;
+ private BlockStatementNode _implementation;
+
+ public MethodDeclarationNode(Token token,
+ ParseNodeList attributes,
+ Modifiers modifiers,
+ ParseNode returnType,
+ NameNode interfaceType,
+ AtomicNameNode name,
+ ParseNodeList typeParameters,
+ ParseNodeList formals,
+ ParseNodeList constraints,
+ BlockStatementNode body)
+ : this(ParseNodeType.MethodDeclaration, token, attributes, modifiers, returnType, name, formals, body) {
+ _interfaceType = (NameNode)GetParentedNode(interfaceType);
+ _typeParameters = GetParentedNodeList(typeParameters);
+ _constraints = GetParentedNodeList(constraints);
+ }
+
+ protected MethodDeclarationNode(ParseNodeType nodeType, Token token,
+ ParseNodeList attributes,
+ Modifiers modifiers,
+ ParseNode returnType,
+ AtomicNameNode name,
+ ParseNodeList formals,
+ BlockStatementNode body)
+ : base(nodeType, token) {
+ _attributes = GetParentedNodeList(AttributeNode.GetAttributeList(attributes));
+ _modifiers = modifiers;
+ _returnType = GetParentedNode(returnType);
+ _name = (AtomicNameNode)GetParentedNode(name);
+ _parameters = GetParentedNodeList(formals);
+ _implementation = (BlockStatementNode)GetParentedNode(body);
+ }
+
+ public override ParseNodeList Attributes {
+ get {
+ return _attributes;
+ }
+ }
+
+ public BlockStatementNode Implementation {
+ get {
+ return _implementation;
+ }
+ }
+
+ public ParseNode InterfaceType {
+ get {
+ return _interfaceType;
+ }
+ }
+
+ public override Modifiers Modifiers {
+ get {
+ return _modifiers;
+ }
+ }
+
+ public override string Name {
+ get {
+ return _name.Name;
+ }
+ }
+
+ public ParseNodeList Parameters {
+ get {
+ return _parameters;
+ }
+ }
+
+ public override ParseNode Type {
+ get {
+ return _returnType;
+ }
+ }
+ }
+}
View
27 src/Core/Compiler/CodeModel/Members/OperatorDeclarationNode.cs
@@ -0,0 +1,27 @@
+// OperatorDeclarationNode.cs
+// Script#/Core/Compiler
+// This source code is subject to terms and conditions of the Apache License, Version 2.0.
+//
+
+using System;
+using System.Diagnostics;
+
+namespace ScriptSharp.CodeModel {
+
+ // NOTE: Not supported in conversion
+ internal sealed class OperatorDeclarationNode : MethodDeclarationNode {
+
+ public TokenType operatorTokenType;
+
+ public OperatorDeclarationNode(Token token,
+ ParseNodeList attributes,
+ Modifiers modifiers,
+ TokenType operatorNodeType,
+ ParseNode returnType,
+ ParseNodeList formals,
+ BlockStatementNode body)
+ : base(ParseNodeType.OperatorDeclaration, token, attributes, modifiers, returnType, /* name */ null, formals, body) {
+ this.operatorTokenType = operatorNodeType;
+ }
+ }
+}
View
23 src/Core/Compiler/CodeModel/Members/ParameterFlags.cs
@@ -0,0 +1,23 @@
+// ParameterFlags.cs
+// Script#/Core/Compiler
+// This source code is subject to terms and conditions of the Apache License, Version 2.0.
+//
+
+using System;
+
+namespace ScriptSharp.CodeModel {
+
+ /// <summary>
+ /// Modifiers on a formal parameter.
+ /// </summary>
+ internal enum ParameterFlags {
+
+ None,
+
+ Ref,
+
+ Out,
+
+ Params
+ }
+}
View
54 src/Core/Compiler/CodeModel/Members/ParameterNode.cs
@@ -0,0 +1,54 @@
+// ParameterNode.cs
+// Script#/Core/Compiler
+// This source code is subject to terms and conditions of the Apache License, Version 2.0.
+//
+
+using System;
+using System.Diagnostics;
+
+namespace ScriptSharp.CodeModel {
+
+ internal sealed class ParameterNode : ParseNode {
+
+ private ParseNodeList _attributes;
+ private ParameterFlags _flags;
+ private ParseNode _type;
+ private AtomicNameNode _name;
+
+ public ParameterNode(Token token,
+ ParseNodeList attributes,
+ ParameterFlags flags,
+ ParseNode type,
+ AtomicNameNode name)
+ : base(ParseNodeType.FormalParameter, token) {
+ _attributes = GetParentedNodeList(AttributeNode.GetAttributeList(attributes));
+ _flags = flags;
+ _type = GetParentedNode(type);
+ _name = (AtomicNameNode)GetParentedNode(name);
+ }
+
+ public ParseNodeList Attributes {
+ get {
+ return _attributes;
+ }
+ }
+
+ public ParameterFlags Flags {
+ get {
+ return _flags;
+ }
+ }
+
+ public string Name {
+ get {
+ return _name.Name;
+ }
+ }
+
+ public ParseNode Type {
+ get {
+ return _type;
+ }
+ }
+ }
+}
View
99 src/Core/Compiler/CodeModel/Members/PropertyDeclarationNode.cs
@@ -0,0 +1,99 @@
+// PropertyDeclarationNode.cs
+// Script#/Core/Compiler
+// This source code is subject to terms and conditions of the Apache License, Version 2.0.
+//
+
+using System;
+using System.Collections;
+using System.Diagnostics;
+
+namespace ScriptSharp.CodeModel {
+
+ internal class PropertyDeclarationNode : MemberNode {
+
+ private ParseNodeList _attributes;
+ private Modifiers _modifiers;
+ private ParseNode _type;
+ private NameNode _interfaceType;
+ private NameNode _name;
+ private AccessorNode _getOrRemove;
+ private AccessorNode _setOrAdd;
+
+ public PropertyDeclarationNode(Token token,
+ ParseNodeList attributes,
+ Modifiers modifiers,
+ ParseNode type,
+ NameNode interfaceType,
+ AtomicNameNode name,
+ AccessorNode getOrRemove,
+ AccessorNode setOrAdd)
+ : this(ParseNodeType.PropertyDeclaration, token, attributes, modifiers, type, interfaceType, getOrRemove, setOrAdd) {
+ _name = (AtomicNameNode)GetParentedNode(name);
+ }
+
+ protected PropertyDeclarationNode(ParseNodeType nodeType, Token token,
+ ParseNodeList attributes,
+ Modifiers modifiers,
+ ParseNode type,
+ NameNode interfaceType,
+ AccessorNode getOrRemove,
+ AccessorNode setOrAdd)
+ : base(nodeType, token) {
+ _attributes = GetParentedNodeList(AttributeNode.GetAttributeList(attributes));
+ _modifiers = modifiers;
+ _type = GetParentedNode(type);
+ _interfaceType = (NameNode)GetParentedNode(interfaceType);
+ _getOrRemove = (AccessorNode)GetParentedNode(getOrRemove);
+ _setOrAdd = (AccessorNode)GetParentedNode(setOrAdd);
+ }
+
+ public override ParseNodeList Attributes {
+ get {
+ return _attributes;
+ }
+ }
+
+ public AccessorNode GetAccessor {
+ get {
+ return _getOrRemove;
+ }
+ }
+
+ public ParseNode InterfaceType {
+ get {
+ return _interfaceType;
+ }
+ }
+
+ public override Modifiers Modifiers {
+ get {
+ return _modifiers;
+ }
+ }
+
+ public override string Name {
+ get {
+ Debug.Assert(_name != null);
+ return _name.Name;
+ }
+ }
+
+ public NameNode NameNode {
+ get {
+ return _name;
+ }
+ }
+
+ public AccessorNode SetAccessor {
+ get {
+ return _setOrAdd;
+ }
+ }
+
+ public override ParseNode Type {
+ get {
+ return _type;
+ }
+ }
+ }
+}
View
54 src/Core/Compiler/CodeModel/Modifiers.cs
@@ -0,0 +1,54 @@
+// Modifiers.cs
+// Script#/Core/Compiler
+// This source code is subject to terms and conditions of the Apache License, Version 2.0.
+//
+
+using System;
+
+namespace ScriptSharp.CodeModel {
+
+ /// <summary>
+ /// Modifiers for types and their _members.
+ /// </summary>
+ [Flags]
+ internal enum Modifiers {
+ None = 0x0000,
+
+ Abstract = 0x0001,
+ Sealed = 0x0002,
+
+ Public = 0x0004,
+ Internal = 0x0008,
+ Private = 0x0010,
+ Protected = 0x0020,
+ AccessMask = Public | Internal | Protected | Private,
+
+ New = 0x0040,
+ Virtual = 0x0080,
+ Static = 0x0100,
+ Readonly = 0x0200,
+ Extern = 0x0400,
+ Override = 0x0800,
+ Unsafe = 0x1000,
+ Volatile = 0x2000,
+ Partial = 0x4000,
+
+ // valid flags by member type
+ ClassModifiers = New | AccessMask | Abstract | Sealed | Static | Unsafe | Partial,
+ ConstantModifiers = New | AccessMask | Unsafe,
+ FieldModifiers = New | AccessMask | Static | Readonly | Unsafe | Volatile,
+ MethodModifiers = New | AccessMask | Static | Virtual | Sealed | Override | Abstract | Extern | Unsafe,
+ PropertyModifiers = New | AccessMask | Static | Virtual | Sealed | Override | Abstract | Extern | Unsafe,
+ EventModifiers = New | AccessMask | Static | Virtual | Sealed | Override | Abstract | Extern | Unsafe,
+ IndexerModifiers = New | AccessMask | Static | Virtual | Sealed | Override | Abstract | Extern | Unsafe,
+ OperatorModifiers = Public | Static | Extern | Unsafe,
+ ConstructorModifiers = AccessMask | Extern | Unsafe,
+ StaticConstructorModifiers = Static | Extern | Unsafe,
+ DestructorModifiers = Extern | Unsafe,
+ StructModifiers = New | AccessMask | Unsafe | Partial,
+ InterfaceModifiers = New | AccessMask | Unsafe | Partial,
+ EnumModifiers = New | AccessMask,
+ DelegateModifiers = New | AccessMask | Unsafe,
+ PartialModifiers = AccessMask | Abstract | Sealed | Static
+ }
+}
View
30 src/Core/Compiler/CodeModel/Names/AliasQualifiedNameNode.cs
@@ -0,0 +1,30 @@
+// AliasQualifiedNameNode.cs
+// Script#/Core/Compiler
+// This source code is subject to terms and conditions of the Apache License, Version 2.0.
+//
+
+using System;
+using System.Collections;
+using System.Diagnostics;
+using System.Text;
+
+namespace ScriptSharp.CodeModel {
+
+ internal sealed class AliasQualifiedNameNode : NameNode {
+
+ private AtomicNameNode _aliasName;
+ private NameNode _name;
+
+ public AliasQualifiedNameNode(AtomicNameNode left, NameNode right)
+ : base(ParseNodeType.AliasQualifiedName, left.token) {
+ _aliasName = (AtomicNameNode)GetParentedNode(left);
+ _name = (NameNode)GetParentedNode(right);
+ }
+
+ protected sealed override ParseNodeList List {
+ get {
+ return new ParseNodeList(this);
+ }
+ }
+ }
+}
View
37 src/Core/Compiler/CodeModel/Names/AtomicNameNode.cs
@@ -0,0 +1,37 @@
+// AtomicNameNode.cs
+// Script#/Core/Compiler
+// This source code is subject to terms and conditions of the Apache License, Version 2.0.
+//
+
+using System;
+using System.Collections;
+using System.Diagnostics;
+
+namespace ScriptSharp.CodeModel {
+
+ internal class AtomicNameNode : NameNode {
+
+ private IdentifierToken _identifier;
+
+ public AtomicNameNode(IdentifierToken identifier)
+ : this(ParseNodeType.Name, identifier) {
+ }
+
+ protected AtomicNameNode(ParseNodeType nodeType, IdentifierToken identifier)
+ : base(nodeType, identifier) {
+ _identifier = identifier;
+ }
+
+ public IdentifierToken Identifier {
+ get {
+ return _identifier;
+ }
+ }
+
+ protected sealed override ParseNodeList List {
+ get {
+ return new ParseNodeList(this);
+ }
+ }
+ }
+}
View
27 src/Core/Compiler/CodeModel/Names/GenericNameNode.cs
@@ -0,0 +1,27 @@
+// GenericNameNode.cs
+// Script#/Core/Compiler
+// This source code is subject to terms and conditions of the Apache License, Version 2.0.
+//
+
+using System;
+using System.Collections;
+using System.Diagnostics;
+
+namespace ScriptSharp.CodeModel {
+
+ internal sealed class GenericNameNode : AtomicNameNode {
+
+ private ParseNodeList _typeArguments;
+
+ public GenericNameNode(IdentifierToken name, ParseNodeList typeArguments)
+ : base(ParseNodeType.GenericName, name) {
+ _typeArguments = typeArguments;
+ }
+
+ public ParseNodeList TypeArguments {
+ get {
+ return _typeArguments;
+ }
+ }
+ }
+}
View
27 src/Core/Compiler/CodeModel/Names/MultiPartNameNode.cs
@@ -0,0 +1,27 @@
+// MultiPartNameNode.cs
+// Script#/Core/Compiler
+// This source code is subject to terms and conditions of the Apache License, Version 2.0.
+//
+
+using System;
+using System.Collections;
+using System.Diagnostics;
+
+namespace ScriptSharp.CodeModel {
+
+ internal sealed class MultiPartNameNode : NameNode {
+
+ private ParseNodeList _names;
+
+ public MultiPartNameNode(Token token, ParseNodeList names)
+ : base(ParseNodeType.MultiPartName, token) {
+ _names = GetParentedNodeList(names);
+ }
+
+ protected sealed override ParseNodeList List {
+ get {
+ return _names;
+ }
+ }
+ }
+}
View
42 src/Core/Compiler/CodeModel/Names/NameNode.cs
@@ -0,0 +1,42 @@
+// NameNode.cs
+// Script#/Core/Compiler
+// This source code is subject to terms and conditions of the Apache License, Version 2.0.
+//
+
+using System;
+using System.Collections;
+using System.Diagnostics;
+using System.Text;
+
+namespace ScriptSharp.CodeModel {
+
+ internal abstract class NameNode : ParseNode {
+
+ private string _name;
+
+ protected NameNode(ParseNodeType nodeType, Token token)
+ : base(nodeType, token) {
+ }
+
+ protected abstract ParseNodeList List {
+ get;
+ }
+
+ public string Name {
+ get {
+ if (_name == null) {
+ StringBuilder sb = new StringBuilder();
+ foreach (AtomicNameNode symbolNode in List) {
+ if (sb.Length != 0) {
+ sb.Append('.');
+ }
+ sb.Append(symbolNode.Identifier);
+ }
+
+ _name = sb.ToString();
+ }
+ return _name;
+ }
+ }
+ }
+}
View
64 src/Core/Compiler/CodeModel/ParseNode.cs
@@ -0,0 +1,64 @@
+// ParseNode.cs
+// Script#/Core/Compiler
+// This source code is subject to terms and conditions of the Apache License, Version 2.0.
+//
+
+using System;
+using System.Collections;
+using System.Diagnostics;
+
+namespace ScriptSharp.CodeModel {
+
+ /// <summary>
+ /// The root of the parse tree hierarchy.
+ /// Note that any ParseNode can be treated as a ListTree.
+ /// A null value corresponds to an empty list. A non-ListTree
+ /// ParseNode is a list of 1 element. While a ListTree is used
+ /// for lists containing more than 1 element.
+ /// </summary>
+ internal abstract class ParseNode {
+
+ public ParseNodeType nodeType;
+ public Token token;
+ public ParseNode parent;
+
+ protected ParseNode(ParseNodeType nodeType, Token token) {
+ this.nodeType = nodeType;
+ this.token = token;
+ }
+
+ public ParseNodeType NodeType {
+ get {
+ return nodeType;
+ }
+ }
+
+ public ParseNode Parent {
+ get {
+ return parent;
+ }
+ }
+
+ public Token Token {
+ get {
+ return token;
+ }
+ }
+
+ protected ParseNode GetParentedNode(ParseNode child) {
+ if (child != null) {
+ child.SetParent(this);
+ }
+ return child;
+ }
+
+ protected ParseNodeList GetParentedNodeList(ParseNodeList nodeList) {
+ nodeList.SetParent(this);
+ return nodeList;
+ }
+
+ internal void SetParent(ParseNode node) {
+ parent = node;
+ }
+ }
+}
View
119 src/Core/Compiler/CodeModel/ParseNodeList.cs
@@ -0,0 +1,119 @@
+// ParseNodeList.cs
+// Script#/Core/Compiler
+// This source code is subject to terms and conditions of the Apache License, Version 2.0.
+//
+
+using System;
+using System.Collections;
+using System.Diagnostics;
+
+namespace ScriptSharp.CodeModel {
+
+ internal sealed class ParseNodeList : IEnumerable {
+
+ private ArrayList _list;
+
+ public ParseNodeList() {
+ }
+
+ public ParseNodeList(ParseNode node) {
+ Append(node);
+ }
+
+ public int Count {
+ get {
+ if (_list == null) {
+ return 0;
+ }
+ else {
+ return _list.Count;
+ }
+ }