Browse Source

Updated/merged mcs.

newNRvisualizers
Mike Krüger 14 years ago
parent
commit
574994c01a
  1. 99
      ICSharpCode.NRefactory.CSharp/Parser/CSharpParser.cs
  2. 47
      ICSharpCode.NRefactory.CSharp/Parser/mcs/anonymous.cs
  3. 4
      ICSharpCode.NRefactory.CSharp/Parser/mcs/async.cs
  4. 1241
      ICSharpCode.NRefactory.CSharp/Parser/mcs/class.cs
  5. 4
      ICSharpCode.NRefactory.CSharp/Parser/mcs/const.cs
  6. 5377
      ICSharpCode.NRefactory.CSharp/Parser/mcs/cs-parser.cs
  7. 69
      ICSharpCode.NRefactory.CSharp/Parser/mcs/cs-parser.jay
  8. 46
      ICSharpCode.NRefactory.CSharp/Parser/mcs/cs-tokenizer.cs
  9. 22
      ICSharpCode.NRefactory.CSharp/Parser/mcs/decl.cs
  10. 14
      ICSharpCode.NRefactory.CSharp/Parser/mcs/delegate.cs
  11. 50
      ICSharpCode.NRefactory.CSharp/Parser/mcs/driver.cs
  12. 5
      ICSharpCode.NRefactory.CSharp/Parser/mcs/dynamic.cs
  13. 19
      ICSharpCode.NRefactory.CSharp/Parser/mcs/enum.cs
  14. 61
      ICSharpCode.NRefactory.CSharp/Parser/mcs/eval.cs
  15. 7
      ICSharpCode.NRefactory.CSharp/Parser/mcs/expression.cs
  16. 11
      ICSharpCode.NRefactory.CSharp/Parser/mcs/field.cs
  17. 23
      ICSharpCode.NRefactory.CSharp/Parser/mcs/flowanalysis.cs
  18. 14
      ICSharpCode.NRefactory.CSharp/Parser/mcs/iterators.cs
  19. 2
      ICSharpCode.NRefactory.CSharp/Parser/mcs/linq.cs
  20. 7
      ICSharpCode.NRefactory.CSharp/Parser/mcs/location.cs
  21. 2
      ICSharpCode.NRefactory.CSharp/Parser/mcs/membercache.cs
  22. 19
      ICSharpCode.NRefactory.CSharp/Parser/mcs/method.cs
  23. 10
      ICSharpCode.NRefactory.CSharp/Parser/mcs/module.cs
  24. 70
      ICSharpCode.NRefactory.CSharp/Parser/mcs/namespace.cs
  25. 24
      ICSharpCode.NRefactory.CSharp/Parser/mcs/property.cs
  26. 3
      ICSharpCode.NRefactory.CSharp/Parser/mcs/settings.cs
  27. 32
      ICSharpCode.NRefactory.CSharp/Parser/mcs/statement.cs
  28. 18
      ICSharpCode.NRefactory.CSharp/Parser/mcs/visit.cs

99
ICSharpCode.NRefactory.CSharp/Parser/CSharpParser.cs

@ -299,23 +299,36 @@ namespace ICSharpCode.NRefactory.CSharp
public override void Visit (NamespaceContainer nspace) public override void Visit (NamespaceContainer nspace)
{ {
NamespaceDeclaration nDecl = null; NamespaceDeclaration nDecl = null;
var loc = LocationsBag.GetLocations (nspace);
if (nspace.NS != null && !string.IsNullOrEmpty (nspace.NS.Name)) { if (nspace.NS != null && !string.IsNullOrEmpty (nspace.NS.Name)) {
nDecl = new NamespaceDeclaration (); nDecl = new NamespaceDeclaration ();
// nDecl.AddChild (new CSharpTokenNode (Convert (nspace.NamespaceLocation), "namespace".Length), NamespaceDeclaration.Roles.Keyword); if (loc != null)
ConvertNamespaceName (nspace.NS.MemberName, nDecl); nDecl.AddChild (new CSharpTokenNode (Convert (loc[0]), "namespace".Length), NamespaceDeclaration.Roles.Keyword);
// nDecl.AddChild (new CSharpTokenNode (Convert (nspace.OpenBrace), 1), NamespaceDeclaration.Roles.LBrace); ConvertNamespaceName (nspace.RealMemberName, nDecl);
if (loc != null && loc.Count > 1)
nDecl.AddChild (new CSharpTokenNode (Convert (loc[1]), 1), NamespaceDeclaration.Roles.LBrace);
AddToNamespace (nDecl); AddToNamespace (nDecl);
namespaceStack.Push (nDecl); namespaceStack.Push (nDecl);
} }
if (nspace.Usings != null) {
foreach (var us in nspace.Usings) {
us.Accept (this);
}
}
foreach (var container in nspace.Containers) { if (nspace.Containers != null) {
container.Accept (this); foreach (var container in nspace.Containers) {
Console.WriteLine ("add container:"+ container);
container.Accept (this);
}
} }
if (nDecl != null) { if (nDecl != null) {
// nDecl.AddChild (new CSharpTokenNode (Convert (nspace.CloseBrace), 1), NamespaceDeclaration.Roles.RBrace); if (loc != null && loc.Count > 2)
// if (!nspace.OptSemicolon.IsNull) nDecl.AddChild (new CSharpTokenNode (Convert (loc[2]), 1), NamespaceDeclaration.Roles.RBrace);
// nDecl.AddChild (new CSharpTokenNode (Convert (nspace.OptSemicolon), 1), NamespaceDeclaration.Roles.Semicolon); if (loc != null && loc.Count > 3)
nDecl.AddChild (new CSharpTokenNode (Convert (loc[3]), 1), NamespaceDeclaration.Roles.Semicolon);
namespaceStack.Pop (); namespaceStack.Pop ();
} }
@ -347,35 +360,44 @@ namespace ICSharpCode.NRefactory.CSharp
} }
} }
// public override void Visit (UsingsBag.Using u) public override void Visit (UsingNamespace un)
// { {
// UsingDeclaration ud = new UsingDeclaration (); var ud = new UsingDeclaration ();
// ud.AddChild (new CSharpTokenNode (Convert (u.UsingLocation), "using".Length), UsingDeclaration.Roles.Keyword); var loc = LocationsBag.GetLocations (un);
// ud.AddChild (ConvertToType (u.NSpace), UsingDeclaration.ImportRole); ud.AddChild (new CSharpTokenNode (Convert (un.Location), "using".Length), UsingDeclaration.Roles.Keyword);
// ud.AddChild (new CSharpTokenNode (Convert (u.SemicolonLocation), 1), UsingDeclaration.Roles.Semicolon); ud.AddChild (ConvertToType (un.NamespaceExpression), UsingDeclaration.ImportRole);
// AddToNamespace (ud); if (loc != null)
// } ud.AddChild (new CSharpTokenNode (Convert (loc[0]), 1), UsingDeclaration.Roles.Semicolon);
AddToNamespace (ud);
// public override void Visit (UsingsBag.AliasUsing u) }
// {
// UsingAliasDeclaration ud = new UsingAliasDeclaration (); public override void Visit (UsingAliasNamespace uan)
// ud.AddChild (new CSharpTokenNode (Convert (u.UsingLocation), "using".Length), UsingAliasDeclaration.Roles.Keyword); {
// ud.AddChild (Identifier.Create (u.Identifier.Value, Convert (u.Identifier.Location)), UsingAliasDeclaration.AliasRole); var ud = new UsingAliasDeclaration ();
// ud.AddChild (new CSharpTokenNode (Convert (u.AssignLocation), 1), UsingAliasDeclaration.Roles.Assign); var loc = LocationsBag.GetLocations (uan);
// ud.AddChild (ConvertToType (u.Nspace), UsingAliasDeclaration.ImportRole);
// ud.AddChild (new CSharpTokenNode (Convert (u.SemicolonLocation), 1), UsingAliasDeclaration.Roles.Semicolon); ud.AddChild (new CSharpTokenNode (Convert (uan.Location), "using".Length), UsingAliasDeclaration.Roles.Keyword);
// AddToNamespace (ud); ud.AddChild (Identifier.Create (uan.Alias.Value, Convert (uan.Alias.Location)), UsingAliasDeclaration.AliasRole);
// } if (loc != null)
// ud.AddChild (new CSharpTokenNode (Convert (loc[0]), 1), UsingAliasDeclaration.Roles.Assign);
// public override void Visit (UsingsBag.ExternAlias u) ud.AddChild (ConvertToType (uan.NamespaceExpression), UsingAliasDeclaration.ImportRole);
// { if (loc != null && loc.Count > 1)
// var ud = new ExternAliasDeclaration (); ud.AddChild (new CSharpTokenNode (Convert (loc[1]), 1), UsingAliasDeclaration.Roles.Semicolon);
// ud.AddChild (new CSharpTokenNode (Convert (u.ExternLocation), "extern".Length), ExternAliasDeclaration.Roles.Keyword); AddToNamespace (ud);
// ud.AddChild (new CSharpTokenNode (Convert (u.AliasLocation), "alias".Length), ExternAliasDeclaration.AliasRole); }
// ud.AddChild (Identifier.Create (u.Identifier.Value, Convert (u.Identifier.Location)), ExternAliasDeclaration.Roles.Identifier);
// ud.AddChild (new CSharpTokenNode (Convert (u.SemicolonLocation), 1), UsingAliasDeclaration.Roles.Semicolon); public override void Visit (UsingExternAlias uea)
// AddToNamespace (ud); {
// } var ud = new ExternAliasDeclaration ();
var loc = LocationsBag.GetLocations (uea);
ud.AddChild (new CSharpTokenNode (Convert (uea.Location), "extern".Length), ExternAliasDeclaration.Roles.Keyword);
if (loc != null)
ud.AddChild (new CSharpTokenNode (Convert (loc[0]), "alias".Length), ExternAliasDeclaration.AliasRole);
ud.AddChild (Identifier.Create (uea.Alias.Value, Convert (uea.Alias.Location)), ExternAliasDeclaration.Roles.Identifier);
if (loc != null && loc.Count > 1)
ud.AddChild (new CSharpTokenNode (Convert (loc[1]), 1), UsingAliasDeclaration.Roles.Semicolon);
AddToNamespace (ud);
}
AstType ConvertImport (MemberName memberName) AstType ConvertImport (MemberName memberName)
{ {
@ -613,7 +635,7 @@ namespace ICSharpCode.NRefactory.CSharp
newType.AddChild (new CSharpTokenNode (Convert (location[curLoc++]), 1), AstNode.Roles.LBrace); newType.AddChild (new CSharpTokenNode (Convert (location[curLoc++]), 1), AstNode.Roles.LBrace);
typeStack.Push (newType); typeStack.Push (newType);
foreach (EnumMember member in e.OrderedAllMembers) { foreach (EnumMember member in e.Members) {
Visit (member); Visit (member);
if (location != null && curLoc < location.Count - 1) //last one is closing brace if (location != null && curLoc < location.Count - 1) //last one is closing brace
newType.AddChild (new CSharpTokenNode (Convert (location[curLoc++]), 1), AstNode.Roles.Comma); newType.AddChild (new CSharpTokenNode (Convert (location[curLoc++]), 1), AstNode.Roles.Comma);
@ -3517,6 +3539,7 @@ namespace ICSharpCode.NRefactory.CSharp
}; };
var unit = Parse (top, fileName, lineModifier); var unit = Parse (top, fileName, lineModifier);
unit.Errors.AddRange (errorReportPrinter.Errors); unit.Errors.AddRange (errorReportPrinter.Errors);
CompilerCallableEntryPoint.Reset ();
return unit; return unit;
} }
} }

