Skip to content
Browse files

Initial revision

svn path=/trunk/mcs/; revision=2
  • Loading branch information...
0 parents commit 773a66abc5e63cc1d2f111daeaa2848891dc8f61 @migueldeicaza migueldeicaza committed Jun 8, 2001
Showing with 14,791 additions and 0 deletions.
  1. +3 −0 mcs/docs/clr-abi.txt
  2. +2 −0 mcs/docs/order.txt
  3. +4 −0 mcs/errors/1529.cs
  4. +12 −0 mcs/errors/cs0029.cs
  5. +15 −0 mcs/errors/cs0051.cs
  6. +7 −0 mcs/errors/cs0060.cs
  7. +6 −0 mcs/errors/cs0107.cs
  8. +29 −0 mcs/errors/cs0110.cs
  9. +9 −0 mcs/errors/cs0117.cs
  10. +11 −0 mcs/errors/cs0118.cs
  11. +15 −0 mcs/errors/cs0120.cs
  12. +8 −0 mcs/errors/cs0127.cs
  13. +12 −0 mcs/errors/cs0128.cs
  14. +8 −0 mcs/errors/cs0133.cs
  15. +13 −0 mcs/errors/cs0136.cs
  16. +13 −0 mcs/errors/cs0152.cs
  17. +9 −0 mcs/errors/cs0164.cs
  18. +16 −0 mcs/errors/cs0165-2.cs
  19. +11 −0 mcs/errors/cs0165.cs
  20. +9 −0 mcs/errors/cs0169.cs
  21. +14 −0 mcs/errors/cs0176.cs
  22. +4 −0 mcs/errors/cs0234.cs
  23. +5 −0 mcs/errors/cs0501.cs
  24. +5 −0 mcs/errors/cs0503.cs
  25. +10 −0 mcs/errors/cs0513.cs
  26. +7 −0 mcs/errors/cs0515.cs
  27. +10 −0 mcs/errors/cs0534.cs
  28. +6 −0 mcs/errors/cs0542.cs
  29. +5 −0 mcs/errors/cs0621.cs
  30. +11 −0 mcs/errors/cs0649.cs
  31. +13 −0 mcs/errors/cs0654.cs
  32. +11 −0 mcs/errors/cs1001.cs
  33. +10 −0 mcs/errors/cs1002.cs
  34. +6 −0 mcs/errors/cs1011.cs
  35. +6 −0 mcs/errors/cs1012.cs
  36. +7 −0 mcs/errors/cs102.cs
  37. +15 −0 mcs/errors/cs1501.cs
  38. +12 −0 mcs/errors/cs1520.cs
  39. +8 −0 mcs/errors/cs1525.cs
  40. +4 −0 mcs/errors/cs1529.cs
  41. +11 −0 mcs/errors/cs1552.cs
  42. +13 −0 mcs/errors/cs1579.cs
  43. +8 −0 mcs/errors/cs5001.cs
  44. +11 −0 mcs/errors/errors.txt
  45. +147 −0 mcs/mcs/ChangeLog
  46. +40 −0 mcs/mcs/assign.cs
  47. +778 −0 mcs/mcs/class.cs
  48. +48 −0 mcs/mcs/constant.cs
  49. +5,531 −0 mcs/mcs/cs-parser.cs
  50. +2,747 −0 mcs/mcs/cs-parser.jay
  51. +889 −0 mcs/mcs/cs-tokenizer.cs
  52. +108 −0 mcs/mcs/decl.cs
  53. +247 −0 mcs/mcs/driver.cs
  54. +78 −0 mcs/mcs/enum.cs
  55. +12 −0 mcs/mcs/errors.cs
  56. +499 −0 mcs/mcs/expression.cs
  57. +100 −0 mcs/mcs/gen-il.cs
  58. +1,015 −0 mcs/mcs/gen-treedump.cs
  59. +19 −0 mcs/mcs/generator.cs
  60. +299 −0 mcs/mcs/interface.cs
  61. +167 −0 mcs/mcs/literal.cs
  62. +83 −0 mcs/mcs/makefile
  63. +112 −0 mcs/mcs/modifiers.cs
  64. +99 −0 mcs/mcs/namespace.cs
  65. +145 −0 mcs/mcs/parameter.cs
  66. +160 −0 mcs/mcs/parameterCollection.cs
  67. +23 −0 mcs/mcs/parser.cs
  68. +596 −0 mcs/mcs/statement.cs
  69. +160 −0 mcs/mcs/statementCollection.cs
  70. +86 −0 mcs/mcs/tree.cs
  71. +104 −0 mcs/mcs/type.cs
  72. +22 −0 mcs/tests/interfaces.cs
  73. +53 −0 mcs/tests/try.cs