47
ICSharpCode.NRefactory.CSharp/Parser/mcs/anonymous.cs

@ -183,7 +183,6 @@ namespace Mono.CSharp {
// Unique storey ID // Unique storey ID
public readonly int ID; public readonly int ID;
static int unique_id;
public readonly Block OriginalSourceBlock; public readonly Block OriginalSourceBlock;
@ -202,11 +201,11 @@ namespace Mono.CSharp {
public Expression Instance; public Expression Instance;
public AnonymousMethodStorey (Block block, TypeDefinition parent, MemberBase host, TypeParameters tparams, string name) public AnonymousMethodStorey (Block block, TypeDefinition parent, MemberBase host, TypeParameters tparams, string name)
: base (parent, MakeMemberName (host, name, unique_id, tparams, block.StartLocation), : base (parent, MakeMemberName (host, name, parent.Module.CounterAnonymousContainers, tparams, block.StartLocation),
tparams, Modifiers.SEALED) tparams, Modifiers.SEALED)
{ {
OriginalSourceBlock = block; OriginalSourceBlock = block;
ID = unique_id++; ID = parent.Module.CounterAnonymousContainers++;
} }
public void AddCapturedThisField (EmitContext ec) public void AddCapturedThisField (EmitContext ec)
@ -497,8 +496,10 @@ namespace Mono.CSharp {
} }
} }
public override void EmitContainer () public override void Emit ()
{ {
base.Emit ();
SymbolWriter.DefineAnonymousScope (ID); SymbolWriter.DefineAnonymousScope (ID);
if (hoisted_this != null) if (hoisted_this != null)
@ -519,8 +520,6 @@ namespace Mono.CSharp {
SymbolWriter.DefineCapturedScope (ID, sf.Storey.ID, sf.Field.Name); SymbolWriter.DefineCapturedScope (ID, sf.Storey.ID, sf.Field.Name);
} }
} }
base.EmitContainer ();
} }
// //
@ -597,11 +596,6 @@ namespace Mono.CSharp {
public IList<ExplicitBlock> ReferencesFromChildrenBlock { public IList<ExplicitBlock> ReferencesFromChildrenBlock {
get { return children_references; } get { return children_references; }
} }
public static void Reset ()
{
unique_id = 0;
}
} }
public abstract class HoistedVariable public abstract class HoistedVariable
@ -1337,7 +1331,7 @@ namespace Mono.CSharp {
this.Storey = storey; this.Storey = storey;
this.RealName = real_name; this.RealName = real_name;
Parent.PartialContainer.AddMethod (this); Parent.PartialContainer.Members.Add (this);
Block = new ToplevelBlock (am.block, parameters); Block = new ToplevelBlock (am.block, parameters);
} }
@ -1496,8 +1490,6 @@ namespace Mono.CSharp {
string block_name; string block_name;
TypeInferenceContext return_inference; TypeInferenceContext return_inference;
static int unique_id;
public AnonymousMethodBody (ParametersCompiled parameters, public AnonymousMethodBody (ParametersCompiled parameters,
ParametersBlock block, TypeSpec return_type, TypeSpec delegate_type, ParametersBlock block, TypeSpec return_type, TypeSpec delegate_type,
Location loc) Location loc)
@ -1587,7 +1579,7 @@ namespace Mono.CSharp {
MemberCore mc = ec.MemberContext as MemberCore; MemberCore mc = ec.MemberContext as MemberCore;
string name = CompilerGeneratedClass.MakeName (parent != storey ? block_name : null, string name = CompilerGeneratedClass.MakeName (parent != storey ? block_name : null,
"m", null, unique_id++); "m", null, ec.Module.CounterAnonymousMethods++);
MemberName member_name; MemberName member_name;
if (storey == null && ec.CurrentTypeParameters != null) { if (storey == null && ec.CurrentTypeParameters != null) {
@ -1643,7 +1635,7 @@ namespace Mono.CSharp {
// //
if (!method.MemberName.IsGeneric) { if (!method.MemberName.IsGeneric) {
var parent = method.Parent.PartialContainer; var parent = method.Parent.PartialContainer;
int id = parent.Fields == null ? 0 : parent.Fields.Count; int id = parent.AnonymousMethodsCounter++;
var cache_type = storey != null && storey.Mutator != null ? storey.Mutator.Mutate (type) : type; var cache_type = storey != null && storey.Mutator != null ? storey.Mutator.Mutate (type) : type;
am_cache = new Field (parent, new TypeExpression (cache_type, loc), am_cache = new Field (parent, new TypeExpression (cache_type, loc),
@ -1752,11 +1744,6 @@ namespace Mono.CSharp {
{ {
return TypeManager.CSharpName (type); return TypeManager.CSharpName (type);
} }
public static void Reset ()
{
unique_id = 0;
}
} }
// //
@ -1764,7 +1751,6 @@ namespace Mono.CSharp {
// //
public class AnonymousTypeClass : CompilerGeneratedClass public class AnonymousTypeClass : CompilerGeneratedClass
{ {
static int types_counter;
public const string ClassNamePrefix = "<>__AnonType"; public const string ClassNamePrefix = "<>__AnonType";
public const string SignatureForError = "anonymous type"; public const string SignatureForError = "anonymous type";
@ -1778,7 +1764,7 @@ namespace Mono.CSharp {
public static AnonymousTypeClass Create (TypeContainer parent, IList<AnonymousTypeParameter> parameters, Location loc) public static AnonymousTypeClass Create (TypeContainer parent, IList<AnonymousTypeParameter> parameters, Location loc)
{ {
string name = ClassNamePrefix + types_counter++; string name = ClassNamePrefix + parent.Module.CounterAnonymousTypes++;
ParametersCompiled all_parameters; ParametersCompiled all_parameters;
TypeParameters tparams = null; TypeParameters tparams = null;
@ -1850,7 +1836,7 @@ namespace Mono.CSharp {
new MemberName (p.Name, p.Location), null); new MemberName (p.Name, p.Location), null);
prop.Get = new Property.GetMethod (prop, 0, null, p.Location); prop.Get = new Property.GetMethod (prop, 0, null, p.Location);
prop.Get.Block = get_block; prop.Get.Block = get_block;
a_type.AddProperty (prop); a_type.AddMember (prop);
} }
if (error) if (error)
@ -1860,11 +1846,6 @@ namespace Mono.CSharp {
return a_type; return a_type;
} }
public static void Reset ()
{
types_counter = 0;
}
protected override bool DoDefineMembers () protected override bool DoDefineMembers ()
{ {
if (!base.DoDefineMembers ()) if (!base.DoDefineMembers ())
@ -1911,7 +1892,7 @@ namespace Mono.CSharp {
Expression rs_hashcode = new IntConstant (Compiler.BuiltinTypes, -2128831035, loc); Expression rs_hashcode = new IntConstant (Compiler.BuiltinTypes, -2128831035, loc);
for (int i = 0; i < parameters.Count; ++i) { for (int i = 0; i < parameters.Count; ++i) {
var p = parameters [i]; var p = parameters [i];
var f = Fields [i]; var f = (Field) Members [i * 2];
MemberAccess equality_comparer = new MemberAccess (new MemberAccess ( MemberAccess equality_comparer = new MemberAccess (new MemberAccess (
system_collections_generic, "EqualityComparer", system_collections_generic, "EqualityComparer",
@ -1988,7 +1969,7 @@ namespace Mono.CSharp {
equals.Block = equals_block; equals.Block = equals_block;
equals.Define (); equals.Define ();
AddMethod (equals); Members.Add (equals);
// //
// GetHashCode () override // GetHashCode () override
@ -2042,7 +2023,7 @@ namespace Mono.CSharp {
hashcode_block.AddStatement (new Return (hash_variable, loc)); hashcode_block.AddStatement (new Return (hash_variable, loc));
hashcode.Block = hashcode_top; hashcode.Block = hashcode_top;
hashcode.Define (); hashcode.Define ();
AddMethod (hashcode); Members.Add (hashcode);
// //
// ToString () override // ToString () override
@ -2052,7 +2033,7 @@ namespace Mono.CSharp {
tostring_block.AddStatement (new Return (string_concat, loc)); tostring_block.AddStatement (new Return (string_concat, loc));
tostring.Block = tostring_block; tostring.Block = tostring_block;
tostring.Define (); tostring.Define ();
AddMethod (tostring); Members.Add (tostring);
return true; return true;
} }

4
ICSharpCode.NRefactory.CSharp/Parser/mcs/async.cs

@ -675,10 +675,12 @@ namespace Mono.CSharp
builder = AddCompilerGeneratedField ("$builder", new TypeExpression (bt, Location)); builder = AddCompilerGeneratedField ("$builder", new TypeExpression (bt, Location));
var ctor = DefineDefaultConstructor (false);
if (!base.DoDefineMembers ()) if (!base.DoDefineMembers ())
return false; return false;
var block = instance_constructors[0].Block; Block block = ctor.Block;
var mg = MethodGroupExpr.CreatePredefined (builder_factory, bt, Location); var mg = MethodGroupExpr.CreatePredefined (builder_factory, bt, Location);
block.AddStatement ( block.AddStatement (

1241
ICSharpCode.NRefactory.CSharp/Parser/mcs/class.cs

File diff suppressed because it is too large Load Diff

4
ICSharpCode.NRefactory.CSharp/Parser/mcs/const.cs

@ -63,12 +63,12 @@ namespace Mono.CSharp {
if (declarators != null) { if (declarators != null) {
var t = new TypeExpression (MemberType, TypeExpression.Location); var t = new TypeExpression (MemberType, TypeExpression.Location);
int index = Parent.PartialContainer.Constants.IndexOf (this);
foreach (var d in declarators) { foreach (var d in declarators) {
var c = new Const (Parent, t, ModFlags & ~Modifiers.STATIC, new MemberName (d.Name.Value, d.Name.Location), OptAttributes); var c = new Const (Parent, t, ModFlags & ~Modifiers.STATIC, new MemberName (d.Name.Value, d.Name.Location), OptAttributes);
c.initializer = d.Initializer; c.initializer = d.Initializer;
((ConstInitializer) c.initializer).Name = d.Name.Value; ((ConstInitializer) c.initializer).Name = d.Name.Value;
Parent.PartialContainer.Constants.Insert (++index, c); c.Define ();
Parent.PartialContainer.Members.Add (c);
} }
} }

5377
ICSharpCode.NRefactory.CSharp/Parser/mcs/cs-parser.cs

File diff suppressed because it is too large Load Diff

69
ICSharpCode.NRefactory.CSharp/Parser/mcs/cs-parser.jay

@ -86,7 +86,7 @@ namespace Mono.CSharp
/// ///
/// Controls the verbosity of the errors produced by the parser /// Controls the verbosity of the errors produced by the parser
/// ///
static public int yacc_verbose_flag; int yacc_verbose_flag;
/// ///
/// Used by the interactive shell, flags whether EOF was reached /// Used by the interactive shell, flags whether EOF was reached
@ -978,7 +978,7 @@ constant_declaration
var lt = (Tokenizer.LocatedToken) $5; var lt = (Tokenizer.LocatedToken) $5;
var mod = (Modifiers) $2; var mod = (Modifiers) $2;
current_field = new Const (current_type, (FullNamedExpression) $4, mod, new MemberName (lt.Value, lt.Location), (Attributes) $1); current_field = new Const (current_type, (FullNamedExpression) $4, mod, new MemberName (lt.Value, lt.Location), (Attributes) $1);
current_container.PartialContainer.AddConstant ((Const) current_field); current_type.AddMember (current_field);
if ((mod & Modifiers.STATIC) != 0) { if ((mod & Modifiers.STATIC) != 0) {
report.Error (504, current_field.Location, "The constant `{0}' cannot be marked static", current_field.GetSignatureForError ()); report.Error (504, current_field.Location, "The constant `{0}' cannot be marked static", current_field.GetSignatureForError ());
@ -1060,7 +1060,7 @@ field_declaration
var lt = (Tokenizer.LocatedToken) $4; var lt = (Tokenizer.LocatedToken) $4;
current_field = new Field (current_type, type, (Modifiers) $2, new MemberName (lt.Value, lt.Location), (Attributes) $1); current_field = new Field (current_type, type, (Modifiers) $2, new MemberName (lt.Value, lt.Location), (Attributes) $1);
current_container.PartialContainer.AddField (current_field); current_type.AddField (current_field);
$$ = current_field; $$ = current_field;
} }
opt_field_initializer opt_field_initializer
@ -1087,7 +1087,7 @@ field_declaration
current_field = new FixedField (current_type, (FullNamedExpression) $4, (Modifiers) $2, current_field = new FixedField (current_type, (FullNamedExpression) $4, (Modifiers) $2,
new MemberName (lt.Value, lt.Location), (Attributes) $1); new MemberName (lt.Value, lt.Location), (Attributes) $1);
current_container.PartialContainer.AddField (current_field); current_type.AddField (current_field);
} }
fixed_field_size opt_fixed_field_declarators SEMICOLON fixed_field_size opt_fixed_field_declarators SEMICOLON
{ {
@ -1227,7 +1227,7 @@ method_declaration
// Add it early in the case of body being eof for full ast // Add it early in the case of body being eof for full ast
Method m = (Method) $1; Method m = (Method) $1;
async_block = (m.ModFlags & Modifiers.ASYNC) != 0; async_block = (m.ModFlags & Modifiers.ASYNC) != 0;
current_container.PartialContainer.AddMethod (m); current_type.AddMember (m);
} }
method_body method_body
{ {
@ -1678,7 +1678,7 @@ property_declaration
if (type.Type != null && type.Type.Kind == MemberKind.Void) if (type.Type != null && type.Type.Kind == MemberKind.Void)
report.Error (547, GetLocation ($3), "`{0}': property or indexer cannot have void type", current_property.GetSignatureForError ()); report.Error (547, GetLocation ($3), "`{0}': property or indexer cannot have void type", current_property.GetSignatureForError ());
current_container.PartialContainer.AddProperty ((Property)current_property); current_type.AddMember (current_property);
lbag.AddMember (current_property, GetModifierLocations (), GetLocation ($6)); lbag.AddMember (current_property, GetModifierLocations (), GetLocation ($6));
lexer.PropertyParsing = true; lexer.PropertyParsing = true;
@ -1712,7 +1712,7 @@ indexer_declaration
current_property = indexer; current_property = indexer;
current_container.PartialContainer.AddIndexer (indexer); current_type.AddIndexer (indexer);
lbag.AddMember (current_property, GetModifierLocations (), GetLocation ($5), GetLocation ($8), GetLocation ($9)); lbag.AddMember (current_property, GetModifierLocations (), GetLocation ($5), GetLocation ($8), GetLocation ($9));
if (type.Type != null && type.Type.Kind == MemberKind.Void) if (type.Type != null && type.Type.Kind == MemberKind.Void)
@ -1988,7 +1988,7 @@ operator_declaration
} }
// Note again, checking is done in semantic analysis // Note again, checking is done in semantic analysis
current_container.PartialContainer.AddOperator (op); current_type.AddOperator (op);
lbag.AddMember (op, GetModifierLocations (), lbag.GetLocations (decl)); lbag.AddMember (op, GetModifierLocations (), lbag.GetLocations (decl));
if ($5 == null) { // Semicolon if ($5 == null) { // Semicolon
@ -2190,7 +2190,7 @@ constructor_declarator
} }
} }
current_container.PartialContainer.AddConstructor (c); current_type.AddConstructor (c);
lbag.AddMember (c, GetModifierLocations (), GetLocation ($5), GetLocation ($7)); lbag.AddMember (c, GetModifierLocations (), GetLocation ($5), GetLocation ($7));
$$ = c; $$ = c;
@ -2286,7 +2286,7 @@ destructor_declaration
d.DocComment = ConsumeStoredComment (); d.DocComment = ConsumeStoredComment ();
d.Block = (ToplevelBlock) $8; d.Block = (ToplevelBlock) $8;
current_container.PartialContainer.AddMethod (d); current_type.AddMember (d);
lbag.AddMember (d, GetModifierLocations (), GetLocation ($3), GetLocation ($6), GetLocation ($7)); lbag.AddMember (d, GetModifierLocations (), GetLocation ($3), GetLocation ($6), GetLocation ($7));
current_local_parameters = null; current_local_parameters = null;
@ -2299,7 +2299,7 @@ event_declaration
EVENT type member_declaration_name EVENT type member_declaration_name
{ {
current_event_field = new EventField (current_type, (FullNamedExpression) $4, (Modifiers) $2, (MemberName) $5, (Attributes) $1); current_event_field = new EventField (current_type, (FullNamedExpression) $4, (Modifiers) $2, (MemberName) $5, (Attributes) $1);
current_container.PartialContainer.AddEvent (current_event_field); current_type.AddMember (current_event_field);
if (current_event_field.MemberName.ExplicitInterface != null) { if (current_event_field.MemberName.ExplicitInterface != null) {
report.Error (71, current_event_field.Location, "`{0}': An explicit interface implementation of an event must use property syntax", report.Error (71, current_event_field.Location, "`{0}': An explicit interface implementation of an event must use property syntax",
@ -2326,7 +2326,7 @@ event_declaration
OPEN_BRACE OPEN_BRACE
{ {
current_event = new EventProperty (current_type, (FullNamedExpression) $4, (Modifiers) $2, (MemberName) $5, (Attributes) $1); current_event = new EventProperty (current_type, (FullNamedExpression) $4, (Modifiers) $2, (MemberName) $5, (Attributes) $1);
current_container.PartialContainer.AddEvent (current_event); current_type.AddMember (current_event);
lbag.AddMember (current_event, GetModifierLocations (), GetLocation ($3), GetLocation ($6)); lbag.AddMember (current_event, GetModifierLocations (), GetLocation ($3), GetLocation ($6));
lexer.EventParsing = true; lexer.EventParsing = true;
@ -2649,7 +2649,7 @@ delegate_declaration
p.CheckParameters (del); p.CheckParameters (del);
(current_container.PartialContainer ?? current_container).AddTypeContainer (del); current_container.AddTypeContainer (del);
current_delegate = del; current_delegate = del;
lexer.ConstraintsParsing = true; lexer.ConstraintsParsing = true;
@ -5062,9 +5062,11 @@ expression_statement
} }
| statement_expression COMPLETE_COMPLETION { $$ = $1; } | statement_expression COMPLETE_COMPLETION { $$ = $1; }
| statement_expression CLOSE_BRACE { | statement_expression CLOSE_BRACE {
$$ = $1; $$ = $1;
report.Error (1525, "Unexpected symbol '}', expecting ';'"); lbag.AddStatement ($$, GetLocation ($2));
} report.Error (1525, "Unexpected symbol '}' after statement, expecting ';'");
lexer.putback ('}');
}
; ;
interactive_expression_statement interactive_expression_statement
@ -5861,7 +5863,7 @@ from_clause
{ {
current_block = new Linq.QueryBlock (current_block, lexer.Location); current_block = new Linq.QueryBlock (current_block, lexer.Location);
} }
expression expression_or_error
{ {
var lt = (Tokenizer.LocatedToken) $2; var lt = (Tokenizer.LocatedToken) $2;
var sn = new Linq.RangeVariable (lt.Value, lt.Location); var sn = new Linq.RangeVariable (lt.Value, lt.Location);
@ -5876,7 +5878,7 @@ from_clause
{ {
current_block = new Linq.QueryBlock (current_block, lexer.Location); current_block = new Linq.QueryBlock (current_block, lexer.Location);
} }
expression expression_or_error
{ {
var lt = (Tokenizer.LocatedToken) $3; var lt = (Tokenizer.LocatedToken) $3;
var sn = new Linq.RangeVariable (lt.Value, lt.Location); var sn = new Linq.RangeVariable (lt.Value, lt.Location);
@ -5921,7 +5923,7 @@ select_or_group_clause
{ {
current_block = new Linq.QueryBlock (current_block, lexer.Location); current_block = new Linq.QueryBlock (current_block, lexer.Location);
} }
expression expression_or_error
{ {
$$ = new Linq.Select ((Linq.QueryBlock)current_block, (Expression)$3, GetLocation ($1)); $$ = new Linq.Select ((Linq.QueryBlock)current_block, (Expression)$3, GetLocation ($1));
@ -5936,14 +5938,14 @@ select_or_group_clause
current_block = new Linq.QueryBlock (current_block, lexer.Location); current_block = new Linq.QueryBlock (current_block, lexer.Location);
linq_clause_blocks.Push ((Linq.QueryBlock)current_block); linq_clause_blocks.Push ((Linq.QueryBlock)current_block);
} }
expression expression_or_error
{ {
current_block.SetEndLocation (lexer.Location); current_block.SetEndLocation (lexer.Location);
current_block = current_block.Parent; current_block = current_block.Parent;
current_block = new Linq.QueryBlock (current_block, lexer.Location); current_block = new Linq.QueryBlock (current_block, lexer.Location);
} }
BY expression BY expression_or_error
{ {
$$ = new Linq.GroupBy ((Linq.QueryBlock)current_block, (Expression)$3, linq_clause_blocks.Pop (), (Expression)$6, GetLocation ($1)); $$ = new Linq.GroupBy ((Linq.QueryBlock)current_block, (Expression)$3, linq_clause_blocks.Pop (), (Expression)$6, GetLocation ($1));
lbag.AddLocation ($$, GetLocation ($5)); lbag.AddLocation ($$, GetLocation ($5));
@ -5980,7 +5982,7 @@ let_clause
{ {
current_block = new Linq.QueryBlock (current_block, lexer.Location); current_block = new Linq.QueryBlock (current_block, lexer.Location);
} }
expression expression_or_error
{ {
var lt = (Tokenizer.LocatedToken) $2; var lt = (Tokenizer.LocatedToken) $2;
var sn = new Linq.RangeVariable (lt.Value, lt.Location); var sn = new Linq.RangeVariable (lt.Value, lt.Location);
@ -5999,7 +6001,7 @@ where_clause
{ {
current_block = new Linq.QueryBlock (current_block, lexer.Location); current_block = new Linq.QueryBlock (current_block, lexer.Location);
} }
expression expression_or_error
{ {
$$ = new Linq.Where ((Linq.QueryBlock)current_block, (Expression)$3, GetLocation ($1)); $$ = new Linq.Where ((Linq.QueryBlock)current_block, (Expression)$3, GetLocation ($1));
@ -6017,7 +6019,7 @@ join_clause
current_block = new Linq.QueryBlock (current_block, lexer.Location); current_block = new Linq.QueryBlock (current_block, lexer.Location);
linq_clause_blocks.Push ((Linq.QueryBlock) current_block); linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
} }
expression ON expression_or_error ON
{ {
current_block.SetEndLocation (lexer.Location); current_block.SetEndLocation (lexer.Location);
current_block = current_block.Parent; current_block = current_block.Parent;
@ -6025,7 +6027,7 @@ join_clause
current_block = new Linq.QueryBlock (current_block, lexer.Location); current_block = new Linq.QueryBlock (current_block, lexer.Location);
linq_clause_blocks.Push ((Linq.QueryBlock) current_block); linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
} }
expression EQUALS expression_or_error EQUALS
{ {
current_block.AddStatement (new ContextualReturn ((Expression) $8)); current_block.AddStatement (new ContextualReturn ((Expression) $8));
current_block.SetEndLocation (lexer.Location); current_block.SetEndLocation (lexer.Location);
@ -6033,7 +6035,7 @@ join_clause
current_block = new Linq.QueryBlock (current_block, lexer.Location); current_block = new Linq.QueryBlock (current_block, lexer.Location);
} }
expression opt_join_into expression_or_error opt_join_into
{ {
current_block.AddStatement (new ContextualReturn ((Expression) $11)); current_block.AddStatement (new ContextualReturn ((Expression) $11));
current_block.SetEndLocation (lexer.Location); current_block.SetEndLocation (lexer.Location);
@ -6079,7 +6081,7 @@ join_clause
current_block = new Linq.QueryBlock (current_block, lexer.Location); current_block = new Linq.QueryBlock (current_block, lexer.Location);
linq_clause_blocks.Push ((Linq.QueryBlock) current_block); linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
} }
expression ON expression_or_error ON
{ {
current_block.SetEndLocation (lexer.Location); current_block.SetEndLocation (lexer.Location);
current_block = current_block.Parent; current_block = current_block.Parent;
@ -6087,7 +6089,7 @@ join_clause
current_block = new Linq.QueryBlock (current_block, lexer.Location); current_block = new Linq.QueryBlock (current_block, lexer.Location);
linq_clause_blocks.Push ((Linq.QueryBlock) current_block); linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
} }
expression EQUALS expression_or_error EQUALS
{ {
current_block.AddStatement (new ContextualReturn ((Expression) $9)); current_block.AddStatement (new ContextualReturn ((Expression) $9));
current_block.SetEndLocation (lexer.Location); current_block.SetEndLocation (lexer.Location);
@ -6095,7 +6097,7 @@ join_clause
current_block = new Linq.QueryBlock (current_block, lexer.Location); current_block = new Linq.QueryBlock (current_block, lexer.Location);
} }
expression opt_join_into expression_or_error opt_join_into
{ {
current_block.AddStatement (new ContextualReturn ((Expression) $12)); current_block.AddStatement (new ContextualReturn ((Expression) $12));
current_block.SetEndLocation (lexer.Location); current_block.SetEndLocation (lexer.Location);
@ -6293,7 +6295,7 @@ interactive_parsing
pars, pars,
null /* attributes */); null /* attributes */);
current_container.PartialContainer.AddMethod (method); current_type.AddMember (method);
oob_stack.Push (method); oob_stack.Push (method);
++lexer.parsing_block; ++lexer.parsing_block;
@ -6520,12 +6522,10 @@ void push_current_container (TypeDefinition tc, object partial_token)
undo.AddTypeContainer (current_container, tc); undo.AddTypeContainer (current_container, tc);
} }
var main_container = current_container.PartialContainer ?? current_container;
if (partial_token != null) if (partial_token != null)
main_container.AddPartial (tc); current_container.AddPartial (tc);
else else
main_container.AddTypeContainer (tc); current_container.AddTypeContainer (tc);
++lexer.parsing_declaration; ++lexer.parsing_declaration;
current_container = tc; current_container = tc;
@ -6624,6 +6624,7 @@ public CSharpParser (SeekableStreamReader reader, CompilationSourceFile file, Re
this.report = report; this.report = report;
lang_version = settings.Version; lang_version = settings.Version;
yacc_verbose_flag = settings.VerboseParserFlag;
doc_support = settings.DocumentationFile != null; doc_support = settings.DocumentationFile != null;
oob_stack.Clear (); oob_stack.Clear ();
lexer = new Tokenizer (reader, file, compiler); lexer = new Tokenizer (reader, file, compiler);

46
ICSharpCode.NRefactory.CSharp/Parser/mcs/cs-tokenizer.cs

@ -73,7 +73,8 @@ namespace Mono.CSharp
{ {
int row, column; int row, column;
string value; string value;
static LocatedToken[] buffer;
static LocatedToken[] buffer = new LocatedToken[0];
static int pos; static int pos;
private LocatedToken () private LocatedToken ()
@ -129,8 +130,10 @@ namespace Mono.CSharp
public static void Initialize () public static void Initialize ()
{ {
if (buffer == null) #if !FULL_AST
if (buffer.Length == 0)
buffer = new LocatedToken [10000]; buffer = new LocatedToken [10000];
#endif
pos = 0; pos = 0;
} }
@ -263,7 +266,7 @@ namespace Mono.CSharp
// //
static readonly KeywordEntry<int>[][] keywords; static readonly KeywordEntry<int>[][] keywords;
static readonly KeywordEntry<PreprocessorDirective>[][] keywords_preprocessor; static readonly KeywordEntry<PreprocessorDirective>[][] keywords_preprocessor;
static readonly Dictionary<string, object> keyword_strings; // TODO: HashSet static readonly HashSet<string> keyword_strings;
static readonly NumberStyles styles; static readonly NumberStyles styles;
static readonly NumberFormatInfo csharp_format_info; static readonly NumberFormatInfo csharp_format_info;
@ -348,14 +351,27 @@ namespace Mono.CSharp
// //
Stack<int> ifstack; Stack<int> ifstack;
static System.Text.StringBuilder string_builder;
const int max_id_size = 512; const int max_id_size = 512;
static readonly char[] id_builder = new char [max_id_size];
public static Dictionary<char[], string>[] identifiers = new Dictionary<char[], string>[max_id_size + 1];
const int max_number_size = 512; const int max_number_size = 512;
static char[] number_builder = new char [max_number_size];
#if FULL_AST
readonly char [] id_builder = new char [max_id_size];
Dictionary<char[], string>[] identifiers = new Dictionary<char[], string>[max_id_size + 1];
char [] number_builder = new char [max_number_size];
int number_pos;
char[] value_builder = new char[256];
#else
static readonly char [] id_builder = new char [max_id_size];
static Dictionary<char[], string>[] identifiers = new Dictionary<char[], string>[max_id_size + 1];
static char [] number_builder = new char [max_number_size];
static int number_pos; static int number_pos;
static char[] value_builder = new char[256]; static char[] value_builder = new char[256];
#endif
public int Line { public int Line {
get { get {
@ -457,7 +473,7 @@ namespace Mono.CSharp
static void AddKeyword (string kw, int token) static void AddKeyword (string kw, int token)
{ {
keyword_strings.Add (kw, null); keyword_strings.Add (kw);
AddKeyword (keywords, kw, token); AddKeyword (keywords, kw, token);
} }
@ -493,7 +509,7 @@ namespace Mono.CSharp
// //
static Tokenizer () static Tokenizer ()
{ {
keyword_strings = new Dictionary<string, object> (); keyword_strings = new HashSet<string> ();
// 11 is the length of the longest keyword for now // 11 is the length of the longest keyword for now
keywords = new KeywordEntry<int>[11][]; keywords = new KeywordEntry<int>[11][];
@ -621,8 +637,6 @@ namespace Mono.CSharp
csharp_format_info = NumberFormatInfo.InvariantInfo; csharp_format_info = NumberFormatInfo.InvariantInfo;
styles = NumberStyles.Float; styles = NumberStyles.Float;
string_builder = new System.Text.StringBuilder ();
} }
int GetKeyword (char[] id, int id_len) int GetKeyword (char[] id, int id_len)
@ -900,7 +914,7 @@ namespace Mono.CSharp
public static bool IsKeyword (string s) public static bool IsKeyword (string s)
{ {
return keyword_strings.ContainsKey (s); return keyword_strings.Contains (s);
} }
// //
@ -1780,7 +1794,7 @@ namespace Mono.CSharp
return reader.Peek (); return reader.Peek ();
} }
void putback (int c) public void putback (int c)
{ {
if (putback_char != -1){ if (putback_char != -1){
Console.WriteLine ("Col: " + col); Console.WriteLine ("Col: " + col);
@ -1971,7 +1985,7 @@ namespace Mono.CSharp
char [] quotes = { '\"' }; char [] quotes = { '\"' };
string name = arg.Substring (pos). Trim (quotes); string name = arg.Substring (pos).Trim (quotes);
ref_name = context.LookupFile (file_name, name); ref_name = context.LookupFile (file_name, name);
file_name.AddIncludeFile (ref_name); file_name.AddIncludeFile (ref_name);
hidden = false; hidden = false;
@ -2078,7 +2092,7 @@ namespace Mono.CSharp
if (c != '"') if (c != '"')
return false; return false;
string_builder.Length = 0; var string_builder = new StringBuilder ();
while (c != -1 && c != '\n') { while (c != -1 && c != '\n') {
c = get_char (); c = get_char ();
if (c == '"') { if (c == '"') {
@ -2903,7 +2917,7 @@ namespace Mono.CSharp
return Token.IDENTIFIER; return Token.IDENTIFIER;
} }
static string InternIdentifier (char[] charBuffer, int length) string InternIdentifier (char[] charBuffer, int length)
{ {
// //
// Keep identifiers in an array of hashtables to avoid needless // Keep identifiers in an array of hashtables to avoid needless

22
ICSharpCode.NRefactory.CSharp/Parser/mcs/decl.cs

@ -296,7 +296,9 @@ namespace Mono.CSharp {
IsAssigned = 1 << 12, // Field is assigned IsAssigned = 1 << 12, // Field is assigned
HasExplicitLayout = 1 << 13, HasExplicitLayout = 1 << 13,
PartialDefinitionExists = 1 << 14, // Set when corresponding partial method definition exists PartialDefinitionExists = 1 << 14, // Set when corresponding partial method definition exists
HasStructLayout = 1 << 15 // Has StructLayoutAttribute HasStructLayout = 1 << 15, // Has StructLayoutAttribute
HasInstanceConstructor = 1 << 16,
HasUserOperators = 1 << 17
} }
/// <summary> /// <summary>
@ -663,14 +665,22 @@ namespace Mono.CSharp {
return true; return true;
} }
//
// Does extension methods look up to find a method which matches name and extensionType.
// Search starts from this namespace and continues hierarchically up to top level.
//
public ExtensionMethodCandidates LookupExtensionMethod (TypeSpec extensionType, string name, int arity) public ExtensionMethodCandidates LookupExtensionMethod (TypeSpec extensionType, string name, int arity)
{ {
return LookupExtensionMethod (this, extensionType, name, arity); var m = Parent;
} do {
var ns = m as NamespaceContainer;
if (ns != null)
return ns.LookupExtensionMethod (this, extensionType, name, arity, ns, 0);
protected virtual ExtensionMethodCandidates LookupExtensionMethod (IMemberContext invocationContext, TypeSpec extensionType, string name, int arity) m = m.Parent;
{ } while (m != null);
return Parent.LookupExtensionMethod (invocationContext, extensionType, name, arity);
return null;
} }
public virtual FullNamedExpression LookupNamespaceAlias (string name) public virtual FullNamedExpression LookupNamespaceAlias (string name)

14
ICSharpCode.NRefactory.CSharp/Parser/mcs/delegate.cs

@ -299,8 +299,10 @@ namespace Mono.CSharp {
} }
} }
public override void EmitContainer () public override void Emit ()
{ {
base.Emit ();
if (ReturnType.Type != null) { if (ReturnType.Type != null) {
if (ReturnType.Type.BuiltinType == BuiltinTypeSpec.Type.Dynamic) { if (ReturnType.Type.BuiltinType == BuiltinTypeSpec.Type.Dynamic) {
return_attributes = new ReturnParameter (this, InvokeBuilder.MethodBuilder, Location); return_attributes = new ReturnParameter (this, InvokeBuilder.MethodBuilder, Location);
@ -327,12 +329,6 @@ namespace Mono.CSharp {
BeginInvokeBuilder.MethodBuilder.SetImplementationFlags (MethodImplAttributes.Runtime); BeginInvokeBuilder.MethodBuilder.SetImplementationFlags (MethodImplAttributes.Runtime);
EndInvokeBuilder.MethodBuilder.SetImplementationFlags (MethodImplAttributes.Runtime); EndInvokeBuilder.MethodBuilder.SetImplementationFlags (MethodImplAttributes.Runtime);
} }
if (OptAttributes != null) {
OptAttributes.Emit ();
}
base.Emit ();
} }
protected override TypeSpec[] ResolveBaseTypes (out FullNamedExpression base_class) protected override TypeSpec[] ResolveBaseTypes (out FullNamedExpression base_class)
@ -344,9 +340,7 @@ namespace Mono.CSharp {
protected override TypeAttributes TypeAttr { protected override TypeAttributes TypeAttr {
get { get {
return ModifiersExtensions.TypeAttr (ModFlags, IsTopLevel) | return base.TypeAttr | TypeAttributes.Class | TypeAttributes.Sealed;
TypeAttributes.Class | TypeAttributes.Sealed |
base.TypeAttr;
} }
} }

50
ICSharpCode.NRefactory.CSharp/Parser/mcs/driver.cs

@ -358,5 +358,55 @@ namespace Mono.CSharp
public SpecialsBag SpecialsBag { get; set; } public SpecialsBag SpecialsBag { get; set; }
public object LastYYValue { get; set; } public object LastYYValue { get; set; }
} }
//
// This is the only public entry point
//
public class CompilerCallableEntryPoint : MarshalByRefObject
{
public static bool InvokeCompiler (string [] args, TextWriter error)
{
try {
var r = new Report (new StreamReportPrinter (error));
CommandLineParser cmd = new CommandLineParser (r, error);
var setting = cmd.ParseArguments (args);
if (setting == null || r.Errors > 0)
return false;
var d = new Driver (new CompilerContext (setting, r));
return d.Compile ();
} finally {
Reset ();
}
}
public static int[] AllWarningNumbers {
get {
return Report.AllWarnings;
}
}
public static void Reset ()
{
Reset (true);
}
public static void PartialReset ()
{
Reset (false);
}
public static void Reset (bool full_flag)
{
Location.Reset ();
if (!full_flag)
return;
SymbolWriter.Reset ();
Linq.QueryBlock.TransparentParameter.Reset ();
TypeInfo.Reset ();
}
}
} }

5
ICSharpCode.NRefactory.CSharp/Parser/mcs/dynamic.cs

@ -447,7 +447,6 @@ namespace Mono.CSharp
d.CreateContainer (); d.CreateContainer ();
d.DefineContainer (); d.DefineContainer ();
d.Define (); d.Define ();
d.Emit ();
site.AddTypeContainer (d); site.AddTypeContainer (d);
del_type = new TypeExpression (d.CurrentType, loc); del_type = new TypeExpression (d.CurrentType, loc);
@ -487,7 +486,7 @@ namespace Mono.CSharp
// When site container already exists the inflated version has to be // When site container already exists the inflated version has to be
// updated manually to contain newly created field // updated manually to contain newly created field
if (gt is InflatedTypeSpec && site_container.Fields.Count > 1) { if (gt is InflatedTypeSpec && site_container.AnonymousMethodsCounter > 1) {
var tparams = gt.MemberDefinition.TypeParametersCount > 0 ? gt.MemberDefinition.TypeParameters : TypeParameterSpec.EmptyTypes; var tparams = gt.MemberDefinition.TypeParametersCount > 0 ? gt.MemberDefinition.TypeParameters : TypeParameterSpec.EmptyTypes;
var inflator = new TypeParameterInflator (module, gt, tparams, gt.TypeArguments); var inflator = new TypeParameterInflator (module, gt, tparams, gt.TypeArguments);
gt.MemberCache.AddMember (field.InflateMember (inflator)); gt.MemberCache.AddMember (field.InflateMember (inflator));
@ -965,7 +964,7 @@ namespace Mono.CSharp
public FieldSpec CreateCallSiteField (FullNamedExpression type, Location loc) public FieldSpec CreateCallSiteField (FullNamedExpression type, Location loc)
{ {
int index = fields == null ? 0 : fields.Count; int index = AnonymousMethodsCounter++;
Field f = new HoistedField (this, type, Modifiers.PUBLIC | Modifiers.STATIC, "Site" + index.ToString ("X"), null, loc); Field f = new HoistedField (this, type, Modifiers.PUBLIC | Modifiers.STATIC, "Site" + index.ToString ("X"), null, loc);
f.Define (); f.Define ();

19
ICSharpCode.NRefactory.CSharp/Parser/mcs/enum.cs

@ -189,8 +189,7 @@ namespace Mono.CSharp {
protected override TypeAttributes TypeAttr { protected override TypeAttributes TypeAttr {
get { get {
return ModifiersExtensions.TypeAttr (ModFlags, IsTopLevel) | return base.TypeAttr | TypeAttributes.Class | TypeAttributes.Sealed;
TypeAttributes.Class | TypeAttributes.Sealed | base.TypeAttr;
} }
} }
@ -215,7 +214,7 @@ namespace Mono.CSharp {
return; return;
} }
AddConstant (em); AddMember (em);
} }
public static void Error_1008 (Location loc, Report Report) public static void Error_1008 (Location loc, Report Report)
@ -236,15 +235,13 @@ namespace Mono.CSharp {
protected override bool DoDefineMembers () protected override bool DoDefineMembers ()
{ {
if (constants != null) { for (int i = 0; i < Members.Count; ++i) {
for (int i = 0; i < constants.Count; ++i) { EnumMember em = (EnumMember) Members[i];
EnumMember em = (EnumMember) constants [i]; if (em.Initializer == null) {
if (em.Initializer == null) { em.Initializer = new ImplicitInitializer (em, i == 0 ? null : (EnumMember) Members[i - 1]);
em.Initializer = new ImplicitInitializer (em, i == 0 ? null : (EnumMember) constants[i - 1]);
}
em.Define ();
} }
em.Define ();
} }
return true; return true;

61
ICSharpCode.NRefactory.CSharp/Parser/mcs/eval.cs

@ -353,8 +353,6 @@ namespace Mono.CSharp
bool partial_input; bool partial_input;
CSharpParser parser = ParseString (ParseMode.GetCompletions, input, out partial_input); CSharpParser parser = ParseString (ParseMode.GetCompletions, input, out partial_input);
if (parser == null){ if (parser == null){
if (CSharpParser.yacc_verbose_flag != 0)
Console.WriteLine ("DEBUG: No completions available");
return null; return null;
} }
@ -372,7 +370,7 @@ namespace Mono.CSharp
// Need to setup MemberCache // Need to setup MemberCache
parser_result.CreateContainer (); parser_result.CreateContainer ();
var method = parser_result.Methods[0] as Method; var method = parser_result.Members[0] as Method;
BlockContext bc = new BlockContext (method, method.Block, ctx.BuiltinTypes.Void); BlockContext bc = new BlockContext (method, method.Block, ctx.BuiltinTypes.Void);
try { try {
@ -552,7 +550,6 @@ namespace Mono.CSharp
{ {
partial_input = false; partial_input = false;
Reset (); Reset ();
Tokenizer.LocatedToken.Initialize ();
var enc = ctx.Settings.Encoding; var enc = ctx.Settings.Encoding;
var s = new MemoryStream (enc.GetBytes (input)); var s = new MemoryStream (enc.GetBytes (input));
@ -590,7 +587,7 @@ namespace Mono.CSharp
parser.Lexer.CompleteOnEOF = true; parser.Lexer.CompleteOnEOF = true;
ReportPrinter old_printer = null; ReportPrinter old_printer = null;
if ((mode == ParseMode.Silent || mode == ParseMode.GetCompletions) && CSharpParser.yacc_verbose_flag == 0) if ((mode == ParseMode.Silent || mode == ParseMode.GetCompletions))
old_printer = ctx.Report.SetPrinter (new StreamReportPrinter (TextWriter.Null)); old_printer = ctx.Report.SetPrinter (new StreamReportPrinter (TextWriter.Null));
try { try {
@ -651,7 +648,7 @@ namespace Mono.CSharp
host.DefineContainer (); host.DefineContainer ();
host.Define (); host.Define ();
expression_method = (Method) host.Methods[0]; expression_method = (Method) host.Members[0];
} else { } else {
expression_method = null; expression_method = null;
} }
@ -695,34 +692,36 @@ namespace Mono.CSharp
var tt = assembly.Builder.GetType (host.TypeBuilder.Name); var tt = assembly.Builder.GetType (host.TypeBuilder.Name);
var mi = tt.GetMethod (expression_method.MemberName.Name); var mi = tt.GetMethod (expression_method.MemberName.Name);
if (host.Fields != null) { //
// // We need to then go from FieldBuilder to FieldInfo
// We need to then go from FieldBuilder to FieldInfo // or reflection gets confused (it basically gets confused, and variables override each
// or reflection gets confused (it basically gets confused, and variables override each // other).
// other). //
// foreach (var member in host.Members) {
foreach (Field field in host.Fields) { var field = member as Field;
var fi = tt.GetField (field.Name); if (field == null)
continue;
Tuple<FieldSpec, FieldInfo> old;
var fi = tt.GetField (field.Name);
// If a previous value was set, nullify it, so that we do
// not leak memory Tuple<FieldSpec, FieldInfo> old;
if (fields.TryGetValue (field.Name, out old)) {
if (old.Item1.MemberType.IsStruct) { // If a previous value was set, nullify it, so that we do
// // not leak memory
// TODO: Clear fields for structs if (fields.TryGetValue (field.Name, out old)) {
// if (old.Item1.MemberType.IsStruct) {
} else { //
try { // TODO: Clear fields for structs
old.Item2.SetValue (null, null); //
} catch { } else {
} try {
old.Item2.SetValue (null, null);
} catch {
} }
} }
fields[field.Name] = Tuple.Create (field.Spec, fi);
} }
fields[field.Name] = Tuple.Create (field.Spec, fi);
} }
return (CompiledMethod) System.Delegate.CreateDelegate (typeof (CompiledMethod), mi); return (CompiledMethod) System.Delegate.CreateDelegate (typeof (CompiledMethod), mi);

7
ICSharpCode.NRefactory.CSharp/Parser/mcs/expression.cs

@ -10265,8 +10265,11 @@ namespace Mono.CSharp
return base.CreateExpressionTree (ec); return base.CreateExpressionTree (ec);
var init = new ArrayInitializer (parameters.Count, loc); var init = new ArrayInitializer (parameters.Count, loc);
foreach (Property p in anonymous_type.Properties) foreach (var m in anonymous_type.Members) {
init.Add (new TypeOfMethod (MemberCache.GetMember (type, p.Get.Spec), loc)); var p = m as Property;
if (p != null)
init.Add (new TypeOfMethod (MemberCache.GetMember (type, p.Get.Spec), loc));
}
var ctor_args = new ArrayInitializer (arguments.Count, loc); var ctor_args = new ArrayInitializer (arguments.Count, loc);
foreach (Argument a in arguments) foreach (Argument a in arguments)

11
ICSharpCode.NRefactory.CSharp/Parser/mcs/field.cs

@ -118,8 +118,7 @@ namespace Mono.CSharp
declarators.Add (declarator); declarators.Add (declarator);
// TODO: This will probably break Parent.AddNameToContainer (this, declarator.Name.Value);
Parent.AddMember (this, declarator.Name.Value);
} }
public override void ApplyAttributeBuilder (Attribute a, MethodSpec ctor, byte[] cdata, PredefinedAttributes pa) public override void ApplyAttributeBuilder (Attribute a, MethodSpec ctor, byte[] cdata, PredefinedAttributes pa)
@ -407,12 +406,12 @@ namespace Mono.CSharp
GetSignatureForError ()); GetSignatureForError ());
} else if (declarators != null) { } else if (declarators != null) {
var t = new TypeExpression (MemberType, TypeExpression.Location); var t = new TypeExpression (MemberType, TypeExpression.Location);
int index = Parent.PartialContainer.Fields.IndexOf (this);
foreach (var d in declarators) { foreach (var d in declarators) {
var f = new FixedField (Parent, t, ModFlags, new MemberName (d.Name.Value, d.Name.Location), OptAttributes); var f = new FixedField (Parent, t, ModFlags, new MemberName (d.Name.Value, d.Name.Location), OptAttributes);
f.initializer = d.Initializer; f.initializer = d.Initializer;
((ConstInitializer) f.initializer).Name = d.Name.Value; ((ConstInitializer) f.initializer).Name = d.Name.Value;
Parent.PartialContainer.Fields.Insert (++index, f); f.Define ();
Parent.PartialContainer.Members.Add (f);
} }
} }
@ -645,13 +644,13 @@ namespace Mono.CSharp
if (declarators != null) { if (declarators != null) {
var t = new TypeExpression (MemberType, TypeExpression.Location); var t = new TypeExpression (MemberType, TypeExpression.Location);
int index = Parent.PartialContainer.Fields.IndexOf (this);
foreach (var d in declarators) { foreach (var d in declarators) {
var f = new Field (Parent, t, ModFlags, new MemberName (d.Name.Value, d.Name.Location), OptAttributes); var f = new Field (Parent, t, ModFlags, new MemberName (d.Name.Value, d.Name.Location), OptAttributes);
if (d.Initializer != null) if (d.Initializer != null)
f.initializer = d.Initializer; f.initializer = d.Initializer;
Parent.PartialContainer.Fields.Insert (++index, f); f.Define ();
Parent.PartialContainer.Members.Add (f);
} }
} }

23
ICSharpCode.NRefactory.CSharp/Parser/mcs/flowanalysis.cs

@ -1213,7 +1213,6 @@ namespace Mono.CSharp
class StructInfo class StructInfo
{ {
public readonly TypeSpec Type;
readonly List<FieldSpec> fields; readonly List<FieldSpec> fields;
public readonly TypeInfo[] StructFields; public readonly TypeInfo[] StructFields;
public readonly int Length; public readonly int Length;
@ -1223,14 +1222,13 @@ namespace Mono.CSharp
private Dictionary<string, TypeInfo> struct_field_hash; private Dictionary<string, TypeInfo> struct_field_hash;
private Dictionary<string, int> field_hash; private Dictionary<string, int> field_hash;
protected bool InTransit; bool InTransit;
// Private constructor. To save memory usage, we only need to create one instance //
// of this class per struct type. // We only need one instance per type
private StructInfo (TypeSpec type) //
StructInfo (TypeSpec type)
{ {
this.Type = type;
field_type_hash.Add (type, this); field_type_hash.Add (type, this);
fields = MemberCache.GetAllFieldsForDefiniteAssignment (type); fields = MemberCache.GetAllFieldsForDefiniteAssignment (type);
@ -1327,7 +1325,7 @@ namespace Mono.CSharp
// </summary> // </summary>
public class VariableInfo { public class VariableInfo {
readonly string Name; readonly string Name;
public readonly TypeInfo TypeInfo; readonly TypeInfo TypeInfo;
// <summary> // <summary>
// The bit offset of this variable in the flow vector. // The bit offset of this variable in the flow vector.
@ -1348,7 +1346,7 @@ namespace Mono.CSharp
VariableInfo[] sub_info; VariableInfo[] sub_info;
protected VariableInfo (string name, TypeSpec type, int offset) VariableInfo (string name, TypeSpec type, int offset)
{ {
this.Name = name; this.Name = name;
this.Offset = offset; this.Offset = offset;
@ -1359,7 +1357,7 @@ namespace Mono.CSharp
Initialize (); Initialize ();
} }
protected VariableInfo (VariableInfo parent, TypeInfo type) VariableInfo (VariableInfo parent, TypeInfo type)
{ {
this.Name = parent.Name; this.Name = parent.Name;
this.TypeInfo = type; this.TypeInfo = type;
@ -1451,6 +1449,11 @@ namespace Mono.CSharp
return !ec.DoFlowAnalysis || ec.CurrentBranching.IsStructFieldAssigned (this, name); return !ec.DoFlowAnalysis || ec.CurrentBranching.IsStructFieldAssigned (this, name);
} }
public bool IsFullyInitialized (BlockContext bc, Location loc)
{
return TypeInfo.IsFullyInitialized (bc, this, loc);
}
public bool IsStructFieldAssigned (MyBitVector vector, string field_name) public bool IsStructFieldAssigned (MyBitVector vector, string field_name)
{ {
int field_idx = TypeInfo.GetFieldIndex (field_name); int field_idx = TypeInfo.GetFieldIndex (field_name);

14
ICSharpCode.NRefactory.CSharp/Parser/mcs/iterators.cs

@ -187,7 +187,7 @@ namespace Mono.CSharp
throw new InternalErrorException (); throw new InternalErrorException ();
this.method = method; this.method = method;
AddMethod (method); Members.Add (method);
} }
protected override bool DoDefineMembers () protected override bool DoDefineMembers ()
@ -329,7 +329,7 @@ namespace Mono.CSharp
: base (host, null, new TypeExpression (host.Compiler.BuiltinTypes.Void, host.Location), Modifiers.PUBLIC | Modifiers.DEBUGGER_HIDDEN, : base (host, null, new TypeExpression (host.Compiler.BuiltinTypes.Void, host.Location), Modifiers.PUBLIC | Modifiers.DEBUGGER_HIDDEN,
new MemberName ("Dispose", host.Location)) new MemberName ("Dispose", host.Location))
{ {
host.AddMethod (this); host.Members.Add (this);
Block.AddStatement (new DisposeMethodStatement (host.Iterator)); Block.AddStatement (new DisposeMethodStatement (host.Iterator));
} }
@ -494,10 +494,10 @@ namespace Mono.CSharp
get_enumerator.Block.AddStatement ( get_enumerator.Block.AddStatement (
new Return (new Invocation (new DynamicMethodGroupExpr (gget_enumerator, Location), null), Location)); new Return (new Invocation (new DynamicMethodGroupExpr (gget_enumerator, Location), null), Location));
AddMethod (get_enumerator); Members.Add (get_enumerator);
AddMethod (gget_enumerator); Members.Add (gget_enumerator);
} else { } else {
AddMethod (new GetEnumeratorMethod (this, enumerator_type, name)); Members.Add (new GetEnumeratorMethod (this, enumerator_type, name));
} }
} }
@ -526,7 +526,7 @@ namespace Mono.CSharp
current.Get = new Property.GetMethod (current, 0, null, Location); current.Get = new Property.GetMethod (current, 0, null, Location);
current.Get.Block = get_block; current.Get.Block = get_block;
AddProperty (current); Members.Add (current);
} }
void Define_Reset () void Define_Reset ()
@ -536,7 +536,7 @@ namespace Mono.CSharp
Modifiers.PUBLIC | Modifiers.DEBUGGER_HIDDEN, Modifiers.PUBLIC | Modifiers.DEBUGGER_HIDDEN,
new MemberName ("Reset", Location), new MemberName ("Reset", Location),
ParametersCompiled.EmptyReadOnlyParameters, null); ParametersCompiled.EmptyReadOnlyParameters, null);
AddMethod (reset); Members.Add (reset);
reset.Block = new ToplevelBlock (Compiler, Location); reset.Block = new ToplevelBlock (Compiler, Location);

2
ICSharpCode.NRefactory.CSharp/Parser/mcs/linq.cs

@ -850,7 +850,7 @@ namespace Mono.CSharp.Linq
public void AddRangeVariable (RangeVariable variable) public void AddRangeVariable (RangeVariable variable)
{ {
variable.Block = this; variable.Block = this;
AddLocalName (variable.Name, variable); TopBlock.AddLocalName (variable.Name, variable, true);
} }
public override void Error_AlreadyDeclared (string name, INamedBlockVariable variable, string reason) public override void Error_AlreadyDeclared (string name, INamedBlockVariable variable, string reason)

7
ICSharpCode.NRefactory.CSharp/Parser/mcs/location.cs

@ -220,7 +220,7 @@ namespace Mono.CSharp {
static Checkpoint [] checkpoints; static Checkpoint [] checkpoints;
static int checkpoint_index; static int checkpoint_index;
public readonly static Location Null = new Location (-1); public readonly static Location Null = new Location ();
public static bool InEmacs; public static bool InEmacs;
static Location () static Location ()
@ -269,11 +269,6 @@ namespace Mono.CSharp {
// File is always pushed before being changed. // File is always pushed before being changed.
} }
public Location (int row)
: this (row, 0)
{
}
public Location (int row, int column) public Location (int row, int column)
{ {
if (row <= 0) if (row <= 0)

2
ICSharpCode.NRefactory.CSharp/Parser/mcs/membercache.cs

@ -894,7 +894,7 @@ namespace Mono.CSharp {
return IndexerNameAlias; return IndexerNameAlias;
if (mc is Constructor) if (mc is Constructor)
return Constructor.ConstructorName; return mc.IsStatic ? Constructor.TypeConstructorName : Constructor.ConstructorName;
return mc.MemberName.Name; return mc.MemberName.Name;
} }

19
ICSharpCode.NRefactory.CSharp/Parser/mcs/method.cs

@ -1361,10 +1361,6 @@ namespace Mono.CSharp {
public override bool EnableOverloadChecks (MemberCore overload) public override bool EnableOverloadChecks (MemberCore overload)
{ {
// TODO: It can be deleted when members will be defined in correct order
if (overload is Operator)
return overload.EnableOverloadChecks (this);
if (overload is Indexer) if (overload is Indexer)
return false; return false;
@ -1619,6 +1615,9 @@ namespace Mono.CSharp {
return false; return false;
} }
if ((caching_flags & Flags.MethodOverloadsExist) != 0)
Parent.MemberCache.CheckExistingMembersOverloads (this, parameters);
// the rest can be ignored // the rest can be ignored
return true; return true;
} }
@ -1649,14 +1648,6 @@ namespace Mono.CSharp {
if (ConstructorBuilder != null) if (ConstructorBuilder != null)
return true; return true;
var ca = MethodAttributes.RTSpecialName | MethodAttributes.SpecialName;
if ((ModFlags & Modifiers.STATIC) != 0) {
ca |= MethodAttributes.Static | MethodAttributes.Private;
} else {
ca |= ModifiersExtensions.MethodAttr (ModFlags);
}
if (!CheckAbstractAndExtern (block != null)) if (!CheckAbstractAndExtern (block != null))
return false; return false;
@ -1664,6 +1655,8 @@ namespace Mono.CSharp {
if (!CheckBase ()) if (!CheckBase ())
return false; return false;
var ca = ModifiersExtensions.MethodAttr (ModFlags) | MethodAttributes.RTSpecialName | MethodAttributes.SpecialName;
ConstructorBuilder = Parent.TypeBuilder.DefineConstructor ( ConstructorBuilder = Parent.TypeBuilder.DefineConstructor (
ca, CallingConventions, ca, CallingConventions,
parameters.GetMetaInfo ()); parameters.GetMetaInfo ());
@ -1906,12 +1899,10 @@ namespace Mono.CSharp {
public MethodData (InterfaceMemberBase member, public MethodData (InterfaceMemberBase member,
Modifiers modifiers, MethodAttributes flags, Modifiers modifiers, MethodAttributes flags,
IMethodData method, MethodBuilder builder, IMethodData method, MethodBuilder builder,
//GenericMethod generic,
MethodSpec parent_method) MethodSpec parent_method)
: this (member, modifiers, flags, method) : this (member, modifiers, flags, method)
{ {
this.builder = builder; this.builder = builder;
//this.GenericMethod = generic;
this.parent_method = parent_method; this.parent_method = parent_method;
} }

10
ICSharpCode.NRefactory.CSharp/Parser/mcs/module.cs

@ -39,7 +39,7 @@ namespace Mono.CSharp
sealed class StaticDataContainer : CompilerGeneratedClass sealed class StaticDataContainer : CompilerGeneratedClass
{ {
readonly Dictionary<int, Struct> size_types; readonly Dictionary<int, Struct> size_types;
new int fields; int fields;
public StaticDataContainer (ModuleContainer module) public StaticDataContainer (ModuleContainer module)
: base (module, new MemberName ("<PrivateImplementationDetails>" + module.builder.ModuleVersionId.ToString ("B"), Location.Null), Modifiers.STATIC) : base (module, new MemberName ("<PrivateImplementationDetails>" + module.builder.ModuleVersionId.ToString ("B"), Location.Null), Modifiers.STATIC)
@ -180,6 +180,11 @@ namespace Mono.CSharp
} }
} }
public int CounterAnonymousTypes { get; set; }
public int CounterAnonymousMethods { get; set; }
public int CounterAnonymousContainers { get; set; }
public int CounterSwitchTypes { get; set; }
public AssemblyDefinition DeclaringAssembly { public AssemblyDefinition DeclaringAssembly {
get { get {
return assembly; return assembly;
@ -423,7 +428,8 @@ namespace Mono.CSharp
base.EmitContainer (); base.EmitContainer ();
VerifyMembers (); if (Compiler.Report.Errors == 0)
VerifyMembers ();
if (anonymous_types != null) { if (anonymous_types != null) {
foreach (var atypes in anonymous_types) foreach (var atypes in anonymous_types)

70
ICSharpCode.NRefactory.CSharp/Parser/mcs/namespace.cs

@ -83,6 +83,7 @@ namespace Mono.CSharp {
string fullname; string fullname;
protected Dictionary<string, Namespace> namespaces; protected Dictionary<string, Namespace> namespaces;
protected Dictionary<string, IList<TypeSpec>> types; protected Dictionary<string, IList<TypeSpec>> types;
List<TypeSpec> extension_method_types;
Dictionary<string, TypeExpr> cached_types; Dictionary<string, TypeExpr> cached_types;
RootNamespace root; RootNamespace root;
bool cls_checked; bool cls_checked;
@ -403,27 +404,35 @@ namespace Mono.CSharp {
// //
public List<MethodSpec> LookupExtensionMethod (IMemberContext invocationContext, TypeSpec extensionType, string name, int arity) public List<MethodSpec> LookupExtensionMethod (IMemberContext invocationContext, TypeSpec extensionType, string name, int arity)
{ {
if (types == null) if (extension_method_types == null)
return null; return null;
List<MethodSpec> found = null; List<MethodSpec> found = null;
for (int i = 0; i < extension_method_types.Count; ++i) {
var ts = extension_method_types[i];
// TODO: Add per namespace flag when at least 1 type has extension //
// When the list was built we didn't know what members the type
// contains
//
if ((ts.Modifiers & Modifiers.METHOD_EXTENSION) == 0) {
if (extension_method_types.Count == 1) {
extension_method_types = null;
return found;
}
foreach (var tgroup in types.Values) { extension_method_types.RemoveAt (i--);
foreach (var ts in tgroup) { continue;
if ((ts.Modifiers & Modifiers.METHOD_EXTENSION) == 0) }
continue;
var res = ts.MemberCache.FindExtensionMethods (invocationContext, extensionType, name, arity); var res = ts.MemberCache.FindExtensionMethods (invocationContext, extensionType, name, arity);
if (res == null) if (res == null)
continue; continue;
if (found == null) { if (found == null) {
found = res; found = res;
} else { } else {
found.AddRange (res); found.AddRange (res);
}
} }
} }
@ -436,6 +445,14 @@ namespace Mono.CSharp {
types = new Dictionary<string, IList<TypeSpec>> (64); types = new Dictionary<string, IList<TypeSpec>> (64);
} }
if (ts.IsStatic && ts.Arity == 0 &&
(ts.MemberDefinition.DeclaringAssembly == null || ts.MemberDefinition.DeclaringAssembly.HasExtensionMethod)) {
if (extension_method_types == null)
extension_method_types = new List<TypeSpec> ();
extension_method_types.Add (ts);
}
var name = ts.Name; var name = ts.Name;
IList<TypeSpec> existing; IList<TypeSpec> existing;
if (types.TryGetValue (name, out existing)) { if (types.TryGetValue (name, out existing)) {
@ -604,10 +621,12 @@ namespace Mono.CSharp {
Namespace[] namespace_using_table; Namespace[] namespace_using_table;
Dictionary<string, UsingAliasNamespace> aliases; Dictionary<string, UsingAliasNamespace> aliases;
public readonly MemberName RealMemberName;
public NamespaceContainer (MemberName name, ModuleContainer module, NamespaceContainer parent, CompilationSourceFile sourceFile) public NamespaceContainer (MemberName name, ModuleContainer module, NamespaceContainer parent, CompilationSourceFile sourceFile)
: base ((TypeContainer) parent ?? module, name, null, MemberKind.Namespace) : base ((TypeContainer) parent ?? module, name, null, MemberKind.Namespace)
{ {
this.RealMemberName = name;
this.module = module; this.module = module;
this.Parent = parent; this.Parent = parent;
this.file = sourceFile; this.file = sourceFile;
@ -761,15 +780,6 @@ namespace Mono.CSharp {
base.EmitContainer (); base.EmitContainer ();
} }
//
// Does extension methods look up to find a method which matches name and extensionType.
// Search starts from this namespace and continues hierarchically up to top level.
//
protected override ExtensionMethodCandidates LookupExtensionMethod (IMemberContext invocationContext, TypeSpec extensionType, string name, int arity)
{
return LookupExtensionMethod (invocationContext, extensionType, name, arity, this, 0);
}
public ExtensionMethodCandidates LookupExtensionMethod (IMemberContext invocationContext, TypeSpec extensionType, string name, int arity, NamespaceContainer container, int position) public ExtensionMethodCandidates LookupExtensionMethod (IMemberContext invocationContext, TypeSpec extensionType, string name, int arity, NamespaceContainer container, int position)
{ {
// //
@ -1180,10 +1190,10 @@ namespace Mono.CSharp {
return MemberName == null ? "global::" : base.GetSignatureForError (); return MemberName == null ? "global::" : base.GetSignatureForError ();
} }
public override void RemoveContainer (TypeContainer next_part) public override void RemoveContainer (TypeContainer cont)
{ {
base.RemoveContainer (next_part); base.RemoveContainer (cont);
NS.RemoveContainer (next_part); NS.RemoveContainer (cont);
} }
protected override bool VerifyClsCompliance () protected override bool VerifyClsCompliance ()
@ -1265,7 +1275,7 @@ namespace Mono.CSharp {
} }
} }
public void Accept (StructuralVisitor visitor) public virtual void Accept (StructuralVisitor visitor)
{ {
visitor.Visit (this); visitor.Visit (this);
} }
@ -1288,7 +1298,7 @@ namespace Mono.CSharp {
} }
} }
public void Accept (StructuralVisitor visitor) public override void Accept (StructuralVisitor visitor)
{ {
visitor.Visit (this); visitor.Visit (this);
} }
@ -1422,7 +1432,7 @@ namespace Mono.CSharp {
resolved = NamespaceExpression.ResolveAsTypeOrNamespace (new AliasContext (ctx)); resolved = NamespaceExpression.ResolveAsTypeOrNamespace (new AliasContext (ctx));
} }
public void Accept (StructuralVisitor visitor) public override void Accept (StructuralVisitor visitor)
{ {
visitor.Visit (this); visitor.Visit (this);
} }

24
ICSharpCode.NRefactory.CSharp/Parser/mcs/property.cs

@ -445,7 +445,7 @@ namespace Mono.CSharp
if (first == null) if (first == null)
first = value; first = value;
Parent.AddMember (get); Parent.AddNameToContainer (get, get.MemberName.Basename);
} }
} }
@ -458,7 +458,7 @@ namespace Mono.CSharp
if (first == null) if (first == null)
first = value; first = value;
Parent.AddMember (set); Parent.AddNameToContainer (set, set.MemberName.Basename);
} }
} }
@ -743,7 +743,7 @@ namespace Mono.CSharp
if (!field.Define ()) if (!field.Define ())
return; return;
Parent.PartialContainer.AddField (field); Parent.PartialContainer.Members.Add (field);
FieldExpr fe = new FieldExpr (field, Location); FieldExpr fe = new FieldExpr (field, Location);
if ((field.ModFlags & Modifiers.STATIC) == 0) if ((field.ModFlags & Modifiers.STATIC) == 0)
@ -787,7 +787,7 @@ namespace Mono.CSharp
else else
pm = new GetMethod (this, 0, null, Location); pm = new GetMethod (this, 0, null, Location);
Parent.AddMember (pm); Parent.AddNameToContainer (pm, pm.MemberName.Basename);
} }
if (!CheckBase ()) if (!CheckBase ())
@ -1040,8 +1040,7 @@ namespace Mono.CSharp
declarators.Add (declarator); declarators.Add (declarator);
// TODO: This will probably break Parent.AddNameToContainer (this, declarator.Name.Value);
Parent.AddMember (this, declarator.Name.Value);
} }
public override void ApplyAttributeBuilder (Attribute a, MethodSpec ctor, byte[] cdata, PredefinedAttributes pa) public override void ApplyAttributeBuilder (Attribute a, MethodSpec ctor, byte[] cdata, PredefinedAttributes pa)
@ -1074,14 +1073,14 @@ namespace Mono.CSharp
mod_flags_src &= ~(Modifiers.AccessibilityMask | Modifiers.DEFAULT_ACCESS_MODIFER); mod_flags_src &= ~(Modifiers.AccessibilityMask | Modifiers.DEFAULT_ACCESS_MODIFER);
var t = new TypeExpression (MemberType, TypeExpression.Location); var t = new TypeExpression (MemberType, TypeExpression.Location);
int index = Parent.PartialContainer.Events.IndexOf (this);
foreach (var d in declarators) { foreach (var d in declarators) {
var ef = new EventField (Parent, t, mod_flags_src, new MemberName (d.Name.Value, d.Name.Location), OptAttributes); var ef = new EventField (Parent, t, mod_flags_src, new MemberName (d.Name.Value, d.Name.Location), OptAttributes);
if (d.Initializer != null) if (d.Initializer != null)
ef.initializer = d.Initializer; ef.initializer = d.Initializer;
Parent.PartialContainer.Events.Insert (++index, ef); ef.Define ();
Parent.PartialContainer.Members.Add (ef);
} }
} }
@ -1098,7 +1097,7 @@ namespace Mono.CSharp
Modifiers.BACKING_FIELD | Modifiers.COMPILER_GENERATED | Modifiers.PRIVATE | (ModFlags & (Modifiers.STATIC | Modifiers.UNSAFE)), Modifiers.BACKING_FIELD | Modifiers.COMPILER_GENERATED | Modifiers.PRIVATE | (ModFlags & (Modifiers.STATIC | Modifiers.UNSAFE)),
MemberName, null); MemberName, null);
Parent.PartialContainer.AddField (backing_field); Parent.PartialContainer.Members.Add (backing_field);
backing_field.Initializer = Initializer; backing_field.Initializer = Initializer;
backing_field.ModFlags &= ~Modifiers.COMPILER_GENERATED; backing_field.ModFlags &= ~Modifiers.COMPILER_GENERATED;
@ -1238,7 +1237,7 @@ namespace Mono.CSharp
} }
set { set {
add = value; add = value;
Parent.AddMember (value); Parent.AddNameToContainer (value, value.MemberName.Basename);
} }
} }
@ -1254,7 +1253,7 @@ namespace Mono.CSharp
} }
set { set {
remove = value; remove = value;
Parent.AddMember (value); Parent.AddNameToContainer (value, value.MemberName.Basename);
} }
} }
#endregion #endregion
@ -1572,8 +1571,7 @@ namespace Mono.CSharp
} }
} }
if (!Parent.PartialContainer.AddMember (this)) Parent.AddNameToContainer (this, MemberName.Basename);
return false;
flags |= MethodAttributes.HideBySig | MethodAttributes.SpecialName; flags |= MethodAttributes.HideBySig | MethodAttributes.SpecialName;

3
ICSharpCode.NRefactory.CSharp/Parser/mcs/settings.cs

@ -133,6 +133,7 @@ namespace Mono.CSharp {
// Compiler debug flags only // Compiler debug flags only
public bool ParseOnly, TokenizeOnly, Timestamps; public bool ParseOnly, TokenizeOnly, Timestamps;
public int DebugFlags; public int DebugFlags;
public int VerboseParserFlag;
// //
// Whether we are being linked against the standard libraries. // Whether we are being linked against the standard libraries.
@ -1095,7 +1096,7 @@ namespace Mono.CSharp {
{ {
switch (arg){ switch (arg){
case "-v": case "-v":
CSharpParser.yacc_verbose_flag++; settings.VerboseParserFlag++;
return ParseResult.Success; return ParseResult.Success;
case "--version": case "--version":

32
ICSharpCode.NRefactory.CSharp/Parser/mcs/statement.cs

@ -1912,7 +1912,7 @@ namespace Mono.CSharp {
if (!ec.DoFlowAnalysis || ec.CurrentBranching.IsAssigned (VariableInfo)) if (!ec.DoFlowAnalysis || ec.CurrentBranching.IsAssigned (VariableInfo))
return true; return true;
return VariableInfo.TypeInfo.IsFullyInitialized (ec, VariableInfo, block.StartLocation); return VariableInfo.IsFullyInitialized (ec, block.StartLocation);
} }
public bool IsAssigned (BlockContext ec) public bool IsAssigned (BlockContext ec)
@ -2099,9 +2099,9 @@ namespace Mono.CSharp {
AddLocalName (li.Name, li); AddLocalName (li.Name, li);
} }
public virtual void AddLocalName (string name, INamedBlockVariable li) public void AddLocalName (string name, INamedBlockVariable li)
{ {
ParametersBlock.TopBlock.AddLocalName (name, li); ParametersBlock.TopBlock.AddLocalName (name, li, false);
} }
public virtual void Error_AlreadyDeclared (string name, INamedBlockVariable variable, string reason) public virtual void Error_AlreadyDeclared (string name, INamedBlockVariable variable, string reason)
@ -3003,7 +3003,7 @@ namespace Mono.CSharp {
} }
} }
public override void AddLocalName (string name, INamedBlockVariable li) public void AddLocalName (string name, INamedBlockVariable li, bool ignoreChildrenBlocks)
{ {
if (names == null) if (names == null)
names = new Dictionary<string, object> (); names = new Dictionary<string, object> ();
@ -3047,13 +3047,15 @@ namespace Mono.CSharp {
} }
} }
// Collision with with children if (!ignoreChildrenBlocks) {
b = existing.Block; // Collision with children
while ((b = b.Parent) != null) { b = existing.Block;
if (li.Block == b) { while ((b = b.Parent) != null) {
li.Block.Error_AlreadyDeclared (name, li, "child"); if (li.Block == b) {
i = existing_list.Count; li.Block.Error_AlreadyDeclared (name, li, "child");
break; i = existing_list.Count;
break;
}
} }
} }
} }
@ -3551,7 +3553,6 @@ namespace Mono.CSharp {
VariableReference value; VariableReference value;
ExpressionStatement string_dictionary; ExpressionStatement string_dictionary;
FieldExpr switch_cache_field; FieldExpr switch_cache_field;
static int unique_counter;
ExplicitBlock block; ExplicitBlock block;
// //
@ -3912,11 +3913,6 @@ namespace Mono.CSharp {
return null; return null;
} }
public static void Reset ()
{
unique_counter = 0;
}
public override bool Resolve (BlockContext ec) public override bool Resolve (BlockContext ec)
{ {
Expr = Expr.Resolve (ec); Expr = Expr.Resolve (ec);
@ -4089,7 +4085,7 @@ namespace Mono.CSharp {
var ctype = ec.CurrentMemberDefinition.Parent.PartialContainer; var ctype = ec.CurrentMemberDefinition.Parent.PartialContainer;
Field field = new Field (ctype, string_dictionary_type, Field field = new Field (ctype, string_dictionary_type,
Modifiers.STATIC | Modifiers.PRIVATE | Modifiers.COMPILER_GENERATED, Modifiers.STATIC | Modifiers.PRIVATE | Modifiers.COMPILER_GENERATED,
new MemberName (CompilerGeneratedClass.MakeName (null, "f", "switch$map", unique_counter++), loc), null); new MemberName (CompilerGeneratedClass.MakeName (null, "f", "switch$map", ec.Module.CounterSwitchTypes++), loc), null);
if (!field.Define ()) if (!field.Define ())
return; return;
ctype.AddField (field); ctype.AddField (field);

18
ICSharpCode.NRefactory.CSharp/Parser/mcs/visit.cs

@ -29,19 +29,15 @@ namespace Mono.CSharp
} }
void VisitTypeContainer (TypeContainer tc) void VisitTypeDefinition (TypeDefinition tc)
{ {
if (tc.Containers == null) foreach (var container in tc.Members) {
return; container.Accept (this);
foreach (var container in tc.Containers) {
if (container != null)
container.Accept (this);
} }
} }
public virtual void Visit (NamespaceContainer ns) public virtual void Visit (NamespaceContainer ns)
{ {
VisitTypeContainer (ns);
} }
public virtual void Visit (UsingNamespace un) public virtual void Visit (UsingNamespace un)
@ -58,18 +54,18 @@ namespace Mono.CSharp
public virtual void Visit (Class c) public virtual void Visit (Class c)
{ {
VisitTypeContainer (c); VisitTypeDefinition (c);
} }
public virtual void Visit (Struct s) public virtual void Visit (Struct s)
{ {
VisitTypeContainer (s); VisitTypeDefinition (s);
} }
public virtual void Visit (Interface i) public virtual void Visit (Interface i)
{ {
VisitTypeContainer (i); VisitTypeDefinition (i);
} }
public virtual void Visit (Delegate d) public virtual void Visit (Delegate d)
@ -78,7 +74,7 @@ namespace Mono.CSharp
public virtual void Visit (Enum e) public virtual void Visit (Enum e)
{ {
VisitTypeContainer (e); VisitTypeDefinition (e);
} }
public virtual void Visit (FixedField f) public virtual void Visit (FixedField f)

Loading…
Cancel
Save