3 mcs/docs/clr-abi.txt
@@ -0,0 +1,3 @@
+* The generated code from the JIT by Microsoft uses registers
+ to pass arguments to functions rather than pushing then on the
+ stack.
2 mcs/docs/order.txt
@@ -0,0 +1,2 @@
+Order:
+ Not all code paths return a value
4 mcs/errors/1529.cs
@@ -0,0 +1,4 @@
+// cs1529.cs: Using clause must precede all other namespace elements
+// Line:
+class X { }
+using System;
12 mcs/errors/cs0029.cs
@@ -0,0 +1,12 @@
+// cs0029: cannot implicitly conver type `double' to `decimal'
+// Line: 7
+
+class T {
+ public static int Main (string [] args)
+ {
+ decimal d = 100d;
+
+ return 1;
+ }
+}
+
15 mcs/errors/cs0051.cs
@@ -0,0 +1,15 @@
+// cs0051.cs: Inconsistent accessibility: parameter type `MyClass.X' is less accessible than method MyClass.method(MyClass.X)
+// Line: 12
+
+public class MyClass {
+
+ //
+ // To fix change the next line to "public enum X {
+ enum X {
+ a, b
+ }
+
+ public void method (X arg)
+ {
+ }
+}
7 mcs/errors/cs0060.cs
@@ -0,0 +1,7 @@
+// cs0060.cs: Incosistent accessability between X and Y.X
+// Line: 6
+class X {
+}
+
+public class Y : X {
+}
6 mcs/errors/cs0107.cs
@@ -0,0 +1,6 @@
+// cs0107.cs: More than one protection modifier
+// Line: 4
+class X {
+ public private X {
+ }
+}
29 mcs/errors/cs0110.cs
@@ -0,0 +1,29 @@
+class A {
+ int a;
+
+ class B {
+ int b;
+
+ class C {
+ int c;
+
+ void m ()
+ {
+ c = 1;
+ }
+
+ enum F {
+ A, B, C, D = X, E
+ }
+
+ const int X = Y + 1;
+ const int Y = 1 + (int) F.E;
+ }
+ }
+
+ static int Main (string [] args)
+ {
+ return 0;
+ }
+
+}
9 mcs/errors/cs0117.cs
@@ -0,0 +1,9 @@
+// cs0117: `int' does not contain a definition for 'E'.
+// Line: 7
+
+class T {
+ public static int Main (string [] args )
+ {
+ int x = 1.E;
+ }
+}
11 mcs/errors/cs0118.cs
@@ -0,0 +1,11 @@
+// cs0118.cs: X.s denotes a 'field' where a class was expected
+// Line: 6
+class X {
+ string s;
+
+ s MyProperty {
+ get {
+ return s;
+ }
+ }
+}
15 mcs/errors/cs0120.cs
@@ -0,0 +1,15 @@
+// cs0120: Ie, a static method invoking a non-static method
+// `An object reference is required for the nonstatic field, method or property test.method()
+// Line: 11
+
+class test {
+
+ void method ()
+ {
+ }
+
+ public static int Main (string [] args){
+ method ();
+ return 1;
+ }
+}
8 mcs/errors/cs0127.cs
@@ -0,0 +1,8 @@
+// cs0127.cs: Since 'X.fn' returns void, a return keyword must not be followed by an object expression
+// Line: 6
+class X {
+ void fn ()
+ {
+ return 1;
+ }
+}
12 mcs/errors/cs0128.cs
@@ -0,0 +1,12 @@
+// cs0128: a local variable named `x' is already defined in this scope
+// Line:
+
+class x {
+ static int y ()
+ {
+ int x = 1;
+ int x = 2;
+
+ return x + x;
+ }
+}
8 mcs/errors/cs0133.cs
@@ -0,0 +1,8 @@
+// cs0133.cs: the expression being assigned to `x' must be constant
+// Line: 6
+class X {
+ X (int arg)
+ {
+ const int x = arg;
+ }
+}
13 mcs/errors/cs0136.cs
@@ -0,0 +1,13 @@
+// cs0136: A local variable named 'i' cannot be declared in this scope because it would give a different meaning to 'i'
+// Line: 8
+class X {
+ void b ()
+ {
+ int i;
+ {
+ string i;
+ }
+ }
+}
+
+
13 mcs/errors/cs0152.cs
@@ -0,0 +1,13 @@
+// cs0152.cs: The label `case X:' already occurs in this switch statement
+// Line: 9
+class X {
+ void f (int i)
+ {
+ switch (i){
+ case 1:
+ break;
+ case 1:
+ break;
+ }
+ }
+}
9 mcs/errors/cs0164.cs
@@ -0,0 +1,9 @@
+// cs0164.cs: This label has not been referenced
+// Line: 5
+class X {
+ void D () {
+ a:
+
+ return;
+ }
+}
16 mcs/errors/cs0165-2.cs
@@ -0,0 +1,16 @@
+class T {
+ void fun (ref int a)
+ {
+ if (a == 3)
+ a = 2;
+ }
+
+ void x ()
+ {
+ int x;
+
+ if (System.Console.Read () == 1)
+ x = 1;
+ fun (ref x);
+ }
+}
11 mcs/errors/cs0165.cs
@@ -0,0 +1,11 @@
+// cs0165.cs: Use of unassigned local variable
+// Line: 9
+
+class T {
+ public T ()
+ {
+ int errors;
+
+ errors += 1;
+ }
+}
9 mcs/errors/cs0169.cs
@@ -0,0 +1,9 @@
+// cs0169.cs: warning, private field `prv' is never used
+// Line: 4
+class X {
+ int x;
+
+ void blah ()
+ {
+ }
+}
14 mcs/errors/cs0176.cs
@@ -0,0 +1,14 @@
+// cs0176.cs: cannot be accessed with an instance reference, use typename instead
+// Line: 12
+class X {
+ static void void_method ()
+ {
+ }
+}
+
+class Y {
+ void m (X arg)
+ {
+ arg.void_method ();
+ }
+}
4 mcs/errors/cs0234.cs
@@ -0,0 +1,4 @@
+//cs0243: NonExistant does not exist in this namespace
+
+using Nonexistant;
+
5 mcs/errors/cs0501.cs
@@ -0,0 +1,5 @@
+// cs0501.cs: `Class.X' must declare a body because it is not marked abstract or extern
+// Line: 4
+class Class {
+ virtual public void X ();
+}
5 mcs/errors/cs0503.cs
@@ -0,0 +1,5 @@
+// cs0503.cs: The abstract method `Class.X' cannot be marked virtual
+// Line: 4
+class Class {
+ virtual abstract public void X ();
+}
10 mcs/errors/cs0513.cs
@@ -0,0 +1,10 @@
+// cs0513.cs: X.myAbstract is abstract but it is contained in non-abstract class
+// Line: 5
+
+class X {
+ public abstract void myAbstract ();
+}
+
+class Y : X {
+}
+
7 mcs/errors/cs0515.cs
@@ -0,0 +1,7 @@
+// cs0515.cs: access modifiers are not allowed on static constructors
+// Line: 4
+class X {
+ public static X ()
+ {
+ }
+}
10 mcs/errors/cs0534.cs
@@ -0,0 +1,10 @@
+// cs0534.cs: `Y' does not implement inherited abstract member `myAbstract'
+// Line: 5
+
+abstract class X {
+ public abstract void myAbstract ();
+}
+
+class Y : X {
+}
+
6 mcs/errors/cs0542.cs
@@ -0,0 +1,6 @@
+// cs0542.cs: member names can not be the same as their enclosing type
+// Line: 4
+class X {
+ int X;
+}
+
5 mcs/errors/cs0621.cs
@@ -0,0 +1,5 @@
+// cs0621.cs: X.method virtual or abstract methods can not be private
+// Line:
+class X {
+ virtual void method ();
+}
11 mcs/errors/cs0649.cs
@@ -0,0 +1,11 @@
+// cs0649.cs: Field `X.s' is never assigned to, and will always have its default value null
+// Line: 4
+class X {
+ string s;
+
+ string Value {
+ get {
+ return s;
+ }
+ }
+}
13 mcs/errors/cs0654.cs
@@ -0,0 +1,13 @@
+// cs0654.cs: Method referenced without argument list.
+// Line: 12
+class X {
+ int a (int a)
+ {
+ return 0;
+ }
+
+ void b ()
+ {
+ int x = a;
+ }
+}
11 mcs/errors/cs1001.cs
@@ -0,0 +1,11 @@
+//
+// cs1001: identifier expected
+// Line: 8
+
+class T {
+
+ // Change (args) to (string args) to fix it
+ public static int Main (args)
+ {
+ }
+}
10 mcs/errors/cs1002.cs
@@ -0,0 +1,10 @@
+// cs1002.cs: ; expected
+// Line: 8
+
+class T {
+ void member ()
+ {
+ int a = 1 | 2
+ int b;
+ }
+}
6 mcs/errors/cs1011.cs
@@ -0,0 +1,6 @@
+// cs1011: Empty character literal
+// Line: 5
+
+class T {
+ char c = '';
+}
6 mcs/errors/cs1012.cs
@@ -0,0 +1,6 @@
+// cs1012: Too many characters in character literal
+// Line: 5
+
+class x {
+ char x = 'xx';
+}
7 mcs/errors/cs102.cs
@@ -0,0 +1,7 @@
+// cs102.cs: The class 'X' already contains a definition for 'A'
+// Line: 6
+class X {
+ const int A = 10;
+
+ int A () {}
+}
15 mcs/errors/cs1501.cs
@@ -0,0 +1,15 @@
+// cs1501.cs: No overload for method `Base' takes `0' arguments
+// Line: 12
+class Base {
+ Base (string x)
+ {
+ }
+}
+
+// Notice how there is no invocation to "base (something)"
+
+class Derived : Base {
+ Derived ()
+ {
+ }
+}
12 mcs/errors/cs1520.cs
@@ -0,0 +1,12 @@
+//
+// cs1520: Class, struct or interface method must have a return type
+// Line: 9
+
+class test {
+
+ // To fix add a return type
+
+ public static Main (string[] args)
+ {
+ }
+}
8 mcs/errors/cs1525.cs
@@ -0,0 +1,8 @@
+// cs1525: Invalid expression term.
+// Line: 7
+class X {
+ X ()
+ {
+ label1:
+ }
+}
4 mcs/errors/cs1529.cs
@@ -0,0 +1,4 @@
+// cs1529.cs: Using clause must precede all other namespace elements
+// Line: 4
+class X { }
+using System;
11 mcs/errors/cs1552.cs
@@ -0,0 +1,11 @@
+//
+// cs1552.cs: Array type specified, [] must appear before parameter name
+// Line: 8
+
+class T {
+ // To fix: change (string args[]) to (string [] args)
+
+ public static int Main (string args[])
+ {
+ }
+}
13 mcs/errors/cs1579.cs
@@ -0,0 +1,13 @@
+// cs1579.cs: foreach statement cannot operate on variables of type X because X does not contain a definition for GetEnumerator or is not accessible
+// Line: 10
+class X {
+}
+
+class Y {
+ void yy (X b)
+ {
+
+ foreach (object a in b)
+ ;
+ }
+}
8 mcs/errors/cs5001.cs
@@ -0,0 +1,8 @@
+//cs5001: Program x does not have an entry point defined
+
+using System;
+using System.Collections;
+
+namespace Butt {
+}
+
11 mcs/errors/errors.txt
@@ -0,0 +1,11 @@
+We use negative numbers for the compiler, and leave the possitive
+numbers to match the Microsoft numbers:
+
+-1 An Primary Expression was parsed, when a Type was expected.
+ This happens because my parser knowledge is limited, and I
+ am not good at writing grammars. It is still an error,
+ but if I were smarter, I would have found a Bison/Yacc way
+ of handling it.
+
+-2 Internal error, an interface is being defined inside an
+ interface (This should never happen).
147 mcs/mcs/ChangeLog
@@ -0,0 +1,147 @@
+2001-06-08 Miguel de Icaza <miguel@ximian.com>
+
+ * ARGH. I have screwed up my tree so many times due to the use of
+ rsync rather than using CVS. Going to fix this at once.
+
+ * driver.cs: Objetify driver. Load assemblies, use assemblies to
+ load types.
+
+2001-06-07 Miguel de Icaza <miguel@ximian.com>
+
+ * Experiment successful: Use System.Type rather that our own
+ version of Type.
+
+2001-05-25 Miguel de Icaza <miguel@ximian.com>
+
+ * cs-parser.jay: Removed nsAliases from here.
+
+ Use new namespaces, handle `using XXX;'
+
+ * namespace.cs: Reimplemented namespace handling, use a recursive
+ definition of the class. Now we can keep track of using clauses
+ and catch invalid using clauses.
+
+2001-05-24 Miguel de Icaza <miguel@ximian.com>
+
+ * gen-treedump.cs: Adapted for all the renaming.
+
+ * expression.cs (Expression): this class now has a Type property
+ which returns an expression Type.
+
+ (Probe::, New::, TypeOf::, SizeOf::, Constant::): renamed from
+ `Type', as this has a different meaning now in the base
+
+2001-05-22 Miguel de Icaza <miguel@ximian.com>
+
+ * interface.cs, class.cs: Removed from all the sources the
+ references to signature computation, as we can not do method
+ signature computation during the parsing time, as we are not
+ trying to solve at that point distinguishing:
+
+ class X {
+ void a (Blah x) {}
+ void a (NS.Blah x) {}
+ }
+
+ Which depending on the context might be valid or not, as we do not
+ know if Blah is the same thing as NS.Blah at that point.
+
+ * Redid everything so the code uses TypeRefs now instead of
+ Types. TypeRefs are just temporary type placeholders, that need
+ to be resolved. They initially have a pointer to a string and the
+ current scope in which they are used. This is used later by the
+ compiler to resolve the reference to an actual Type.
+
+ * DeclSpace is no longer a CIR.Type, and neither are
+ TypeContainers (Class and Struct) nor Interfaces nor Enums. They
+ are all DeclSpaces, but no Types.
+
+ * type.cs (TypeRefManager): This implements the TypeRef manager,
+ which keeps track of all the types that need to be resolved after
+ the parsing has finished.
+
+2001-05-13 Miguel de Icaza <miguel@ximian.com>
+
+ * ARGH. We are going to have to store `foreach' as a class rather
+ than resolving it, as we need to verify error 1579 after name
+ resolution. *OR* we could keep a flag that says `This request to
+ IEnumerator comes from a foreach statement' which we can then use
+ to generate the error.
+
+2001-05-10 Miguel de Icaza <miguel@ximian.com>
+
+ * class.cs (TypeContainer.AddMethod): we now add methods to the
+ MethodGroup instead of the method hashtable.
+
+ * expression.cs: Add MethodGroup abstraction, which gets us one
+ step closer to the specification in the way we handle method
+ declarations.
+
+ * cs-parser.jay (primary_expression): qualified_identifier now
+ tried to match up an identifier to a local variable reference or
+ to a parameter reference.
+
+ current_local_parameters is now a parser global variable that
+ points to the current parameters for the block, used during name
+ lookup.
+
+ (property_declaration): Now creates an implicit `value' argument to
+ the set accessor.
+
+2001-05-09 Miguel de Icaza <miguel@ximian.com>
+
+ * parameter.cs: Do not use `param' arguments as part of the
+ signature, per the spec.
+
+2001-05-08 Miguel de Icaza <miguel@ximian.com>
+
+ * decl.cs: Base class for classes, structs and interfaces. This
+ is the "Declaration Space"
+
+ * cs-parser.jay: Use CheckDef for checking declaration errors
+ instead of having one on each function.
+
+ * class.cs: Factor out some code for handling error handling in
+ accordance to the "Declarations" section in the "Basic Concepts"
+ chapter in the ECMA C# spec.
+
+ * interface.cs: Make all interface member classes derive from
+ InterfaceMemberBase.
+
+2001-05-07 Miguel de Icaza <miguel@ximian.com>
+
+ * Many things: all interfaces are parsed and generated in
+ gen-treedump. Support for member variables, constructors,
+ destructors, properties, constants is there.
+
+ Beginning of the IL backend, but very little done, just there for
+ testing purposes.
+
+2001-04-29 Miguel de Icaza <miguel@ximian.com>
+
+ * cs-parser.jay: Fix labeled statement.
+
+ * cs-tokenizer.cs (escape): Escape " and ' always.
+ ref_line, ref_name: keep track of the line/filename as instructed
+ by #line by the compiler.
+ Parse #line.
+
+2001-04-27 Miguel de Icaza <miguel@ximian.com>
+
+ * System.CodeDOM/CodeBinaryOperatorExpression.cs: Rearrange enum
+ to match the values in System.CodeDOM.
+
+ Divid renamed to Divide.
+
+ * System.CodeDOM/CodeForLoopStatement.cs: Always have valid
+ statements.
+ (Statements.set): remove.
+
+ * System.CodeDOM/CodeCatchClause.cs: always have a valid
+ statements.
+
+ * System.CodeDOM/CodeIfStatement.cs: trueStatements and
+ falseStatements always have valid values.
+
+ * cs-parser.jay: Use System.CodeDOM now.
+
40 mcs/mcs/assign.cs
@@ -0,0 +1,40 @@
+//
+// assign.cs: Assignment representation for the IL tree.
+//
+// Author:
+// Miguel de Icaza (miguel@ximian.com)
+//
+// (C) 2001 Ximian, Inc.
+//
+
+namespace CIR {
+ public class Assign : Expression {
+ Expression target, source;
+
+ public Assign (Expression target, Expression source)
+ {
+ this.target = target;
+ this.source = source;
+ }
+
+ public Expression Target {
+ get {
+ return target;
+ }
+
+ set {
+ target = value;
+ }
+ }
+
+ public Expression Source {
+ get {
+ return source;
+ }
+
+ set {
+ source = value;
+ }
+ }
+ }
+}
778 mcs/mcs/class.cs
@@ -0,0 +1,778 @@
+//
+// class.cs: Class and Struct handlers
+//
+// Author: Miguel de Icaza (miguel@gnu.org)
+//
+// Licensed under the terms of the GNU GPL
+//
+// (C) 2001 Ximian, Inc (http://www.ximian.com)
+//
+// TODO:
+//
+// a. Maybe keep a list of defined names in the order they
+// appeared, so we can walk things in this way to present
+// the users with errors in that order?
+//
+
+using System.Collections;
+using System;
+
+namespace CIR {
+
+ public class TypeContainer : DeclSpace {
+ protected int mod_flags;
+ Hashtable types, fields, properties;
+ Hashtable enums, constants, interfaces, method_groups;
+
+ ArrayList constructor_list;
+
+ //
+ // This is the namespace in which this typecontainer
+ // was declared. We use this to resolve names.
+ //
+ CSC.Namespace my_namespace;
+
+ //
+ // This one is computed after we can distinguish interfaces
+ // from classes from the arraylist `type_bases'
+ //
+ string base_class_name;
+
+ TypeContainer parent;
+ ArrayList type_bases;
+
+ public TypeContainer (TypeContainer parent, string name) : base (name)
+ {
+ types = new Hashtable ();
+ this.parent = parent;
+
+ string n;
+ if (parent == null)
+ n = "";
+ else
+ n = parent.Name;
+
+ base_class_name = null;
+
+ //Console.WriteLine ("New class " + name + " inside " + n);
+ }
+
+ public AdditionResult AddConstant (Constant constant)
+ {
+ AdditionResult res;
+ string name = constant.Name;
+
+ if ((res = IsValid (name)) != AdditionResult.Success)
+ return res;
+
+ if (constants == null)
+ constants = new Hashtable ();
+
+ constants.Add (name, constant);
+ DefineName (name, constant);
+
+ return AdditionResult.Success;
+ }
+
+ public AdditionResult AddEnum (CIR.Enum e)
+ {
+ AdditionResult res;
+ string name = e.Name;
+
+ if ((res = IsValid (name)) != AdditionResult.Success)
+ return res;
+
+ if (enums == null)
+ enums = new Hashtable ();
+
+ enums.Add (name, e);
+ DefineName (name, e);
+
+ return AdditionResult.Success;
+ }
+
+ public AdditionResult AddClass (Class c)
+ {
+ AdditionResult res;
+ string name = c.Name;
+
+
+ if ((res = IsValid (name)) != AdditionResult.Success)
+ return res;
+
+ DefineName (name, c);
+ types.Add (name, c);
+
+ return AdditionResult.Success;
+ }
+
+ public AdditionResult AddStruct (Struct s)
+ {
+ AdditionResult res;
+ string name = s.Name;
+
+ if ((res = IsValid (name)) != AdditionResult.Success)
+ return res;
+
+ DefineName (name, s);
+ types.Add (name, s);
+
+ return AdditionResult.Success;
+ }
+
+ public AdditionResult AddMethod (Method method)
+ {
+ string name = method.Name;
+ Object value = defined_names [name];
+
+ if (value != null && (!(value is MethodGroup)))
+ return AdditionResult.NameExists;
+
+ if (method_groups == null)
+ method_groups = new Hashtable ();
+
+ MethodGroup mg = (MethodGroup) method_groups [name];
+ if (mg == null){
+ mg = new MethodGroup (name);
+
+ mg.Add (method);
+ method_groups.Add (name, mg);
+
+ return AdditionResult.Success;
+ }
+ mg.Add (method);
+
+ if (value == null)
+ DefineName (name, mg);
+
+ return AdditionResult.Success;
+ }
+
+ public AdditionResult AddConstructor (Constructor c)
+ {
+ if (c.Name != Basename)
+ return AdditionResult.NotAConstructor;
+
+ if (constructor_list == null)
+ constructor_list = new ArrayList ();
+
+ constructor_list.Add (c);
+
+ return AdditionResult.Success;
+ }
+
+ public AdditionResult AddInterface (Interface iface)
+ {
+ AdditionResult res;
+ string name = iface.Name;
+
+ if ((res = IsValid (name)) != AdditionResult.Success)
+ return res;
+
+ if (interfaces == null)
+ interfaces = new Hashtable ();
+ interfaces.Add (name, iface);
+ DefineName (name, iface);
+
+ return AdditionResult.Success;
+ }
+
+ public AdditionResult AddField (Field field)
+ {
+ AdditionResult res;
+ string name = field.Name;
+
+ if ((res = IsValid (name)) != AdditionResult.Success)
+ return res;
+
+ if (fields == null)
+ fields = new Hashtable ();
+
+ fields.Add (name, field);
+ DefineName (name, field);
+ return AdditionResult.Success;
+ }
+
+ public AdditionResult AddProperty (Property prop)
+ {
+ AdditionResult res;
+ string name = prop.Name;
+
+ if ((res = IsValid (name)) != AdditionResult.Success)
+ return res;
+
+ if (properties == null)
+ properties = new Hashtable ();
+
+ properties.Add (name, prop);
+ DefineName (name, prop);
+
+ return AdditionResult.Success;
+ }
+
+ public Constant GetConstant (string name) {
+ return (Constant) constants [name];
+ }
+
+ public TypeContainer Parent {
+ get {
+ return parent;
+ }
+ }
+
+ public Hashtable Types {
+ get {
+ return types;
+ }
+ }
+
+ public Hashtable MethodGroups {
+ get {
+ return method_groups;
+ }
+ }
+
+ public Hashtable Constants {
+ get {
+ return constants;
+ }
+ }
+
+ public Hashtable Interfaces {
+ get {
+ return interfaces;
+ }
+ }
+
+ public int ModFlags {
+ get {
+ return mod_flags;
+ }
+ }
+
+ public string Base {
+ get {
+ return base_class_name;
+ }
+ }
+
+ public ArrayList Bases {
+ get {
+ return type_bases;
+ }
+
+ set {
+ type_bases = value;
+ }
+ }
+
+ public Hashtable Fields {
+ get {
+ return fields;
+ }
+ }
+
+ public Hashtable Constructors {
+ get {
+ return null; // constructors;
+ }
+ }
+
+ public Hashtable Properties {
+ get {
+ return properties;
+ }
+ }
+
+ public Hashtable Enums {
+ get {
+ return enums;
+ }
+ }
+
+ public Type ResolveName (string name)
+ {
+ return null;
+ }
+
+ public CSC.Namespace Namespace {
+ get {
+ return my_namespace;
+ }
+
+ set {
+ my_namespace = value;
+ }
+ }
+
+ public int ResolveParents (Tree root)
+ {
+ if (Bases != null){
+ if (type_bases.Count == 0){
+ base_class_name = "System.Object";
+ return 0;
+ }
+ } else
+ return 0;
+
+ foreach (Type t in Bases){
+ Type resolved = ResolveName (t.Name);
+
+
+ }
+ return 0;
+ }
+
+ public delegate void VisitContainer (TypeContainer container, object cback_data);
+
+ void VisitTypesAt (TypeContainer root, VisitContainer visit, object cback)
+ {
+ if (root == null)
+ return;
+
+ foreach (DictionaryEntry de in root.Types){
+ TypeContainer type = (TypeContainer) de.Value;
+
+ visit (type, cback);
+ VisitTypesAt (type, visit, cback);
+ }
+ }
+
+ // <summary>
+ // Use this method to visit all the types in a type container.
+ // You can use cback to pass arbitrary data to your callback.
+ // </summary>
+ public void VisitTypes (VisitContainer visit, object cback)
+ {
+ foreach (DictionaryEntry de in types){
+ TypeContainer type = (TypeContainer) de.Value;
+
+ VisitTypesAt (type, visit, cback);
+ }
+
+ }
+
+ internal class VisitExpressions_Lambda {
+ VisitExpressionRoot vb;
+ object user_data;
+
+ void walk_arguments (ArrayList args)
+ {
+ if (args == null)
+ return;
+
+ int top = args.Count;
+
+ for (int i = 0; i < top; i++){
+ Argument arg = (Argument) args [i];
+
+ vb (arg.Expr, user_data);
+ }
+ }
+
+ void walk_block (Block b)
+ {
+ }
+
+ void walk_constructor (Constructor c)
+ {
+ ConstructorInitializer init = c.Initializer;
+
+ if (init != null && init.Arguments != null)
+ walk_arguments (init.Arguments);
+
+ walk_block (c.Block);
+ }
+
+ void walk_properties (Property p)
+ {
+ }
+
+ void walk_method (Method m)
+ {
+ }
+
+ void type_walker_1 (TypeContainer type, object cback)
+ {
+ if (type.Fields != null){
+ foreach (DictionaryEntry de in type.Fields){
+ Field f = (Field) de.Value;
+
+ if (f.Initializer != null){
+ if (f.Initializer is Expression)
+ vb ((Expression) f.Initializer, user_data);
+ }
+ }
+ }
+
+ if (type.Constructors != null){
+ foreach (DictionaryEntry de in type.Constructors)
+ walk_constructor ((Constructor) de.Value);
+ }
+
+ if (type.Properties != null){
+ foreach (DictionaryEntry de in type.Properties)
+ walk_properties ((Property) de.Value);
+ }
+
+ if (type.MethodGroups != null){
+ foreach (DictionaryEntry de in type.MethodGroups){
+ Hashtable methods = ((MethodGroup) de.Value).Methods;
+ foreach (Method m in methods)
+ walk_method (m);
+ }
+ }
+ }
+
+
+ internal VisitExpressions_Lambda (TypeContainer tc,
+ VisitExpressionRoot vb,
+ object user_data)
+ {
+ this.vb = vb;
+ this.user_data = user_data;
+
+ tc.VisitTypes (new VisitContainer (type_walker_1), null);
+ }
+ }
+
+ public delegate void VisitExpressionRoot (Expression e, object cback);
+ // <summary>
+ // Use this method to visit all the code blocks in a TypeContainer
+ // </summary>
+ public void VisitExpressionRoots (VisitExpressionRoot vb, object cback)
+ {
+ VisitExpressions_Lambda l = new VisitExpressions_Lambda (this, vb, cback);
+ }
+ }
+
+ public class Class : TypeContainer {
+ // <summary>
+ // Modifiers allowed in a class declaration
+ // </summary>
+ public const int AllowedModifiers =
+ Modifiers.NEW |
+ Modifiers.PUBLIC |
+ Modifiers.PROTECTED |
+ Modifiers.INTERNAL |
+ Modifiers.PRIVATE |
+ Modifiers.ABSTRACT |
+ Modifiers.SEALED;
+
+ public Class (TypeContainer parent, string name, int mod)
+ : base (parent, name)
+ {
+ int accmods;
+
+ if (parent.Parent == null)
+ accmods = Modifiers.INTERNAL;
+ else
+ accmods = Modifiers.PRIVATE;
+
+ this.mod_flags = Modifiers.Check (AllowedModifiers, mod, accmods);
+ }
+ }
+
+ public class Struct : TypeContainer {
+ // <summary>
+ // Modifiers allowed in a struct declaration
+ // </summary>
+ public const int AllowedModifiers =
+ Modifiers.NEW |
+ Modifiers.PUBLIC |
+ Modifiers.PROTECTED |
+ Modifiers.INTERNAL |
+ Modifiers.PRIVATE;
+
+ public Struct (TypeContainer parent, string name, int mod)
+ : base (parent, name)
+ {
+ int accmods;
+
+ if (parent.Parent == null)
+ accmods = Modifiers.INTERNAL;
+ else
+ accmods = Modifiers.PRIVATE;
+
+ this.mod_flags = Modifiers.Check (AllowedModifiers, mod, accmods);
+ }
+ }
+
+ public class Method {
+ Parameters parameters;
+ TypeRef return_typeref;
+ string name;
+ int modifiers;
+ Block block;
+
+ // return_type can be "null" for VOID values.
+ public Method (TypeRef return_typeref, int mod, string name, Parameters parameters)
+ {
+ this.return_typeref = return_typeref;
+ this.name = name;
+ this.parameters = parameters;
+ this.modifiers = Modifiers.Check (AllowedModifiers, mod, Modifiers.PRIVATE);
+ }
+
+ // <summary>
+ // Modifiers allowed in a class declaration
+ // </summary>
+ const int AllowedModifiers =
+ Modifiers.NEW |
+ Modifiers.PUBLIC |
+ Modifiers.PROTECTED |
+ Modifiers.INTERNAL |
+ Modifiers.PRIVATE |
+ Modifiers.STATIC |
+ Modifiers.VIRTUAL |
+ Modifiers.SEALED |
+ Modifiers.OVERRIDE |
+ Modifiers.ABSTRACT |
+ Modifiers.EXTERN;
+
+ public Block Block {
+ get {
+ return block;
+ }
+
+ set {
+ block = value;
+ }
+ }
+
+ public string Name {
+ get {
+ return name;
+ }
+ }
+
+ public int ModFlags {
+ get {
+ return modifiers;
+ }
+ }
+
+ public Parameters Parameters {
+ get {
+ return parameters;
+ }
+ }
+
+ public Type ReturnType {
+ get {
+ return return_typeref.Type;
+ }
+ }
+
+ public string ArgumentSignature {
+ get {
+ return ""; // TYPEFIX: Type.MakeParameterSignature (name, parameters);
+ }
+ }
+ }
+
+ public class Field {
+ Type type;
+ Object expr_or_array_init;
+ string name;
+ int modifiers;
+
+ // <summary>
+ // Modifiers allowed in a class declaration
+ // </summary>
+ const int AllowedModifiers =
+ Modifiers.NEW |
+ Modifiers.PUBLIC |
+ Modifiers.PROTECTED |
+ Modifiers.INTERNAL |
+ Modifiers.PRIVATE |
+ Modifiers.STATIC |
+ Modifiers.READONLY;
+
+ public Field (TypeRef typeref, int mod, string name, Object expr_or_array_init)
+ {
+ this.type = type;
+ this.modifiers = Modifiers.Check (AllowedModifiers, mod, Modifiers.PRIVATE);
+ this.name = name;
+ this.expr_or_array_init = expr_or_array_init;
+ }
+
+ public Type Type {
+ get {
+ return type;
+ }
+ }
+
+ public object Initializer {
+ get {
+ return expr_or_array_init;
+ }
+ }
+
+ public string Name {
+ get {
+ return name;
+ }
+ }
+
+ public int ModFlags {
+ get {
+ return modifiers;
+ }
+ }
+ }
+
+ public abstract class ConstructorInitializer {
+ ArrayList argument_list;
+
+ public ConstructorInitializer (ArrayList argument_list)
+ {
+ this.argument_list = argument_list;
+ }
+
+ public ArrayList Arguments {
+ get {
+ return argument_list;
+ }
+ }
+ }
+
+ public class ConstructorBaseInitializer : ConstructorInitializer {
+ public ConstructorBaseInitializer (ArrayList argument_list) : base (argument_list)
+ {
+ }
+ }
+
+ public class ConstructorThisInitializer : ConstructorInitializer {
+ public ConstructorThisInitializer (ArrayList argument_list) : base (argument_list)
+ {
+ }
+ }
+
+ public class Constructor {
+ ConstructorInitializer init;
+ string name;
+ Parameters args;
+ Block block;
+ int mod_flags;
+
+ // <summary>
+ // Modifiers allowed for a constructor.
+ // </summary>
+ const int AllowedModifiers =
+ Modifiers.PUBLIC |
+ Modifiers.PROTECTED |
+ Modifiers.INTERNAL |
+ Modifiers.STATIC |
+ Modifiers.PRIVATE;
+
+ //
+ // The spec claims that static is not permitted, but
+ // my very own code has static constructors.
+ //
+
+ public Constructor (string name, Parameters args, ConstructorInitializer init)
+ {
+ this.name = name;
+ this.args = args;
+ this.init = init;
+ }
+
+ public string Name {
+ get {
+ return name;
+ }
+ }
+
+ public ConstructorInitializer Initializer {
+ get {
+ return init;
+ }
+ }
+
+ public Parameters Parameters {
+ get {
+ return args;
+ }
+ }
+
+ public Block Block {
+ get {
+ return block;
+ }
+
+ set {
+ block = value;
+ }
+ }
+
+ public int ModFlags {
+ get {
+ return mod_flags;
+ }
+
+ set {
+ mod_flags = Modifiers.Check (AllowedModifiers, value, 0);
+ }
+ }
+ }
+
+ public class Property {
+ TypeRef typeref;
+ string name;
+ int mod_flags;
+ Block get_block, set_block;
+
+ const int AllowedModifiers =
+ Modifiers.NEW |
+ Modifiers.PUBLIC |
+ Modifiers.PROTECTED |
+ Modifiers.INTERNAL |
+ Modifiers.PRIVATE |
+ Modifiers.STATIC |
+ Modifiers.SEALED |
+ Modifiers.OVERRIDE |
+ Modifiers.ABSTRACT |
+ Modifiers.VIRTUAL;
+
+ public Property (TypeRef typeref, string name, int mod_flags, Block get_block, Block set_block)
+ {
+ this.typeref = typeref;
+ this.name = name;
+ this.mod_flags = Modifiers.Check (AllowedModifiers, mod_flags, Modifiers.PRIVATE);
+ this.get_block = get_block;
+ this.set_block = set_block;
+ }
+
+ public Type Type {
+ get {
+ return typeref.Type;
+ }
+ }
+
+ public string Name {
+ get {
+ return name;
+ }
+ }
+
+ public int ModFlags {
+ get {
+ return mod_flags;
+ }
+ }
+
+ public Block Get {
+ get {
+ return get_block;
+ }
+ }
+
+ public Block Set {
+ get {
+ return set_block;
+ }
+ }
+ }
+}
+
48 mcs/mcs/constant.cs
@@ -0,0 +1,48 @@
+namespace CIR {
+
+ using System;
+
+ public class Constant : Expression {
+ public string name;
+ public Expression expr;
+ public TypeRef typeref;
+
+ public const int AllowedModifiers =
+ Modifiers.NEW |
+ Modifiers.PUBLIC |
+ Modifiers.PROTECTED |
+ Modifiers.INTERNAL |
+ Modifiers.PRIVATE;
+
+ public Constant (TypeRef typeref, string name, Expression expr)
+ {
+ this.typeref = typeref;
+ this.name = name;
+ this.expr = expr;
+ }
+
+ public void Reduce ()
+ {
+
+ }
+
+ public string Name {
+ get {
+ return name;
+ }
+ }
+
+ public Type ConstantType {
+ get {
+ return typeref.Type;
+ }
+ }
+
+ public Expression Expr {
+ get {
+ return expr;
+ }
+ }
+ }
+}
+
5,531 mcs/mcs/cs-parser.cs
5,531 additions, 0 deletions not shown because the diff is too large. Please use a local Git client to view these changes.
2,747 mcs/mcs/cs-parser.jay
@@ -0,0 +1,2747 @@
+%{
+//
+// cs-parser.jay: The Parser for the C# compiler
+//
+// Author: Miguel de Icaza (miguel@gnu.org)
+//
+// Licensed under the terms of the GNU GPL
+//
+// (C) 2001 Ximian, Inc (http://www.ximian.com)
+//
+// TODO:
+// (1) Get rid of the *Collections.cs, that is an idea I took from System.CodeDOM
+// And come to think of it, it is not that great, it duplicates a lot of code
+// for something which is not really needed. We still have piles of typecasts
+// anwyays (due to the nature of the stack being a collection of Objects).
+//
+// (2) Figure out why error productions dont work. `type-declaration' is a
+// great spot to put an `error' because you can reproduce it with this input:
+// "public X { }"
+//
+// (3) Move Modifier checking from each object into the parser itself, that will
+// get rid of the global "error" symbol that we use now to report errors.
+// We still need to pass a pointer to the tree.ErrorHandler, but that is a
+// separate problem
+//
+using System.Text;
+using CSC;
+using System;
+
+namespace CSC
+{
+ using System.Collections;
+ using Compiler;
+ using CSC;
+ using CIR;
+
+ /// <summary>
+ /// The C# Parser
+ /// </summary>
+ public class CSharpParser : Parser {
+ static int global_errors;
+
+ Namespace current_namespace;
+ TypeContainer current_container;
+
+ // <summary>
+ // Current block is used to add statements as we find
+ // them.
+ // </summary>
+
+ Block current_block;
+
+ // <summary>
+ // Current interface is used by the various declaration
+ // productions in the interface declaration to "add"
+ // the interfaces as we find them.
+ // </summary>
+ Interface current_interface;
+
+ // <summary>
+ // This is used by the unary_expression code to resolve
+ // a name against a parameter.
+ // </summary>
+ Parameters current_local_parameters;
+
+ // <summary>
+ // Using during property parsing to describe the implicit
+ // value parameter that is passed to the "set" accesor
+ // method
+ // </summary>
+ ParameterCollection implicit_value_parameters;
+
+ // <summary>
+ // Here we keep track of type references.
+ // </summary>
+ TypeRefManager type_references;
+%}
+
+%token EOF
+%token NONE /* This token is never returned by our lexer */
+%token ERROR // This is used not by the parser, but by the tokenizer.
+ // do not remove.
+
+/*
+ *These are the C# keywords
+ */
+%token ABSTRACT
+%token AS
+%token ADD
+%token BASE
+%token BOOL
+%token BREAK
+%token BYTE
+%token CASE
+%token CATCH
+%token CHAR
+%token CHECKED
+%token CLASS
+%token CONST
+%token CONTINUE
+%token DECIMAL
+%token DEFAULT
+%token DELEGATE
+%token DO
+%token DOUBLE
+%token ELSE
+%token ENUM
+%token EVENT
+%token EXPLICIT
+%token EXTERN
+%token FALSE
+%token FINALLY
+%token FIXED
+%token FLOAT
+%token FOR
+%token FOREACH
+%token GOTO
+%token IF
+%token IMPLICIT
+%token IN
+%token INT
+%token INTERFACE
+%token INTERNAL
+%token IS
+%token LOCK
+%token LONG
+%token NAMESPACE
+%token NEW
+%token NULL
+%token OBJECT
+%token OPERATOR
+%token OUT
+%token OVERRIDE
+%token PARAMS
+%token PRIVATE
+%token PROTECTED
+%token PUBLIC
+%token READONLY
+%token REF
+%token RETURN
+%token REMOVE
+%token SBYTE
+%token SEALED
+%token SHORT
+%token SIZEOF
+%token STATIC
+%token STRING
+%token STRUCT
+%token SWITCH
+%token THIS
+%token THROW
+%token TRUE
+%token TRY
+%token TYPEOF
+%token UINT
+%token ULONG
+%token UNCHECKED
+%token UNSAFE
+%token USHORT
+%token USING
+%token VIRTUAL
+%token VOID
+%token WHILE
+
+/* C# keywords which are not really keywords */
+%token GET "get"
+%token SET "set"
+
+/* C# single character operators/punctuation. */
+%token OPEN_BRACE "{"
+%token CLOSE_BRACE "}"
+%token OPEN_BRACKET "["
+%token CLOSE_BRACKET "]"
+%token OPEN_PARENS "("
+%token CLOSE_PARENS ")"
+%token DOT "."
+%token COMMA ","
+%token COLON ":"
+%token SEMICOLON ";"
+%token TILDE "~"
+
+%token PLUS "+"
+%token MINUS "-"
+%token BANG "!"
+%token ASSIGN "="
+%token OP_LT "<"
+%token OP_GT ">"
+%token BITWISE_AND "&"
+%token BITWISE_OR "|"
+%token STAR "*"
+%token PERCENT "%"
+%token DIV "/"
+%token CARRET "^"
+%token INTERR "?"
+
+/* C# multi-character operators. */
+%token OP_INC "++"
+%token OP_DEC "--"
+%token OP_SHIFT_LEFT "<<"
+%token OP_SHIFT_RIGHT ">>"
+%token OP_LE "<="
+%token OP_GE ">="
+%token OP_EQ "=="
+%token OP_NE "!="
+%token OP_AND "&&"
+%token OP_OR "||"
+%token OP_MULT_ASSIGN "*="
+%token OP_DIV_ASSIGN "/="
+%token OP_MOD_ASSIGN "%="
+%token OP_ADD_ASSIGN "+="
+%token OP_SUB_ASSIGN "-="
+%token OP_SHIFT_LEFT_ASSIGN "<<="
+%token OP_SHIFT_RIGHT_ASSIGN ">>="
+%token OP_AND_ASSIGN "&="
+%token OP_XOR_ASSIGN "^="
+%token OP_OR_ASSIGN "|="
+%token OP_PTR "->"
+
+/* Numbers */
+%token LITERAL_INTEGER "int literal"
+%token LITERAL_FLOAT "float literal"
+%token LITERAL_DOUBLE "double literal"
+%token LITERAL_DECIMAL "decimal literal"
+%token LITERAL_CHARACTER "character literal"
+%token LITERAL_STRING "string literal"
+
+%token IDENTIFIER
+
+/* Add precedence rules to solve dangling else s/r conflict */
+%nonassoc IF
+%nonassoc ELSE
+
+%start compilation_unit
+/*%start namespace_declaration */
+%%
+
+compilation_unit
+ : opt_using_directives opt_attributes opt_namespace_member_declarations
+ EOF
+ {
+ // At some point check that using only comes *before* any namespaces
+ }
+ ;
+
+using_directives
+ : using_directive
+ | using_directives using_directive
+ ;
+
+using_directive
+ : using_alias_directive
+ | using_namespace_directive
+ ;
+
+using_alias_directive
+ : USING IDENTIFIER ASSIGN
+ namespace_or_type_name SEMICOLON {
+ }
+ ;
+
+using_namespace_directive
+ : USING namespace_name SEMICOLON
+ {
+ current_namespace.Using ((string) $2);
+ }
+ ;
+
+namespace_declarations
+ : namespace_declaration
+ | namespace_declarations namespace_declaration
+
+namespace_declaration
+ : NAMESPACE qualified_identifier
+ {
+ current_namespace = new Namespace (current_namespace, (string) $2);
+ }
+ namespace_body opt_semicolon
+ {
+ current_namespace = current_namespace.Parent;
+ }
+ ;
+
+opt_semicolon
+ : /* empty */
+ | SEMICOLON
+ ;
+
+opt_comma
+ : /* empty */
+ | COMMA
+ ;
+
+qualified_identifier
+ : IDENTIFIER
+ | qualified_identifier DOT IDENTIFIER {
+ $$ = (($1).ToString ()) + "." + ($3.ToString ()); }
+ ;
+
+
+namespace_name
+ : namespace_or_type_name
+ ;
+
+namespace_body
+ : OPEN_BRACE
+ opt_using_directives
+ opt_namespace_member_declarations
+ CLOSE_BRACE {
+ }
+ ;
+
+opt_using_directives
+ : /* empty */
+ | using_directives
+ ;
+
+opt_namespace_member_declarations
+ : /* empty */
+ | namespace_member_declarations
+ ;
+
+namespace_member_declarations
+ : namespace_member_declaration
+ | namespace_member_declarations namespace_member_declaration
+ ;
+
+namespace_member_declaration
+ : type_declaration
+ {
+ int mod_flags = 0;
+ string name = "";
+
+ if ($1 is Class){
+ Class c = (Class) $1;
+ mod_flags = c.ModFlags;
+ name = c.Name;
+ } else if ($1 is Struct){
+ Struct s = (Struct) $1;
+ mod_flags = s.ModFlags;
+ name = s.Name;
+ } else
+ break;
+
+ //
+ // We remove this error until we can
+ //if ((mod_flags & (Modifiers.PRIVATE|Modifiers.PROTECTED)) != 0){
+ // error (1527, "Namespace elements cant be explicitly " +
+ // "declared private or protected in `" + name + "'");
+ //}
+ }
+ | namespace_declaration
+ ;
+
+type_declaration
+ : class_declaration
+ | struct_declaration
+ | interface_declaration
+ | enum_declaration
+ | delegate_declaration // finishme
+ ;
+
+//
+// Attributes 17.2
+//
+opt_attributes
+ : /* empty */
+ | attributes
+ ;
+
+attributes
+ : attribute_sections
+ ;
+
+attribute_sections
+ : attribute_section
+ | attribute_sections attribute_section
+ ;
+
+attribute_section
+ : OPEN_BRACKET
+ opt_attribute_target_specifier attribute_list
+ /* FIXME: opt_comma */
+ CLOSE_BRACKET
+ ;
+
+opt_attribute_target_specifier
+ : /* empty */
+ | attribute_target_specifier
+ ;
+
+attribute_target_specifier
+ : attribute_target COLON
+ ;
+
+attribute_target
+ : IDENTIFIER {
+ // if (Collection.Contains ($$))... FIXME
+ note ("Allows: assembly, field, method, module, param, property, type");
+ }
+ | EVENT
+ | RETURN
+ ;
+
+attribute_list
+ : attribute
+ | attribute_list COMMA attribute
+ ;
+
+attribute
+ : attribute_name
+ | opt_attribute_arguments
+ ;
+
+attribute_name
+ : type_name { /* reserved attribute name or identifier: 17.4 */ }
+ ;
+
+opt_attribute_arguments
+ : /* empty */
+ | OPEN_PARENS attribute_arguments CLOSE_PARENS
+ ;
+
+attribute_arguments
+ : expression
+ | attribute_arguments COMMA expression
+ ;
+
+
+opt_dimension_separators
+ : /* empty */
+ | dimension_separators
+ ;
+
+dimension_separators
+ : COMMA
+ | dimension_separators COMMA
+ ;
+
+class_body
+ : OPEN_BRACE opt_class_member_declarations CLOSE_BRACE
+ ;
+
+opt_class_member_declarations
+ : /* empty */
+ | class_member_declarations
+ ;
+
+class_member_declarations
+ : class_member_declaration
+ | class_member_declarations
+ class_member_declaration
+ ;
+
+class_member_declaration
+ : constant_declaration // done
+ | field_declaration // done
+ | method_declaration // done
+ | property_declaration // done
+ | event_declaration // finishme
+ | indexer_declaration // finishme
+ | operator_declaration // finishme
+ | constructor_declaration // done
+ | destructor_declaration // done
+ | type_declaration
+ ;
+
+struct_declaration
+ : opt_attributes
+ opt_modifiers
+ STRUCT IDENTIFIER
+ {
+ Struct new_struct;
+ string full_struct_name = MakeName ((string) $4);
+
+ new_struct = new Struct (current_container, full_struct_name, (int) $2);
+ current_container = new_struct;
+ current_container.Namespace = current_namespace;
+ }
+ opt_struct_interfaces
+ struct_body
+ opt_semicolon
+ {
+ Struct new_struct = (Struct) current_container;
+
+ current_container = current_container.Parent;
+ CheckDef (current_container.AddStruct (new_struct), new_struct.Name);
+ $$ = new_struct;
+ }
+ ;
+
+opt_struct_interfaces
+ : /* empty */
+ | struct_interfaces
+ ;
+
+struct_interfaces
+ : struct_interface
+ | struct_interfaces struct_interface
+ ;
+
+struct_interface
+ : COLON type_list
+ ;
+
+struct_body
+ : OPEN_BRACE opt_struct_member_declarations CLOSE_BRACE
+ ;
+
+opt_struct_member_declarations
+ : /* empty */
+ | struct_member_declarations
+ ;
+
+struct_member_declarations
+ : struct_member_declaration
+ | struct_member_declarations struct_member_declaration
+ ;
+
+struct_member_declaration
+ : constant_declaration
+ | field_declaration
+ | method_declaration
+ | property_declaration
+ | event_declaration
+ | indexer_declaration
+ | operator_declaration
+ | constructor_declaration
+ | type_declaration
+ ;
+
+constant_declaration
+ : opt_attributes
+ opt_modifiers
+ CONST
+ type
+ constant_declarators
+ SEMICOLON
+ {
+ Modifiers.Check (Constant.AllowedModifiers, (int) $2, Modifiers.PRIVATE);
+
+ foreach (DictionaryEntry constant in (ArrayList) $5){
+ Constant c = new Constant (
+ (TypeRef) $4, (string) constant.Key,
+ (Expression) constant.Value);
+
+ CheckDef (current_container.AddConstant (c), c.Name);
+ }
+ }
+ ;
+
+constant_declarators
+ : constant_declarator
+ {
+ ArrayList constants = new ArrayList ();
+ constants.Add ($1);
+ $$ = constants;
+ }
+ | constant_declarators COMMA constant_declarator
+ {
+ ArrayList constants = (ArrayList) $1;
+
+ constants.Add ($3);
+ }
+ ;
+
+constant_declarator
+ : IDENTIFIER ASSIGN constant_expression {
+ $$ = new DictionaryEntry ($1, $3);
+ }
+ ;
+
+field_declaration
+ : opt_attributes
+ opt_modifiers
+ type
+ variable_declarators
+ SEMICOLON
+ {
+ TypeRef typeref = (TypeRef) $3;
+ int mod = (int) $2;
+
+ foreach (VariableDeclaration var in (ArrayList) $4){
+ Field field = new Field (typeref, mod, var.identifier,
+ var.expression_or_array_initializer);
+
+ CheckDef (current_container.AddField (field), field.Name);
+ }
+ }
+
+ ;
+
+variable_declarators
+ : variable_declarator
+ {
+ ArrayList decl = new ArrayList ();
+ $$ = decl;
+ decl.Add ($1);
+ }
+ | variable_declarators COMMA variable_declarator
+ {
+ ArrayList decls = (ArrayList) $1;
+ decls.Add ($3);
+ $$ = $1;
+ }
+ ;
+
+variable_declarator
+ : IDENTIFIER ASSIGN variable_initializer
+ {
+ $$ = new VariableDeclaration ((string) $1, $3);
+ }
+ | IDENTIFIER
+ {
+ $$ = new VariableDeclaration ((string) $1, null);
+ }
+ ;
+
+variable_initializer
+ : expression
+ | array_initializer
+ ;
+
+method_declaration
+ : method_header
+ method_body
+ {
+ Method method = (Method) $1;
+
+ method.Block = (Block) $2;
+ CheckDef (current_container.AddMethod (method), method.Name);
+
+ current_local_parameters = null;
+ }
+ ;
+
+method_header
+ : opt_attributes
+ opt_modifiers
+ type
+ member_name
+ OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
+ {
+ Method method = new Method ((TypeRef) $3, (int) $2, (string) $4, (Parameters) $6);
+
+ current_local_parameters = (Parameters) $6;
+
+ $$ = method;
+ }
+ | opt_attributes
+ opt_modifiers
+ VOID
+ member_name
+ OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
+ {
+ Method method = new Method (type ("void"), (int) $2, (string) $4, (Parameters) $6);
+
+ current_local_parameters = (Parameters) $6;
+ $$ = method;
+ }
+ ;
+
+method_body
+ : block
+ | SEMICOLON { $$ = null; }
+ ;
+
+opt_formal_parameter_list
+ : /* empty */ { $$ = new Parameters (null, null); }
+ | formal_parameter_list
+ ;
+
+formal_parameter_list
+ : fixed_parameters
+ {
+ $$ = new Parameters ((ParameterCollection) $1, null);
+ }
+ | fixed_parameters COMMA parameter_array
+ {
+ $$ = new Parameters ((ParameterCollection) $1, (Parameter) $3);
+ }
+ | parameter_array
+ {
+ $$ = new Parameters (null, (Parameter) $1);
+ }
+ ;
+
+fixed_parameters
+ : fixed_parameter
+ {
+ ParameterCollection pars = new ParameterCollection ();
+ pars.Add ((Parameter) $1);
+ $$ = pars;
+ }
+ | fixed_parameters COMMA fixed_parameter
+ {
+ ParameterCollection pars = (ParameterCollection) $1;
+ pars.Add ((Parameter) $3);
+ $$ = $1;
+ }
+ ;
+
+fixed_parameter
+ : opt_attributes
+ opt_parameter_modifier
+ type
+ IDENTIFIER
+ {
+ $$ = new Parameter ((TypeRef) $3, (string) $4, (Parameter.Modifier) $2);
+ }
+ ;
+
+opt_parameter_modifier
+ : /* empty */ { $$ = Parameter.Modifier.NONE; }
+ | parameter_modifier
+ ;
+
+parameter_modifier
+ : REF { $$ = Parameter.Modifier.REF; }
+ | OUT { $$ = Parameter.Modifier.OUT; }
+ ;
+
+parameter_array
+ : opt_attributes PARAMS type IDENTIFIER
+ {
+ $$ = new Parameter ((TypeRef) $3, (string) $4, Parameter.Modifier.PARAMS);
+ note ("type must be a single-dimension array type");
+ }
+ ;
+
+member_name
+ : IDENTIFIER { $$ = $1.ToString (); }
+ | interface_type DOT IDENTIFIER { $$ = $1.ToString () + "." + $3.ToString (); }
+ ;
+
+property_declaration
+ : opt_attributes
+ opt_modifiers
+ type member_name
+ OPEN_BRACE
+ {
+ Parameter implicit_value_parameter;
+ implicit_value_parameter = new Parameter ((TypeRef) $3, "value", Parameter.Modifier.NONE);
+
+ lexer.properties = true;
+
+ implicit_value_parameters = new ParameterCollection ();
+ implicit_value_parameters.Add (implicit_value_parameter);
+ }
+ accessor_declarations
+ {
+ lexer.properties = false;
+ }
+ CLOSE_BRACE
+ {
+ Property prop;
+ DictionaryEntry pair = (DictionaryEntry) $7;
+ Block get_block = null;
+ Block set_block = null;
+
+ if (pair.Key != null)
+ get_block = (Block) pair.Key;
+ if (pair.Value != null)
+ set_block = (Block) pair.Value;
+
+ prop = new Property ((TypeRef) $3, (string) $4, (int) $2, get_block, set_block);
+
+ CheckDef (current_container.AddProperty (prop), prop.Name);
+ implicit_value_parameters = null;
+ }
+ ;
+
+accessor_declarations
+ : get_accessor_declaration opt_set_accessor_declaration
+ {
+ $$ = new DictionaryEntry ($1, $2);
+ }
+ | set_accessor_declaration opt_get_accessor_declaration
+ {
+ $$ = new DictionaryEntry ($2, $1);
+ }
+ ;
+
+opt_get_accessor_declaration
+ : /* empty */ { $$ = null; }
+ | get_accessor_declaration
+ ;
+
+opt_set_accessor_declaration
+ : /* empty */ { $$ = null; }
+ | set_accessor_declaration
+ ;
+
+get_accessor_declaration
+ : opt_attributes GET accessor_body
+ {
+ $$ = $3;
+ }
+ ;
+
+set_accessor_declaration
+ : opt_attributes SET
+ {
+ current_local_parameters = new Parameters (implicit_value_parameters, null);
+ }
+ accessor_body
+ {
+ $$ = $4;
+ current_local_parameters = null;
+ }
+ ;
+
+accessor_body
+ : block
+ | SEMICOLON { $$ = new Block (null); }
+ ;
+
+interface_declaration
+ : opt_attributes
+ opt_modifiers
+ INTERFACE IDENTIFIER
+ {
+ Interface new_interface;
+ string full_interface_name = MakeName ((string) $4);
+
+ new_interface = new Interface (current_container, full_interface_name, (int) $2);
+ if (current_interface != null)
+ error (-2, "Internal compiler error: interface inside interface");
+ current_interface = new_interface;
+ }
+ opt_interface_base
+ interface_body
+ {
+ Interface new_interface = (Interface) current_interface;
+
+ if ($6 != null)
+ new_interface.Bases = (ArrayList) $6;
+
+ current_interface = null;
+ CheckDef (current_container.AddInterface (new_interface), new_interface.Name);
+ }
+ ;
+
+opt_interface_base
+ : /* empty */ { $$ = null; }
+ | interface_base
+ ;
+
+interface_base
+ : COLON interface_type_list { $$ = $2; }
+ ;
+
+interface_type_list
+ : interface_type
+ {
+ ArrayList interfaces = new ArrayList ();
+
+ interfaces.Add ($1);
+ }
+ | interface_type_list COMMA interface_type
+ {
+ ArrayList interfaces = (ArrayList) $1;
+ interfaces.Add ($3);
+ $$ = interfaces;
+ }
+ ;
+
+interface_body
+ : OPEN_BRACE
+ opt_interface_member_declarations
+ CLOSE_BRACE
+ ;
+
+opt_interface_member_declarations
+ : /* empty */
+ | interface_member_declarations
+ ;
+
+interface_member_declarations
+ : interface_member_declaration
+ | interface_member_declarations interface_member_declaration
+ ;
+
+interface_member_declaration
+ : interface_method_declaration
+ {
+ InterfaceMethod m = (InterfaceMethod) $1;
+
+ CheckDef (current_interface.AddMethod (m), m.Name);
+ }
+ | interface_property_declaration
+ {
+ InterfaceProperty p = (InterfaceProperty) $1;
+
+ CheckDef (current_interface.AddProperty (p), p.Name);
+ }
+ | interface_event_declaration
+ {
+ InterfaceEvent e = (InterfaceEvent) $1;
+
+ CheckDef (current_interface.AddEvent (e), e.Name);
+ }
+ | interface_indexer_declaration
+ {
+ InterfaceIndexer i = (InterfaceIndexer) $1;
+
+ CheckDef (current_interface.AddIndexer (i), "indexer");
+ }
+ ;
+
+opt_new
+ : /* empty */ { $$ = false; }
+ | NEW { $$ = true; }
+ ;
+
+interface_method_declaration
+ : opt_attributes opt_new type IDENTIFIER
+ OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
+ SEMICOLON
+ {
+ $$ = new InterfaceMethod ((TypeRef) $3, (string) $4, (bool) $2, (Parameters) $6);
+ }
+ | opt_attributes opt_new VOID IDENTIFIER
+ OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
+ SEMICOLON
+ {
+ $$ = new InterfaceMethod (type ("void"), (string) $4, (bool) $2, (Parameters) $6);
+ }
+ ;
+
+interface_property_declaration
+ : opt_attributes
+ opt_new
+ type IDENTIFIER
+ OPEN_BRACE
+ { lexer.properties = true; }
+ interface_accesors
+ { lexer.properties = false; }
+ CLOSE_BRACE
+ {
+ int gs = (int) $7;
+
+ $$ = new InterfaceProperty ((TypeRef) $3, (string) $4, (bool) $2,
+ (gs & 1) == 1, (gs & 2) == 2);
+ }
+ ;
+
+interface_accesors
+ : opt_attributes GET SEMICOLON { $$ = 1; }
+ | opt_attributes SET SEMICOLON { $$ = 2; }
+ | opt_attributes GET SEMICOLON opt_attributes SET SEMICOLON
+ { $$ = 3; }
+ | opt_attributes SET SEMICOLON opt_attributes GET SEMICOLON
+ { $$ = 3; }
+ ;
+
+interface_event_declaration
+ : opt_attributes opt_new EVENT type IDENTIFIER SEMICOLON
+ {
+ $$ = new InterfaceEvent ((TypeRef) $4, (string) $5, (bool) $2);
+ }
+ ;
+
+interface_indexer_declaration
+ : opt_attributes opt_new type THIS
+ OPEN_BRACKET formal_parameter_list CLOSE_BRACKET
+ OPEN_BRACE
+ { lexer.properties = true; }
+ interface_accesors
+ { lexer.properties = false; }
+ CLOSE_BRACE
+ {
+ int a_flags = (int) $10;
+
+ bool do_get = (a_flags & 1) == 1;
+ bool do_set = (a_flags & 2) == 2;
+
+ $$ = new InterfaceIndexer ((TypeRef) $3, (Parameters) $6, do_get, do_set, (bool) $2);
+ }
+ ;
+
+operator_declaration
+ : opt_attributes opt_modifiers operator_declarator block
+ {
+ // FIXME: validate that opt_modifiers is exactly: PUBLIC and STATIC
+ }
+ ;
+
+operator_declarator
+ : type OPERATOR overloadable_operator
+ OPEN_PARENS type IDENTIFIER CLOSE_PARENS
+ {
+ // FIXME: since reduce/reduce on this
+ // rule, validate overloadable_operator is unary
+ }
+ | type OPERATOR overloadable_operator
+ OPEN_PARENS
+ type IDENTIFIER COMMA