using System.Reflection;
using System.Runtime.CompilerServices;
-[assembly: AssemblyVersion("1.1.2")]
-[assembly: AssemblyTitle ("Mono C# Compiler")]
-[assembly: AssemblyDescription ("Mono C# Compiler with Generics")]
+[assembly: AssemblyVersion("1.1.3")]
+[assembly: AssemblyTitle ("Mono VB.NET Compiler")]
+[assembly: AssemblyDescription ("Mono VB.NET Compiler with Generics")]
[assembly: AssemblyCopyright ("2001, 2002, 2003 Ximian, Inc.")]
[assembly: AssemblyCompany ("Ximian, Inc.")]
+2005-02-02 Martin Baulig <martin@ximian.com>
+
+ * delegate.cs (Delegate.DefineType): Report an internal error if
+ TypeManager.multicast_delegate_type is null. See bug #72015 for
+ details.
+
+2005-01-29 Miguel de Icaza <miguel@novell.com>
+
+ * pending.cs: Produce better code (no nops produced by using Ldarg
+ + value).
+
+ * pending.cs (PendingImplementation.DefineProxy): It was not `arg
+ i - 1' it should be arg + 1.
+
+ Fixes bug #71819.
+
+2005-01-26 Martin Baulig <martin@ximian.com>
+
+ * cs-parser.jay (indexer_declarator): Don't report an error if we
+ have type parameters since we can be an explicit interface
+ implementation; fixes #71449.
+
+2005-01-26 Martin Baulig <martin@ximian.com>
+
+ * class.cs (TypeContainer.AttributeTargets): Return the correct
+ AttributeTargets depending on our `Kind' instead of throwing an
+ exception; fixes #71632.
+
+2005-01-26 Martin Baulig <martin@ximian.com>
+
+ * delegate.cs (Delegate.DefineType): Correctly define our type
+ parameters. Fixes #71483.
+
+2005-01-25 Raja R Harinath <rharinath@novell.com>
+
+ Fix #71602.
+ * expression.cs (MemberAccess.DoResolve): Don't complain with
+ cs0572 when the LHS of a member access has identical name and type
+ name.
+
+2005-01-25 Marek Safar <marek.safar@seznam.cz>
+
+ Fix #71651, #71675
+ * attribute.cs (ExtractSecurityPermissionSet): Catch exceptions from
+ CreatePermission.
+ Create custom PermissionSet only for PermissionSetAttribute.
+
+2005-01-24 Marek Safar <marek.safar@seznam.cz>
+
+ Fix #71649
+ * class.cs (StaticClass.DefineContainerMembers): Enable enums and
+ delegates in static class.
+
+2005-01-24 Martin Baulig <martin@ximian.com>
+
+ * flowanalysis.cs (FlowBranching.UsageVector.MergeChild): If we're
+ merging an implicit block, just use its reachability.
+
+ * statement.cs (Block.Resolve): Make the unreachable code check
+ work wrt. implicit blocks; see test-337 from #63842.
+
+2005-01-21 Alp Toker <alp@atoker.com>
+
+ * cs-parser.jay: destructor_declaration's container is PartialContainer
+ not Class when partial types are used, so use Kind prop instead of
+ 'is'.
+
+2005-01-22 Miguel de Icaza <miguel@ximian.com>
+
+ * cs-parser.jay: Improve error reporting when an interface
+ declares new types.
+
+2005-01-20 Dick Porter <dick@ximian.com>
+
+ * support.cs: SeekableStreamReader fix from Sandor Dobos
+ (dobos_s@ibcnet.hu) to cope with Position setting when multibyte
+ chars are read. Fixes bug 70369.
+
+2005-01-20 Raja R Harinath <rharinath@novell.com>
+
+ * cs-parser.jay (catch_clause): Simplify current_block handling
+ somewhat.
+
+2005-01-17 Miguel de Icaza <miguel@ximian.com>
+
+ * convert.cs (ImplicitStandardConversionExists): Synchronize the
+ code with ImplicitStandardConversion to handle the implicit
+ conversion of method groups into valid delegate invocations.
+
+ The problem is that in parameter handling we were using this code
+ path. Fixes bug #64698
+
+2005-01-19 Raja R Harinath <rharinath@novell.com>
+
+ * cs-parser.jay: Fix several infelicities.
+ - Avoid assigning to the parser value stack. Code like
+ '$3 = null' is unclean. Synthesize a value for the code block
+ instead.
+ - Avoid using oob_stack for storing location information. Use ...
+ (_mark_): ... this. New (empty) rule. Saves the current location
+ in $$.
+ (foreach_statement): Avoid using oob_stack for current_block
+ handling. Use technique used in for_statement and
+ using_statement. Synthesize a value for the code block to store
+ additional intermediate information.
+
+2005-01-13 Miguel de Icaza <miguel@ximian.com>
+
+ * ecore.cs (IsAccessorAccessible): Accessibility to private fields
+ of a different type is only allowed to private fields of a
+ containing type, not on fields of a base class.
+
+ See test-174.cs and error cs0122-9.cs
+
+2005-01-13 Raja R Harinath <rharinath@novell.com>
+
+ Fix test-335.cs (bug #58126).
+ * cs-parser.jay (argument): Split out non-expression parts of the
+ rule into 'non_simple_argument'.
+ (invocation_expression): Support parenthesized invocations with
+ multiple arguments, and with single non-simple arguments.
+
+2005-01-13 Raja R Harinath <rharinath@novell.com>
+
+ * cs-tokenizer.cs (xtoken): Reset 'comments_seen' in a couple more
+ places.
+
+2005-01-12 Raja R Harinath <rharinath@novell.com>
+
+ Fix cs0038-1.cs, cs1640-6.cs.
+ * ecore.cs (Expression.Resolve): Remove special-case for
+ SimpleName in error-handling.
+ (Expression.almostMatchedMembers): Relax access permission to
+ protected.
+ (Expression.MemberLookupFailed): Handle duplicates in
+ almostMatchedMembers list.
+ (SimpleName.DoSimpleNameResolve): Catch CS0038 errors earlier.
+ * expression.cs (New.DoResolve): Report CS1540 for more cases.
+ * typemanager.cs (GetFullNameSignature): Use the MethodBase
+ overload if the passed in MemberInfo is a MethodBase.
+
+2005-01-25 Martin Baulig <martin@ximian.com>
+
+ * doc.cs
+ (DocUtil.emptyParamList): Removed; use `Type.EmptyTypes' instead.
+
+2005-01-12 Marek Safar <marek.safar@seznam.cz>
+
+ Fix #70749
+ * attribute.cs (ExtractSecurityPermissionSet): Don't report error
+ for non-CAS & merge permission sets properly.
+
+2005-01-11 Raja R Harinath <rharinath@novell.com>
+
+ Improve standard-compliance of simple name and member access
+ resolution. Fixes bugs #52697, #57200, #67520, #69519.
+ * ecore.cs (FullNamedExpression): New abstract base class
+ for Namespaces and TypeExpressions.
+ (ResolveFlags.SimpleName): Remove.
+ (SimpleName): Remove support for dotted names.
+ (SimpleName.ResolveAsTypeStep): Simplify. Now just a wrapper to
+ DeclSpace.FindType and DeclSpace.LookupType.
+ (SimpleName.DoSimpleNameResolve): Remove support for dotted names.
+ (Expression.ExprClassName): Make member function.
+ * expression.cs (MemberAccess.ResolveAsTypeStep): Support LHS being
+ a namespace. Remove creation of dotted "SimpleName"s.
+ (MemberAccess.DoResolve): Likewise.
+ * decl.cs (DeclSpace.Cache): Make private.
+ (DeclSpace.LookupInterfaceOrClass): Return a FullNamedExpression.
+ (DeclSpace.FindType): Update.
+ (DeclSpace.LookupType): Move here from RootContext. Return a
+ FullNamedExpression.
+ * namespace.cs (Namespace): Derive from FullNamedExpression
+ so that it can be part of expression resolution.
+ (Namespace.Lookup): Return an FullNamedExpression.
+ (NamespaceEntry.LookupAlias): Lookup aliases only in current
+ namespace.
+ * rootcontext.cs (NamespaceLookup): Remove.
+ (LookupType): Move to DeclSpace.
+ * attribute.cs (CheckAttributeType): Update.
+ * doc.cs (FindDocumentedType): Remove allowAlias argument.
+ (FindDocumentedTypeNonArray): Likewise.
+
+2005-01-11 Raja R Harinath <rharinath@novell.com>
+
+ Fix cs0509.cs, cs1632.cs.
+ * class.cs (TypeContainer.GetNormalBases): Don't assume !IsClass
+ is the same as IsInterface.
+ (TypeContainer.GetClassBases): Likewise.
+ * statement.cs (LabeledStatement.ig): New field.
+ (LabeledStatement.LabelTarget): Save ILGenerator which created the
+ label.
+ (LabeledStatement.DoEmit): Check that the label was created with
+ the same ILGenerator.
+
+2005-01-10 Marek Safar <marek.safar@seznam.cz>
+
+ Fix #71058
+ * attribute.cs (GetMethodObsoleteAttribute): Need to transform
+ accessors to its properties.
+
+ * ecore.cs (PropertyExpr): Add AccessorTable to help track back
+ from accessors to property.
+
+2005-01-10 Marek Safar <marek.safar@seznam.cz>
+
+ Fix #70722
+ * class.cs (MethodCore.CheckBase): Test base method obsoleteness
+ only for overrides.
+
+2005-01-08 Miguel de Icaza <miguel@ximian.com>
+
+ * attribute.cs: Check for null and empty strings.
+
+ I have lost another battle to Paolo.
+
+2005-01-07 Marek Safar <marek.safar@seznam.cz>
+
+ Fix #70942
+ * class.cs (PropertyMethod): Set Parent field in ctors.
+ (SetMethod.InternalParameters): Add unsafe switch hack.
+ Override MarkForDuplicationCheck where it is appropriate.
+
+ * decl.cs (MemberCore.MarkForDuplicationCheck): New method.
+ It says whether container allows members with the same name.
+ Base default is no.
+ (DeclSpace.AddToContainer): Use MarkForDuplicationCheck.
+ Removed is_method parameter.
+
+2005-01-06 Duncan Mak <duncan@ximian.com>
+
+ * cs-tokenizer.cs (xtoken): Redo the work for signaling CS1040
+ because the previous change led to incorrect reporting of CS1032
+ ("Cannot define/undefine preprocessor symbols after first token in
+ file"). Instead of using `tokens_seen' as the only flag that
+ triggers CS1040, introduce `comments_seen'. This new flag is used
+ to signify having seen comments on the current line, so it is
+ unset after a newline.
+
+2005-01-06 Atsushi Enomoto <atsushi@ximian.com>
+
+ * doc.cs : When searching for a type, find nested type too.
+ This fixes bug #71040.
+
+2005-01-06 Atsushi Enomoto <atsushi@ximian.com>
+
+ * doc.cs :
+ - Warn missing member comment on those classes which also does not
+ have doc comments. Fixed bug #71041.
+ - Don't warn missing doc comment on default constructor.
+ Fixed bug #71042.
+
+2005-01-06 Duncan Mak <duncan@ximian.com>
+
+ * cs-tokenizer.cs (xtoken): After handling traditional C-style
+ comments, set `tokens_seen' to true. This allows us to detect
+ misplaced preprocessor directives (i.e. not at the beginning of
+ the a line, nor after whitespaces). In that case, report error
+ CS1040. This fixes bug #56460.
+
+ * cs-parser.jay (interface_member_declaration): Add checks for
+ IsExplicitImpl, and report CS0541 error if an interface member is
+ defined as an explicit interface declaration.
+
+2005-01-06 Marek Safar <marek.safar@seznam.cz>
+
+ Fix #70817
+ * class.cs (PropertyMethod): Set Parent field in ctors.
+ (SetMethod.InternalParameters): Add unsafe switch hack.
+
+ * decl.cs (MemberCore.Parent): Cannot be readonly.
+
+2005-01-06 Raja R Harinath <rharinath@novell.com>
+
+ * decl.cs (DeclSpace.ResolveType): Remove.
+ (DeclSpace.ResolveBaseTypeExpr): Rename from ResolveTypeExpr.
+ Merge in code from ...
+ (DeclSpace.GetTypeResolvingEmitContext): ... here. Remove.
+ * class.cs, enum.cs: Update to changes.
+
+2005-01-06 Miguel de Icaza <miguel@ximian.com>
+
+ * anonymous.cs: Ensure that we init the scope of our parent if it
+ has not been initialized yet.
+
+2004-12-30 Duncan Mak <duncan@ximian.com>
+
+ * typemanager.cs (TypeManager.CheckStructCycles): Don't crash here
+ if field.FieldBuilder is null. Fixes #70758.
+
+ * convert.cs: Fixed some typos and updated some of the comments.
+ (ImplicitStandardConversionExists):
+ (TryImplicitIntConversion): If `target_type' is an interface and
+ the type of `ic' implements this interface, return true or a new
+ BoxedCast instead of null. This fixes #70468.
+
+2004-12-29 Duncan Mak <duncan@ximian.com>
+
+ * expression.cs (Argument.Emit): Check that Expr is
+ IMemoryLocation before casting to it, and report CS1510 otherwise.
+
+ This fixes #70402.
+
+2004-12-21 Ben Maurer <bmaurer@ximian.com>
+
+ * statement.cs (Block.ThisVariable): remove the recursion here, to
+ make the --profile more sane.
+
+2004-12-17 Carlos Cortez <calberto.cortez@gmail.com>
+
+ * driver.cs: Patch to handle a xsp bug that prevents to reference an .exe
+ assembly, by JB Evain.
+
+2004-12-17 Raja R Harinath <rharinath@novell.com>
+
+ * class.cs, decl.cs, ecore.cs, iterators.cs, pending.cs,
+ rootcontext.cs, typemanager.cs: Make nomenclature consistent.
+ "parent" refers to enclosing type/class. "base" refers to superclass.
+
+2004-12-17 Raja R Harinath <rharinath@novell.com>
+
+ * codegen.cs (CommonAssemblyModulClass.GetClsCompliantAttribute):
+ Ensure that we only have GlobalAttributes.
+ * attribute.cs (Attribute.Emit): Make non-virtual.
+ (GlobalAttribute.Emit): Remove.
+ (Attribute.Resolve): Make virtual.
+ (GlobalAttribute.Resolve): New. Set Rootcontext.Tree.Types.NamespaceEntry.
+ (Attribute.GetConditionalAttributeValue): Take an EmitContext as
+ the argument. Don't create one.
+ (Attribute.GetObsoleteAttribute): Likewise.
+ (Attribute.GetClsCompliantAttributeValue): Likewise.
+ * class.cs, decl.cs: Update to changes.
+
+2004-12-17 Marek Safar <marek.safar@seznam.cz>
+
+ * delegate.cs (NewDelegate.DoResolve): Add error 149 report.
+
+ * ecore.cs (Expression.MemberLookupFailed): Fixed error 143.
+
+ * statement.cs (Foreach.Resolve): Add error 186 report.
+
+2004-12-16 Marek Safar <marek.safar@seznam.cz>
+
+ * expression.cs (Conditional.DoResolve): Add warning 429.
+
+ * statement.cs (If.Resolve): Add warning 665.
+
+2004-12-16 Raja R Harinath <rharinath@novell.com>
+
+ New invariant: RootContext.Tree.Types.NamespaceEntry == null
+ except when in the parser, and in GlobalAttribute.
+ * driver.cs (MainDriver): Reset RootContext.Tree.Types.NamespaceEntry.
+ * attribute.cs (GlobalAttribute.CheckAttributeType): Reset
+ RootContext.Tree.Types.NamespaceEntry once work is done.
+ (GlobalAttribute.Emit): New. Wrapper for Attribute.Emit, but sets
+ and resets RootContext.Tree.Types.NamespaceEntry.
+
+2004-12-15 Marek Safar <marek.safar@seznam.cz>
+
+ * cs-parser.jay: Don't create a block for every variable.
+
+2004-12-14 Miguel de Icaza <miguel@ximian.com>
+
+ * location.cs: Provide extra information.
+
+ * statement.cs: The instance is not `ldarg_0.THIS' when accessing
+ variables from the captured environment, it is the ldarg_0.
+
+2004-12-14 Marek Safar <marek.safar@seznam.cz>
+
+ * cs-parser.jay: Changed warning level for 642 to 4 until Miguel
+ find a conclusion.
+
+ * class.cs: Changed warning level for 169 to avoid developer
+ displeasure from warning flooding. It will be changed back when they
+ fix most of current BCL warnings.
+
+ * RootContext.cs: Pushed default WarningLevel to 3.
+
+ * statement.cs: Removed unused variable.
+
+2004-12-14 Marek Safar <marek.safar@seznam.cz>
+
+ * class.cs (TypeContainer.GetClassBases): Add error 1521 report.
+ (TypeContainer.MethodModifiersValid): Refactored to use MemberCore.
+ Add error 502 report.
+ (StaticClass.DefineType): Add error 441 report.
+ (Class.AllowedModifiersProp): New virtual property as temporary
+ extension to AllowedModifiers.
+ (Class.DefineType): Add error 418 report. Moved ModFlags check here
+ to share implementation with StaticClass and don't call virtual
+ methods from ctor.
+
+ * driver.cs (MainDriver): Add error 1558 test.
+
+ * parameter.cs (Parameter.ApplyAttributeBuilder): Add error 662
+ report. Moved error 36 test here.
+
+ * statement.cs (Throw.Resolve): Add error 724 report.
+
+ * typemanager.cs: Add out_attribute_type core type.
+
+2004-12-13 Marek Safar <marek.safar@seznam.cz>
+
+ * class.cs (TypeContainer.VerifyClsCompliance): Add error
+ 3018 report.
+ (PropertyBase.VerifyClsCompliance): Add errror 3025 report.
+
+ * codegen.cs (ModuleClass.ApplyAttributeBuilder): Add error
+ 3017 report.
+
+ * decl.cs (MemberCore.VerifyClsCompliance): Add warning 3021.
+
+ * parameter.cs (ReturnParameter.ApplyAttributeBuilder):
+ Add error 3023 report.
+ (Parameter.ApplyAttributeBuilder): Add error 3022 report.
+
+ * tree.cs (RootTypes.IsClsCompliaceRequired): Add fake
+ implementation.
+
+2004-12-12 John Luke <john.luke@gmail.com>
+
+ * driver.cs (AddArgs): take -- into account when
+ adding arguments, fixes bug 65710
+
+2004-12-12 Martin Baulig <martin@ximian.com>
+
+ * expression.cs (Unary.TryReduceNegative): Added support for
+ SByteConstant and ByteConstant.
+ (Unary.Reduce): Check error values from TryReduceNegative().
+
+2004-12-10 Marek Safar <marek.safar@seznam.cz>
+
+ * attributes.cs (Attribute.Resolve): Avoid multiple error report
+ and report exception as error 182.
+
+2004-12-10 Raja R Harinath <rharinath@novell.com>
+
+ * driver.cs (Main): Fix message when there are warnings.
+
+2004-12-09 Miguel de Icaza <miguel@ximian.com>
+
+ * delegate.cs: Fixed my fix from yesterday, sorry about that.
+
+2004-12-09 Marek Safar <marek.safar@seznam.cz>
+
+ * anonymous.cs, class.cs, convert.cs, doc.cs, support.cs:
+ Reduced number of warnings.
+
+ * class.cs (TypeContainer.VerifyClsCompliance): One if is enough.
+
+2004-12-08 Miguel de Icaza <miguel@ximian.com>
+
+ * driver.cs: Removed message.
+
+ * delegate.cs: Fix bug introduced in 1.1.x: 70219.
+
+2004-12-08 <vargaz@freemail.hu>
+
+ * cs-tokenizer.cs: Add workaround for NET 2.0 beta 1 csc bug.
+
+2004-12-08 Martin Baulig <martin@ximian.com>
+
+ * class.cs (TypeContainer.VerifyClsCompliance): Report a CS3003
+ instead of a CS3002 for properties and indexer.
+
+2004-12-08 Martin Baulig <martin@ximian.com>
+
+ * decl.cs (MemberName.ToString): Make this work again.
+
+2004-12-08 Marek Safar <marek.safar@seznam.cz>
+
+ * attribute.cs (Resolve): Add error 591 detection.
+
+ * class.cs (FieldMember.Define): Add error 1547 detection.
+ (Indexer.Define): Add error 620 detection.
+ (Operator.Define): Add error 590 detection.
+
+ * ecore.cs: Missing argument for error 79.
+
+ * expression.cs (ComposedCast.DoResolveAsTypeStep): Add error 611
+ detection.
+
+2004-12-07 Marek Safar <marek.safar@seznam.cz>
+
+ Fix #70106
+ * assign.cs.cs (Assign.DoResolve): Reports error 1648 for value types
+ only.
+
+2004-12-07 Atsushi Enomoto <atsushi@ximian.com>
+
+ * cs-parser.jay : handle doc comments on implicit/explicit operators.
+ Some operator comments were suppressed.
+ * doc.cs : Implicit/explicit operator name in doc comments are like
+ "op_Explicit(type)~returnType", so added suffix handling.
+
+2005-01-21 Alp Toker <alp@atoker.com>
+
+ * cs-parser.jay: destructor_declaration's container is PartialContainer
+ not Class when partial types are used, so use Kind prop instead of 'is'.
+
2004-12-12 Martin Baulig <martin@ximian.com>
* expression.cs (Unary.TryReduceNegative): Added support for
throw new CryptographicException ("Invalid blob header");
// ALGID (CALG_RSA_SIGN, CALG_RSA_KEYX, ...)
- int algId = ToInt32LE (blob, offset+4);
+ // int algId = ToInt32LE (blob, offset+4);
// DWORD bitlen
int bitLen = ToInt32LE (blob, offset+12);
throw new CryptographicException ("Invalid blob header");
// ALGID (CALG_RSA_SIGN, CALG_RSA_KEYX, ...)
- int algId = ToInt32LE (blob, offset+4);
+ // int algId = ToInt32LE (blob, offset+4);
// DWORD bitlen
int bitLen = ToInt32LE (blob, offset+12);
if (rsa == null)
throw new ArgumentNullException ("rsa");
- RSAParameters p = rsa.ExportParameters (includePrivateKey);
+ rsa.ExportParameters (includePrivateKey);
if (includePrivateKey)
return ToCapiPrivateKeyBlob (rsa);
else
* This is BMCS
- Last merge to GMCS: 38733
+ Last merge to GMCS: 40534
BMCS is a new fork of the generics compiler from revision
38733 (11th of January 2005).
if (ScopeTypeBuilder != null)
return;
- ILGenerator ig = ec.ig;
TypeBuilder container = ec.TypeContainer.TypeBuilder;
ScopeTypeBuilder = container.DefineNestedType (
Hashtable captured_parameters = CaptureContext.captured_parameters;
foreach (DictionaryEntry de in captured_parameters){
- string name = (string) de.Key;
CapturedParameter cp = (CapturedParameter) de.Value;
ig.Emit (OpCodes.Ldloc, ScopeInstance);
}
if (ParentScope != null){
+ if (!ParentScope.inited)
+ ParentScope.EmitInitScope (ec);
+
//
// Only emit initialization in our capturecontext world
//
public override string ToString ()
{
- ToplevelBlock parent = ParentToplevel;
StringBuilder sb = new StringBuilder ();
-
sb.Append ("[");
DoPath (sb, this);
sb.Append ("]");
cc.EmitParameterInstance (ec, name);
return;
}
- Block invocation_block = ec.CurrentBlock;
+
CapturedParameter par_info = (CapturedParameter) captured_parameters [name];
+ if (par_info != null){
+ //
+ // FIXME: implementing this.
+ //
+ }
ILGenerator ig = ec.ig;
ScopeInfo si;
}
EmitParameterInstance (ec, name);
CapturedParameter par_info = (CapturedParameter) captured_parameters [name];
+ if (par_info != null){
+ //
+ // FIXME: implementing this.
+ //
+ }
ec.ig.Emit (OpCodes.Ldfld, par_info.FieldBuilder);
}
}
FieldExpr field_exp = target as FieldExpr;
- if (field_exp != null && !ec.IsConstructor && !ec.IsFieldInitializer) {
+ if (field_exp != null && field_exp.DeclaringType.IsValueType && !ec.IsConstructor && !ec.IsFieldInitializer) {
field_exp = field_exp.InstanceExpression as FieldExpr;
if (field_exp != null && field_exp.FieldInfo.IsInitOnly) {
if (field_exp.IsStatic) {
public Type Type;
+ bool resolve_error;
+
// Is non-null if type is AttributeUsageAttribute
AttributeUsageAttribute usage_attribute;
Name);
}
- static void Error_AttributeArgumentNotValid (Location loc)
+ static void Error_AttributeArgumentNotValid (string extra, Location loc)
{
Report.Error (182, loc,
"An attribute argument must be a constant expression, typeof " +
- "expression or array creation expression");
+ "expression or array creation expression" + extra);
}
+ static void Error_AttributeArgumentNotValid (Location loc)
+ {
+ Error_AttributeArgumentNotValid ("", loc);
+ }
+
static void Error_TypeParameterInAttribute (Location loc)
{
Report.Error (
protected virtual Type CheckAttributeType (EmitContext ec)
{
string NameAttribute = Name + "Attribute";
- Type t1 = ec.ResolvingTypeTree
+ FullNamedExpression n1 = ec.ResolvingTypeTree
? ec.DeclSpace.FindType (Location, Name)
- : RootContext.LookupType (ec.DeclSpace, Name, true, Location);
+ : ec.DeclSpace.LookupType (Name, true, Location);
// FIXME: Shouldn't do this for quoted attributes: [@A]
- Type t2 = ec.ResolvingTypeTree
+ FullNamedExpression n2 = ec.ResolvingTypeTree
? ec.DeclSpace.FindType (Location, NameAttribute)
- : RootContext.LookupType (ec.DeclSpace, NameAttribute, true, Location);
+ : ec.DeclSpace.LookupType (NameAttribute, true, Location);
+
+ TypeExpr e1 = n1 == null ? null : n1 as TypeExpr;
+ TypeExpr e2 = n2 == null ? null : n2 as TypeExpr;
+
+ Type t1 = e1 == null ? null : e1.ResolveType (ec);
+ Type t2 = e2 == null ? null : e2.ResolveType (ec);
String err0616 = null;
if (t1 != null && ! t1.IsSubclassOf (TypeManager.attribute_type)) {
"Could not find attribute '" + Name
+ "' (are you missing a using directive or an assembly reference ?)");
+ resolve_error = true;
return null;
}
return false;
}
- public CustomAttributeBuilder Resolve (EmitContext ec)
+ public virtual CustomAttributeBuilder Resolve (EmitContext ec)
{
+ if (resolve_error)
+ return null;
+
+ resolve_error = true;
+
Type oldType = Type;
// Sanity check.
if (DoCompares){
if (usage_attr) {
+ if ((int)val == 0) {
+ Report.Error (591, Location, "Invalid value for argument to 'System.AttributeUsage' attribute");
+ return null;
+ }
usage_attribute = new AttributeUsageAttribute ((AttributeTargets)val);
} else if (MethodImplAttr) {
this.ImplOptions = (MethodImplOptions) val;
else
cb = new CustomAttributeBuilder (
(ConstructorInfo) constructor, pos_values);
- } catch (NullReferenceException) {
- //
- // Don't know what to do here
- //
- Report.Warning (
- -101, Location, "NullReferenceException while trying to create attribute." +
- "Something's wrong!");
} catch (Exception e) {
//
// Sample:
// [DefaultValue (CollectionChangeAction.Add)]
// class X { static void Main () {} }
//
- Report.Warning (
- -23, Location, "The compiler can not encode this attribute in .NET due to a bug in the .NET runtime. Try the Mono runtime. The exception was: " + e.Message);
+ Error_AttributeArgumentNotValid (Location);
+ return null;
}
+ resolve_error = false;
return cb;
}
/// </summary>
public string GetIndexerAttributeValue (EmitContext ec)
{
- if (pos_values == null) {
+ if (pos_values == null)
// TODO: It is not neccessary to call whole Resolve (ApplyAttribute does it now) we need only ctor args.
// But because a lot of attribute class code must be rewritten will be better to wait...
Resolve (ec);
- }
return pos_values [0] as string;
}
/// <summary>
/// Returns condition of ConditionalAttribute
/// </summary>
- public string GetConditionalAttributeValue (DeclSpace ds)
+ public string GetConditionalAttributeValue (EmitContext ec)
{
- if (pos_values == null) {
- EmitContext ec = new EmitContext (ds, ds, Location, null, null, 0, false);
-
+ if (pos_values == null)
// TODO: It is not neccessary to call whole Resolve (ApplyAttribute does it now) we need only ctor args.
// But because a lot of attribute class code must be rewritten will be better to wait...
Resolve (ec);
- }
// Some error occurred
if (pos_values [0] == null)
/// <summary>
/// Creates the instance of ObsoleteAttribute from this attribute instance
/// </summary>
- public ObsoleteAttribute GetObsoleteAttribute (DeclSpace ds)
+ public ObsoleteAttribute GetObsoleteAttribute (EmitContext ec)
{
- if (pos_values == null) {
- EmitContext ec = new EmitContext (ds, ds, Location, null, null, 0, false);
-
+ if (pos_values == null)
// TODO: It is not neccessary to call whole Resolve (ApplyAttribute does it now) we need only ctor args.
// But because a lot of attribute class code must be rewritten will be better to wait...
Resolve (ec);
- }
// Some error occurred
if (pos_values == null)
/// before ApplyAttribute. We need to resolve the arguments.
/// This situation occurs when class deps is differs from Emit order.
/// </summary>
- public bool GetClsCompliantAttributeValue (DeclSpace ds)
+ public bool GetClsCompliantAttributeValue (EmitContext ec)
{
- if (pos_values == null) {
- EmitContext ec = new EmitContext (ds, ds, Location, null, null, 0, false);
-
+ if (pos_values == null)
// TODO: It is not neccessary to call whole Resolve (ApplyAttribute does it now) we need only ctor args.
// But because a lot of attribute class code must be rewritten will be better to wait...
Resolve (ec);
- }
// Some error occurred
if (pos_values [0] == null)
}
}
- IPermission perm = sa.CreatePermission ();
- SecurityAction action;
+ IPermission perm;
+ try {
+ perm = sa.CreatePermission ();
+ }
+ catch (Exception e) {
+ Error_AttributeEmitError (String.Format ("{0} was thrown during attribute processing: {1}", e.GetType (), e.Message));
+ return;
+ }
+ SecurityAction action = GetSecurityActionValue ();
// IS is correct because for corlib we are using an instance from old corlib
- if (perm is System.Security.CodeAccessPermission) {
- action = GetSecurityActionValue ();
- } else {
- switch (GetSecurityActionValue ()) {
+ if (!(perm is System.Security.CodeAccessPermission)) {
+ switch (action) {
case SecurityAction.Demand:
action = (SecurityAction)13;
break;
case SecurityAction.InheritanceDemand:
action = (SecurityAction)15;
break;
- default:
- Error_AttributeEmitError ("Invalid SecurityAction for non-Code Access Security permission");
- return;
}
}
PermissionSet ps = (PermissionSet)permissions [action];
if (ps == null) {
- ps = new PermissionSet (PermissionState.None);
+ if (sa is PermissionSetAttribute)
+ ps = new PermissionSet (sa.Unrestricted ? PermissionState.Unrestricted : PermissionState.None);
+ else
+ ps = new PermissionSet (PermissionState.None);
+
permissions.Add (action, ps);
+ } else if (!ps.IsUnrestricted () && sa.Unrestricted) {
+ ps = ps.Union (new PermissionSet (PermissionState.Unrestricted));
+ permissions [action] = ps;
}
- ps.AddPermission (sa.CreatePermission ());
+ ps.AddPermission (perm);
}
object GetValue (object value)
Error_AttributeArgumentNotValid (Location);
return null;
}
-
+ if (dll_name == null || dll_name == ""){
+ Error_AttributeArgumentNotValid (": DllImport requires a non-empty string", Location);
+ return null;
+ }
+
// Now we process the named arguments
CallingConvention cc = CallingConvention.Winapi;
CharSet charset = CharSet.Ansi;
// in effect where the attribute was used. Since code elsewhere cannot assume
// that the NamespaceEntry is right, just overwrite it.
//
- // FIXME: Check every place the NamespaceEntry of RootContext.Tree.Types is used
- // to ensure the right one is used.
+ // Precondition: RootContext.Tree.Types == null || RootContext.Tree.Types == ns.
+ // The second case happens when we are recursively invoked from inside Emit.
+
+ NamespaceEntry old = null;
+ if (ec.DeclSpace == RootContext.Tree.Types) {
+ old = ec.DeclSpace.NamespaceEntry;
+ ec.DeclSpace.NamespaceEntry = ns;
+ if (old != null && old != ns)
+ throw new InternalErrorException (Location + " non-null NamespaceEntry " + old);
+ }
+
+ Type retval = base.CheckAttributeType (ec);
+
if (ec.DeclSpace == RootContext.Tree.Types)
+ ec.DeclSpace.NamespaceEntry = old;
+
+ return retval;
+ }
+
+ public override CustomAttributeBuilder Resolve (EmitContext ec)
+ {
+ if (ec.DeclSpace == RootContext.Tree.Types) {
+ NamespaceEntry old = ec.DeclSpace.NamespaceEntry;
ec.DeclSpace.NamespaceEntry = ns;
+ if (old != null)
+ throw new InternalErrorException (Location + " non-null NamespaceEntry " + old);
+ }
+
+ CustomAttributeBuilder retval = base.Resolve (ec);
- return base.CheckAttributeType (ec);
+ if (ec.DeclSpace == RootContext.Tree.Types)
+ ec.DeclSpace.NamespaceEntry = null;
+
+ return retval;
}
}
if (mb.DeclaringType is TypeBuilder)
return null;
+ PropertyInfo pi = PropertyExpr.AccessorTable [mb] as PropertyInfo;
+ if (pi != null)
+ return GetMemberObsoleteAttribute (pi);
+
return GetMemberObsoleteAttribute (mb);
}
// from classes from the arraylist `type_bases'
//
string base_class_name;
- TypeExpr parent_type;
+ TypeExpr base_type;
ArrayList type_bases;
protected Type[] ifaces;
protected Type ptype;
- // The parent member cache and our member cache
- MemberCache parent_cache;
+ // The base member cache and our member cache
+ MemberCache base_cache;
MemberCache member_cache;
public const string DefaultIndexerName = "Item";
base_class_name = null;
}
- public bool AddToMemberContainer (MemberCore symbol, bool is_method)
+ public bool AddToMemberContainer (MemberCore symbol)
{
- return AddToContainer (symbol, is_method, String.Concat (Name, '.', symbol.Name), symbol.Name);
+ return AddToContainer (symbol, String.Concat (Name, '.', symbol.Name), symbol.Name);
}
bool AddToTypeContainer (DeclSpace ds)
{
- return AddToContainer (ds, false, ds.Name, ds.Basename);
+ return AddToContainer (ds, ds.Name, ds.Basename);
}
public void AddConstant (Const constant)
{
- if (!AddToMemberContainer (constant, false))
+ if (!AddToMemberContainer (constant))
return;
if (constants == null)
public void AddMethod (Method method)
{
- if (!AddToMemberContainer (method, true))
+ if (!AddToMemberContainer (method))
return;
if (methods == null)
public void AddField (Field field)
{
- if (!AddToMemberContainer (field, false))
+ if (!AddToMemberContainer (field))
return;
if (fields == null)
public void AddProperty (Property prop)
{
- if (!AddToMemberContainer (prop, false) ||
- !AddToMemberContainer (prop.Get, true) || !AddToMemberContainer (prop.Set, true))
+ if (!AddToMemberContainer (prop) ||
+ !AddToMemberContainer (prop.Get) || !AddToMemberContainer (prop.Set))
return;
if (properties == null)
public void AddEvent (Event e)
{
- if (!AddToMemberContainer (e, false))
+ if (!AddToMemberContainer (e))
return;
if (e is EventProperty) {
- if (!AddToMemberContainer (e.Add, true))
+ if (!AddToMemberContainer (e.Add))
return;
- if (!AddToMemberContainer (e.Remove, true))
+ if (!AddToMemberContainer (e.Remove))
return;
}
public void AddOperator (Operator op)
{
- if (!AddToMemberContainer (op, true))
+ if (!AddToMemberContainer (op))
return;
if (operators == null)
public override AttributeTargets AttributeTargets {
get {
- throw new NotSupportedException ();
+ switch (Kind) {
+ case Kind.Class:
+ return AttributeTargets.Class;
+ case Kind.Struct:
+ return AttributeTargets.Struct;
+ case Kind.Interface:
+ return AttributeTargets.Interface;
+ default:
+ throw new NotSupportedException ();
+ }
}
}
public abstract PendingImplementation GetPendingImplementations ();
- TypeExpr[] GetPartialBases (out TypeExpr parent, out bool error)
+ TypeExpr[] GetPartialBases (out TypeExpr base_class, out bool error)
{
ArrayList ifaces = new ArrayList ();
- parent = null;
- Location parent_loc = Location.Null;
+ base_class = null;
+ Location base_loc = Location.Null;
foreach (ClassPart part in parts) {
- TypeExpr new_parent;
+ TypeExpr new_base_class;
TypeExpr[] new_ifaces;
- new_ifaces = part.GetClassBases (out new_parent, out error);
+ new_ifaces = part.GetClassBases (out new_base_class, out error);
if (error)
return null;
- if ((parent != null) && (new_parent != null) &&
- !parent.Equals (new_parent)) {
+ if ((base_class != null) && (new_base_class != null) &&
+ !base_class.Equals (new_base_class)) {
Report.Error (263, part.Location,
"Partial declarations of `{0}' must " +
"not specify different base classes",
Name);
- if (!Location.IsNull (parent_loc))
- Report.LocationOfPreviousError (parent_loc);
+ if (!Location.IsNull (base_loc))
+ Report.LocationOfPreviousError (base_loc);
error = true;
return null;
}
- if ((parent == null) && (new_parent != null)) {
- parent = new_parent;
- parent_loc = part.Location;
+ if ((base_class == null) && (new_base_class != null)) {
+ base_class = new_base_class;
+ base_loc = part.Location;
}
if (new_ifaces == null)
return retval;
}
- TypeExpr[] GetNormalBases (out TypeExpr parent, out bool error)
+ TypeExpr[] GetNormalBases (out TypeExpr base_class, out bool error)
{
- parent = null;
+ base_class = null;
int count = Bases.Count;
- int start, i, j;
+ int start = 0, i, j;
if (Kind == Kind.Class){
- TypeExpr name = ResolveTypeExpr ((Expression) Bases [0], Location);
+ TypeExpr name = ResolveBaseTypeExpr (
+ (Expression) Bases [0], false, Location);
if (name == null){
error = true;
return null;
}
- if (name.IsClass){
- parent = name;
+ if (!name.IsInterface) {
+ // base_class could be a class, struct, enum, delegate.
+ // This is validated in GetClassBases.
+ base_class = name;
start = 1;
- } else {
- start = 0;
}
- } else {
- start = 0;
}
TypeExpr [] ifaces = new TypeExpr [count-start];
for (i = start, j = 0; i < count; i++, j++){
- Expression name = (Expression) Bases [i];
- TypeExpr resolved = ResolveTypeExpr (name, Location);
+ TypeExpr resolved = ResolveBaseTypeExpr ((Expression) Bases [i], false, Location);
if (resolved == null) {
error = true;
return null;
/// The return value is an array (might be null) of
/// interfaces implemented (as Types).
///
- /// The @parent argument is set to the parent object or null
+ /// The @base_class argument is set to the base object or null
/// if this is `System.Object'.
/// </summary>
- TypeExpr [] GetClassBases (out TypeExpr parent, out bool error)
+ TypeExpr [] GetClassBases (out TypeExpr base_class, out bool error)
{
int i;
TypeExpr[] ifaces;
if (parts != null)
- ifaces = GetPartialBases (out parent, out error);
+ ifaces = GetPartialBases (out base_class, out error);
else if (Bases == null){
- parent = null;
+ base_class = null;
return null;
} else
- ifaces = GetNormalBases (out parent, out error);
+ ifaces = GetNormalBases (out base_class, out error);
if (error)
return null;
- if ((parent != null) && (Kind == Kind.Class)){
- if (parent is TypeParameterExpr){
+ if ((base_class != null) && (Kind == Kind.Class)){
+ if (base_class is TypeParameterExpr){
Report.Error (
- 689, parent.Location,
+ 689, base_class.Location,
"Type parameter `{0}' can not be used as a " +
- "base class or interface", parent.Name);
+ "base class or interface", base_class.Name);
error = true;
return null;
}
- if (IsGeneric && parent.IsAttribute){
+ if (IsGeneric && base_class.IsAttribute){
Report.Error (
- 698, parent.Location,
+ 698, base_class.Location,
"A generic type cannot derive from `{0}' " +
"because it is an attribute class",
- parent.Name);
+ base_class.Name);
+ error = true;
+ return null;
+ }
+
+ if (base_class.Type.IsArray || base_class.Type.IsPointer) {
+ Report.Error (1521, base_class.Location, "Invalid base type");
error = true;
return null;
}
- if (parent.IsSealed){
+ if (base_class.IsSealed){
error = true;
- Report.SymbolRelatedToPreviousError (parent.Type);
- if (parent.Type.IsAbstract) {
+ Report.SymbolRelatedToPreviousError (base_class.Type);
+ if (base_class.Type.IsAbstract) {
Report.Error (709, Location, "'{0}': Cannot derive from static class", GetSignatureForError ());
} else {
Report.Error (509, Location, "'{0}': Cannot derive from sealed class", GetSignatureForError ());
return null;
}
- if (!parent.CanInheritFrom ()){
+ if (!base_class.CanInheritFrom ()){
Report.Error (644, Location,
"`{0}' cannot inherit from special class `{1}'",
- Name, parent_type.Name);
+ Name, base_class.Name);
error = true;
return null;
}
- if (!parent.AsAccessible (this, ModFlags)) {
- Report.SymbolRelatedToPreviousError (parent.Type);
+ if (!base_class.AsAccessible (this, ModFlags)) {
+ Report.SymbolRelatedToPreviousError (base_class.Type);
Report.Error (60, Location, "Inconsistent accessibility: base class '{0}' is less accessible than class '{1}'",
- TypeManager.CSharpName (parent.Type), GetSignatureForError ());
+ TypeManager.CSharpName (base_class.Type), GetSignatureForError ());
}
}
- if (parent != null)
- base_class_name = parent.Name;
+ if (base_class != null)
+ base_class_name = base_class.Name;
if (ifaces == null)
return null;
for (i = 0; i < count; i++) {
TypeExpr iface = (TypeExpr) ifaces [i];
- if ((Kind != Kind.Class) && !iface.IsInterface){
- string what = Kind == Kind.Struct ?
- "Struct" : "Interface";
-
- Report.Error (527, Location,
- "In {0} `{1}', type `{2}' is not "+
- "an interface", what, Name, iface.Name);
+ if (!iface.IsInterface) {
error = true;
- return null;
- }
-
- if (iface.IsClass) {
- if (parent != null)
+ if (Kind != Kind.Class) {
+ string what = Kind == Kind.Struct ? "Struct" : "Interface";
+
+ Report.Error (527, Location,
+ "In {0} `{1}', type `{2}' is not "+
+ "an interface", what, Name, iface.Name);
+ }
+ else if (base_class != null)
Report.Error (1721, Location,
"In Class `{0}', `{1}' is not an interface, and a base class has already been defined",
Name, iface.Name);
"In Class `{0}', `{1}' is not " +
"an interface, a base class must be listed first", Name, iface.Name);
}
- error = true;
- return null;
+ continue;
}
for (int x = 0; x < i; x++) {
"`{0}' is already listed in " +
"interface list", iface.Name);
error = true;
- return null;
}
}
if ((Kind == Kind.Interface) &&
- !iface.AsAccessible (Parent, ModFlags))
+ !iface.AsAccessible (Parent, ModFlags)) {
Report.Error (61, Location,
"Inconsistent accessibility: base " +
"interface `{0}' is less accessible " +
"than interface `{1}'", iface.Name,
Name);
+ error = true;
+ }
}
+ if (error)
+ return null;
+
return ifaces;
}
//
public override TypeBuilder DefineType ()
{
- TypeExpr parent;
-
if (error)
return null;
if ((Kind == Kind.Struct) && TypeManager.value_type == null)
throw new Exception ();
- TypeExpr[] iface_exprs = GetClassBases (out parent_type, out error);
+ TypeExpr[] iface_exprs = GetClassBases (out base_type, out error);
if (error)
return null;
- if (parent_type == null) {
+ if (base_type == null) {
if (Kind == Kind.Class){
if (RootContext.StdLib)
- parent_type = TypeManager.system_object_expr;
+ base_type = TypeManager.system_object_expr;
else if (Name != "System.Object")
- parent_type = TypeManager.system_object_expr;
+ base_type = TypeManager.system_object_expr;
} else if (Kind == Kind.Struct){
//
// If we are compiling our runtime,
// and we are defining ValueType, then our
- // parent is `System.Object'.
+ // base is `System.Object'.
//
if (!RootContext.StdLib && Name == "System.ValueType")
- parent_type = TypeManager.system_object_expr;
+ base_type = TypeManager.system_object_expr;
else if (Kind == Kind.Struct)
- parent_type = TypeManager.system_valuetype_expr;
+ base_type = TypeManager.system_valuetype_expr;
}
}
- if (parent_type != null) {
- parent_type = parent_type.ResolveAsTypeTerminal (ec);
- if (parent_type == null) {
+ if (base_type != null) {
+ base_type = base_type.ResolveAsTypeTerminal (ec);
+ if (base_type == null) {
error = true;
return null;
}
- ptype = parent_type.Type;
+ ptype = base_type.Type;
}
if (!CheckRecursiveDefinition ()) {
// add interfaces that were not added at type creation
if (iface_exprs != null) {
+ // FIXME: I think this should be ...ExpandInterfaces (Parent.EmitContext, ...).
+ // However, if Parent == RootContext.Tree.Types, its NamespaceEntry will be null.
ifaces = TypeManager.ExpandInterfaces (ec, iface_exprs);
if (ifaces == null) {
error = true;
//
ec.ContainerType = TypeBuilder;
- if ((parent_type != null) && parent_type.IsAttribute) {
+ if ((base_type != null) && base_type.IsAttribute) {
RootContext.RegisterAttribute (this);
} else if (!(this is Iterator))
RootContext.RegisterOrder (this);
if (Parts != null) {
foreach (ClassPart part in Parts) {
part.TypeBuilder = TypeBuilder;
- part.parent_type = parent_type;
+ part.base_type = base_type;
part.ec = new EmitContext (part, Mono.CSharp.Location.Null, null, null, ModFlags);
}
}
// We need to be able to use the member cache while we are checking/defining
//
if (TypeBuilder.BaseType != null)
- parent_cache = TypeManager.LookupMemberCache (TypeBuilder.BaseType);
+ base_cache = TypeManager.LookupMemberCache (TypeBuilder.BaseType);
if (TypeBuilder.IsInterface)
- parent_cache = TypeManager.LookupParentInterfacesCache (TypeBuilder);
+ base_cache = TypeManager.LookupBaseInterfacesCache (TypeBuilder);
if (IsTopLevel) {
if ((ModFlags & Modifiers.NEW) != 0)
return true;
}
- public MemberInfo FindMemberWithSameName (string name, bool ignore_methods)
+ public MemberInfo FindBaseMemberWithSameName (string name, bool ignore_methods)
{
- return ParentCache.FindMemberWithSameName (name, ignore_methods, null);
+ return BaseCache.FindMemberWithSameName (name, ignore_methods, null);
}
/// <summary>
}
//
- // Lookup members in parent if requested.
+ // Lookup members in base if requested.
//
if ((bf & BindingFlags.DeclaredOnly) == 0) {
if (TypeBuilder.BaseType != null) {
//
// Check for internal or private fields that were never assigned
//
- if (RootContext.WarningLevel >= 3) {
+ if (RootContext.WarningLevel >= 4) {
if (fields != null){
foreach (Field f in fields) {
if ((f.ModFlags & Modifiers.Accessibility) != Modifiers.PRIVATE)
type_bases = null;
OptAttributes = null;
ifaces = null;
- parent_cache = null;
+ base_cache = null;
member_cache = null;
}
// Performs the validation on a Method's modifiers (properties have
// the same properties).
//
- public bool MethodModifiersValid (int flags, string n, Location loc)
+ public bool MethodModifiersValid (MemberCore mc)
{
const int vao = (Modifiers.VIRTUAL | Modifiers.ABSTRACT | Modifiers.OVERRIDE);
const int va = (Modifiers.VIRTUAL | Modifiers.ABSTRACT);
const int nv = (Modifiers.NEW | Modifiers.VIRTUAL);
bool ok = true;
+ int flags = mc.ModFlags;
//
// At most one of static, virtual or override
//
if ((flags & Modifiers.STATIC) != 0){
if ((flags & vao) != 0){
- Report.Error (
- 112, loc, "static method " + MakeName (n) + "can not be marked " +
- "as virtual, abstract or override");
+ Report.Error (112, mc.Location, "static method '{0}' can not be marked as virtual, abstract or override",
+ GetSignatureForError ());
ok = false;
}
}
if (Kind == Kind.Struct){
if ((flags & va) != 0){
- Modifiers.Error_InvalidModifier (loc, "virtual or abstract");
+ Modifiers.Error_InvalidModifier (mc.Location, "virtual or abstract");
ok = false;
}
}
if ((flags & Modifiers.OVERRIDE) != 0 && (flags & nv) != 0){
- Report.Error (
- 113, loc, MakeName (n) +
- " marked as override cannot be marked as new or virtual");
+ Report.Error (113, mc.Location, "'{0}' marked as override cannot be marked as new or virtual", mc.GetSignatureForError ());
ok = false;
}
if ((flags & Modifiers.ABSTRACT) != 0){
if ((flags & Modifiers.EXTERN) != 0){
Report.Error (
- 180, loc, MakeName (n) + " can not be both abstract and extern");
+ 180, mc.Location, "'{0}' can not be both abstract and extern", mc.GetSignatureForError ());
+ ok = false;
+ }
+
+ if ((flags & Modifiers.SEALED) != 0) {
+ Report.Error (502, mc.Location, "'{0}' cannot be both abstract and sealed", mc.GetSignatureForError ());
ok = false;
}
if ((flags & Modifiers.VIRTUAL) != 0){
- Report.Error (
- 503, loc, MakeName (n) + " can not be both abstract and virtual");
+ Report.Error (503, mc.Location, "'{0}' can not be both abstract and virtual", mc.GetSignatureForError ());
ok = false;
}
if ((ModFlags & Modifiers.ABSTRACT) == 0){
- Report.Error (
- 513, loc, MakeName (n) +
- " is abstract but its container class is not");
+ Report.Error (513, mc.Location, "'{0}' is abstract but its container class is not", mc.GetSignatureForError ());
ok = false;
-
}
}
if ((flags & Modifiers.PRIVATE) != 0){
if ((flags & vao) != 0){
- Report.Error (
- 621, loc, MakeName (n) +
- " virtual or abstract members can not be private");
+ Report.Error (621, mc.Location, "'{0}' virtual or abstract members can not be private", mc.GetSignatureForError ());
ok = false;
}
}
if ((flags & Modifiers.SEALED) != 0){
if ((flags & Modifiers.OVERRIDE) == 0){
- Report.Error (
- 238, loc, MakeName (n) +
- " cannot be sealed because it is not an override");
+ Report.Error (238, mc.Location, "'{0}' cannot be sealed because it is not an override", mc.GetSignatureForError ());
ok = false;
}
}
if (base_type != null && !AttributeTester.IsClsCompliant (base_type)) {
Report.Error (3009, Location, "'{0}': base type '{1}' is not CLS-compliant", GetSignatureForError (), TypeManager.CSharpName (base_type));
}
+
+ if (!Parent.IsClsCompliaceRequired (ds)) {
+ Report.Error (3018, Location, "'{0}' cannot be marked as CLS-Compliant because it is a member of non CLS-Compliant type '{1}'",
+ GetSignatureForError (), Parent.GetSignatureForError ());
+ }
return true;
}
/// </summary>
void VerifyClsName ()
{
- Hashtable parent_members = parent_cache == null ?
+ Hashtable base_members = base_cache == null ?
new Hashtable () :
- parent_cache.GetPublicMembers ();
+ base_cache.GetPublicMembers ();
Hashtable this_members = new Hashtable ();
foreach (DictionaryEntry entry in defined_names) {
string basename = name.Substring (name.LastIndexOf ('.') + 1);
string lcase = basename.ToLower (System.Globalization.CultureInfo.InvariantCulture);
- object found = parent_members [lcase];
+ object found = base_members [lcase];
if (found == null) {
found = this_members [lcase];
if (found == null) {
}
if (!found){
- Report.Error (540, "`" + full + "': containing class does not implement interface `" + interface_type.FullName + "'");
+ Report.Error (540, loc, "`{0}': containing class does not implement interface `{1}'",
+ full, interface_type.FullName);
return false;
}
get { return "T:"; }
}
- public virtual MemberCache ParentCache {
+ public virtual MemberCache BaseCache {
get {
- return parent_cache;
+ return base_cache;
}
}
interface_type, full, name, loc);
}
- public override MemberCache ParentCache {
+ public override MemberCache BaseCache {
get {
- return PartialContainer.ParentCache;
+ return PartialContainer.BaseCache;
}
}
}
public sealed class StaticClass: Class {
public StaticClass (NamespaceEntry ns, TypeContainer parent, MemberName name, int mod,
Attributes attrs, Location l)
- : base (ns, parent, name, mod & ~Modifiers.STATIC, attrs, l)
+ : base (ns, parent, name, mod, attrs, l)
{
if (RootContext.Version == LanguageVersion.ISO_1) {
Report.FeatureIsNotStandardized (l, "static classes");
}
}
+ protected override int AllowedModifiersProp {
+ get {
+ return Modifiers.NEW | Modifiers.PUBLIC | Modifiers.PROTECTED | Modifiers.INTERNAL | Modifiers.PRIVATE |
+ Modifiers.STATIC | Modifiers.UNSAFE;
+ }
+ }
+
protected override void DefineContainerMembers (MemberCoreArrayList list)
{
if (list == null)
continue;
}
- if ((m.ModFlags & Modifiers.STATIC) != 0)
+ if ((m.ModFlags & Modifiers.STATIC) != 0 || m is Enum || m is Delegate)
continue;
if (m is Constructor) {
public override TypeBuilder DefineType()
{
+ if ((ModFlags & (Modifiers.SEALED | Modifiers.STATIC)) == (Modifiers.SEALED | Modifiers.STATIC)) {
+ Report.Error (441, Location, "'{0}': a class cannot be both static and sealed", GetSignatureForError ());
+ return null;
+ }
+
TypeBuilder tb = base.DefineType ();
if (tb == null)
return null;
}
public class Class : ClassOrStruct {
- // <summary>
- // Modifiers allowed in a class declaration
- // </summary>
+ // TODO: remove this and use only AllowedModifiersProp to fix partial classes bugs
public const int AllowedModifiers =
Modifiers.NEW |
Modifiers.PUBLIC |
Attributes attrs, Location l)
: base (ns, parent, name, attrs, Kind.Class, l)
{
- int accmods;
-
- if (parent.Parent == null)
- accmods = Modifiers.INTERNAL;
- else
- accmods = Modifiers.PRIVATE;
-
- this.ModFlags = Modifiers.Check (AllowedModifiers, mod, accmods, l);
- if ((ModFlags & (Modifiers.ABSTRACT | Modifiers.SEALED)) == (Modifiers.ABSTRACT | Modifiers.SEALED)) {
- Report.Error (502, Location, "'{0}' cannot be both abstract and sealed", GetSignatureForError ());
- }
-
+ this.ModFlags = mod;
attribute_usage = new AttributeUsageAttribute (AttributeTargets.All);
}
- public override AttributeTargets AttributeTargets {
+ virtual protected int AllowedModifiersProp {
get {
- return AttributeTargets.Class;
+ return AllowedModifiers;
}
}
public const TypeAttributes DefaultTypeAttributes =
TypeAttributes.AutoLayout | TypeAttributes.Class;
+ public override TypeBuilder DefineType()
+ {
+ if ((ModFlags & Modifiers.ABSTRACT) == Modifiers.ABSTRACT && (ModFlags & (Modifiers.SEALED | Modifiers.STATIC)) != 0) {
+ Report.Error (418, Location, "'{0}': an abstract class cannot be sealed or static", GetSignatureForError ());
+ return null;
+ }
+
+ int accmods = Parent.Parent == null ? Modifiers.INTERNAL : Modifiers.PRIVATE;
+ ModFlags = Modifiers.Check (AllowedModifiersProp, ModFlags, accmods, Location);
+
+ return base.DefineType ();
+ }
+
//
// FIXME: How do we deal with the user specifying a different
// layout?
this.ModFlags |= Modifiers.SEALED;
}
- public override AttributeTargets AttributeTargets {
- get {
- return AttributeTargets.Struct;
- }
- }
-
public const TypeAttributes DefaultTypeAttributes =
TypeAttributes.SequentialLayout |
TypeAttributes.Sealed |
return null;
}
- public override AttributeTargets AttributeTargets {
- get {
- return AttributeTargets.Interface;
- }
- }
-
public const TypeAttributes DefaultTypeAttributes =
TypeAttributes.AutoLayout |
TypeAttributes.Abstract |
//
// The method we're overriding if this is an override method.
//
- protected MethodInfo parent_method = null;
+ protected MethodInfo base_method = null;
static string[] attribute_targets = new string [] { "method", "return" };
return true;
// Is null for System.Object while compiling corlib and base interfaces
- if (Parent.ParentCache == null) {
+ if (Parent.BaseCache == null) {
if ((RootContext.WarningLevel >= 4) && ((ModFlags & Modifiers.NEW) != 0)) {
Report.Warning (109, Location, "The member '{0}' does not hide an inherited member. The new keyword is not required", GetSignatureForError (Parent));
}
return true;
}
- Type parent_ret_type = null;
- parent_method = FindOutParentMethod (Parent, ref parent_ret_type);
+ Type base_ret_type = null;
+ base_method = FindOutBaseMethod (Parent, ref base_ret_type);
// method is override
- if (parent_method != null) {
+ if (base_method != null) {
if (!CheckMethodAgainstBase ())
return false;
if ((ModFlags & Modifiers.NEW) == 0) {
- if (!MemberType.Equals (TypeManager.TypeToCoreType (parent_ret_type))) {
- Report.SymbolRelatedToPreviousError (parent_method);
+ if (MemberType != TypeManager.TypeToCoreType (base_ret_type)) {
+ Report.SymbolRelatedToPreviousError (base_method);
Report.Error (508, Location, GetSignatureForError (Parent) + ": cannot " +
"change return type when overriding inherited member");
return false;
}
} else {
- if (parent_method.IsAbstract && !IsInterface) {
- Report.SymbolRelatedToPreviousError (parent_method);
+ if (base_method.IsAbstract && !IsInterface) {
+ Report.SymbolRelatedToPreviousError (base_method);
Report.Error (533, Location, "'{0}' hides inherited abstract member", GetSignatureForError (Parent));
return false;
}
}
- if (parent_method.IsSpecialName && !(this is PropertyBase)) {
- Report.Error (561, Location, "'{0}': cannot override '{1}' because it is a special compiler-generated method", GetSignatureForError (Parent), TypeManager.GetFullNameSignature (parent_method));
+ if (base_method.IsSpecialName && !(this is PropertyBase)) {
+ Report.Error (561, Location, "'{0}': cannot override '{1}' because it is a special compiler-generated method", GetSignatureForError (Parent), TypeManager.GetFullNameSignature (base_method));
return false;
}
Parent.Methods.HasGetHashCode = true;
}
- ObsoleteAttribute oa = AttributeTester.GetMethodObsoleteAttribute (parent_method);
- if (oa != null) {
- EmitContext ec = new EmitContext (this.Parent, this.Parent, Location, null, null, ModFlags, false);
- if (OptAttributes == null || !OptAttributes.Contains (TypeManager.obsolete_attribute_type, ec)) {
- Report.SymbolRelatedToPreviousError (parent_method);
- Report.Warning (672, 1, Location, "Member '{0}' overrides obsolete member. Add the Obsolete attribute to '{0}'", GetSignatureForError (Parent));
+ if ((ModFlags & Modifiers.OVERRIDE) != 0) {
+ ObsoleteAttribute oa = AttributeTester.GetMethodObsoleteAttribute (base_method);
+ if (oa != null) {
+ EmitContext ec = new EmitContext (this.Parent, this.Parent, Location, null, null, ModFlags, false);
+ if (OptAttributes == null || !OptAttributes.Contains (TypeManager.obsolete_attribute_type, ec)) {
+ Report.SymbolRelatedToPreviousError (base_method);
+ Report.Warning (672, 1, Location, "Member '{0}' overrides obsolete member. Add the Obsolete attribute to '{0}'", GetSignatureForError (Parent));
+ }
}
}
return true;
}
- MemberInfo conflict_symbol = Parent.FindMemberWithSameName (Name, !(this is Property));
+ MemberInfo conflict_symbol = Parent.FindBaseMemberWithSameName (Name, !(this is Property));
if ((ModFlags & Modifiers.OVERRIDE) != 0) {
if (conflict_symbol != null) {
Report.SymbolRelatedToPreviousError (conflict_symbol);
bool ok = true;
// TODO: replace with GetSignatureForError
- string name = parent_method.DeclaringType.Name + "." + parent_method.Name;
+ string name = base_method.DeclaringType.Name + "." + base_method.Name;
if ((ModFlags & Modifiers.OVERRIDE) != 0){
- if (!(parent_method.IsAbstract || parent_method.IsVirtual)){
+ if (!(base_method.IsAbstract || base_method.IsVirtual)){
Report.Error (
506, Location, Parent.MakeName (Name) +
": cannot override inherited member `" +
// Now we check that the overriden method is not final
- if (parent_method.IsFinal) {
+ if (base_method.IsFinal) {
// This happens when implementing interface methods.
- if (parent_method.IsHideBySig && parent_method.IsVirtual) {
+ if (base_method.IsHideBySig && base_method.IsVirtual) {
Report.Error (
506, Location, Parent.MakeName (Name) +
": cannot override inherited member `" +
// Check that the permissions are not being changed
//
MethodAttributes thisp = flags & MethodAttributes.MemberAccessMask;
- MethodAttributes parentp = parent_method.Attributes & MethodAttributes.MemberAccessMask;
+ MethodAttributes base_classp = base_method.Attributes & MethodAttributes.MemberAccessMask;
- if (!CheckAccessModifiers (thisp, parentp, parent_method)) {
- Error_CannotChangeAccessModifiers (Parent, parent_method, name);
+ if (!CheckAccessModifiers (thisp, base_classp, base_method)) {
+ Error_CannotChangeAccessModifiers (Parent, base_method, name);
ok = false;
}
}
if ((ModFlags & (Modifiers.NEW | Modifiers.OVERRIDE)) == 0 && Name != "Finalize") {
ModFlags |= Modifiers.NEW;
- Report.SymbolRelatedToPreviousError (parent_method);
- if (!IsInterface && (parent_method.IsVirtual || parent_method.IsAbstract)) {
+ Report.SymbolRelatedToPreviousError (base_method);
+ if (!IsInterface && (base_method.IsVirtual || base_method.IsAbstract)) {
if (RootContext.WarningLevel >= 2)
- Report.Warning (114, Location, "'{0}' hides inherited member '{1}'. To make the current member override that implementation, add the override keyword. Otherwise add the new keyword", GetSignatureForError (Parent), TypeManager.CSharpSignature (parent_method));
+ Report.Warning (114, Location, "'{0}' hides inherited member '{1}'. To make the current member override that implementation, add the override keyword. Otherwise add the new keyword", GetSignatureForError (Parent), TypeManager.CSharpSignature (base_method));
} else
Report.Warning (108, Location, "The keyword new is required on '{0}' because it hides inherited member", GetSignatureForError (Parent));
}
return ok;
}
- protected bool CheckAccessModifiers (MethodAttributes thisp, MethodAttributes parentp, MethodInfo base_method)
+ protected bool CheckAccessModifiers (MethodAttributes thisp, MethodAttributes base_classp, MethodInfo base_method)
{
- if ((parentp & MethodAttributes.FamORAssem) == MethodAttributes.FamORAssem){
+ if ((base_classp & MethodAttributes.FamORAssem) == MethodAttributes.FamORAssem){
//
// when overriding protected internal, the method can be declared
// protected internal only within the same assembly
//
return false;
- } else if (thisp != parentp) {
+ } else if (thisp != base_classp) {
//
// same assembly, but other attributes differ - report an error
//
//
return false;
} else if ((thisp & ~(MethodAttributes.Family | MethodAttributes.FamORAssem)) !=
- (parentp & ~(MethodAttributes.Family | MethodAttributes.FamORAssem))) {
+ (base_classp & ~(MethodAttributes.Family | MethodAttributes.FamORAssem))) {
//
// protected ok, but other attributes differ - report an error
//
}
return true;
} else {
- return (thisp == parentp);
+ return (thisp == base_classp);
}
}
- void Error_CannotChangeAccessModifiers (TypeContainer parent, MethodInfo parent_method, string name)
+ void Error_CannotChangeAccessModifiers (TypeContainer parent, MethodInfo base_method, string name)
{
//
// FIXME: report the old/new permissions?
protected abstract bool CheckForDuplications ();
/// <summary>
- /// Gets parent method and its return type
+ /// Gets base method and its return type
/// </summary>
- protected abstract MethodInfo FindOutParentMethod (TypeContainer container, ref Type parent_ret_type);
+ protected abstract MethodInfo FindOutBaseMethod (TypeContainer container, ref Type base_ret_type);
protected virtual bool DoDefineParameters ()
{
}
if (!AttributeTester.IsClsCompliant (MemberType)) {
- if ((this is Property) || (this is Indexer))
+ if (this is PropertyBase)
Report.Error (3003, Location, "Type of `{0}' is not CLS-compliant",
GetSignatureForError ());
else
flags |= MethodAttributes.SpecialName | MethodAttributes.HideBySig;
MethodData = new MethodData (this, ParameterInfo, ModFlags, flags,
- this, mb, GenericMethod, parent_method);
+ this, mb, GenericMethod, base_method);
if (!MethodData.Define (Parent))
return false;
MethodData = null;
}
- protected override MethodInfo FindOutParentMethod (TypeContainer container, ref Type parent_ret_type)
+ protected override MethodInfo FindOutBaseMethod (TypeContainer container, ref Type base_ret_type)
{
- MethodInfo mi = (MethodInfo) container.ParentCache.FindMemberToOverride (
+ MethodInfo mi = (MethodInfo) container.BaseCache.FindMemberToOverride (
container.TypeBuilder, Name, ParameterTypes, false);
if (mi == null)
return null;
- parent_ret_type = mi.ReturnType;
+ base_ret_type = mi.ReturnType;
return mi;
}
+ public override bool MarkForDuplicationCheck ()
+ {
+ caching_flags |= Flags.TestMethodDuplication;
+ return true;
+ }
+
protected override bool VerifyClsCompliance(DeclSpace ds)
{
if (!base.VerifyClsCompliance (ds))
caching_flags &= ~Flags.Excluded_Undetected;
- if (parent_method == null) {
+ if (base_method == null) {
if (OptAttributes == null)
return false;
return false;
foreach (Attribute a in attrs) {
- string condition = a.GetConditionalAttributeValue (ds);
+ string condition = a.GetConditionalAttributeValue (Parent.EmitContext);
if (RootContext.AllDefines.Contains (condition))
return false;
}
return true;
}
- IMethodData md = TypeManager.GetMethod (parent_method);
+ IMethodData md = TypeManager.GetMethod (base_method);
if (md == null) {
- if (AttributeTester.IsConditionalMethodExcluded (parent_method)) {
+ if (AttributeTester.IsConditionalMethodExcluded (base_method)) {
caching_flags |= Flags.Excluded;
return true;
}
public abstract class ConstructorInitializer {
ArrayList argument_list;
- protected ConstructorInfo parent_constructor;
+ protected ConstructorInfo base_constructor;
Parameters parameters;
Location loc;
public bool Resolve (ConstructorBuilder caller_builder, EmitContext ec)
{
- Expression parent_constructor_group;
+ Expression base_constructor_group;
Type t;
ec.CurrentBlock = new ToplevelBlock (Block.Flags.Implicit, parameters, loc);
} else
t = ec.ContainerType;
- parent_constructor_group = Expression.MemberLookup (
+ base_constructor_group = Expression.MemberLookup (
ec, t, ".ctor", MemberTypes.Constructor,
BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly,
loc);
- if (parent_constructor_group == null){
- parent_constructor_group = Expression.MemberLookup (
+ if (base_constructor_group == null){
+ base_constructor_group = Expression.MemberLookup (
ec, t, ".ctor", MemberTypes.Constructor,
BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly,
loc);
- if (parent_constructor_group != null)
+ if (base_constructor_group != null)
Report.Error (
112, loc, "`{0}.{1}' is inaccessible due to " +
"its protection level", t.FullName, t.Name);
return false;
}
- parent_constructor = (ConstructorInfo) Invocation.OverloadResolve (
- ec, (MethodGroupExpr) parent_constructor_group, argument_list,
+ base_constructor = (ConstructorInfo) Invocation.OverloadResolve (
+ ec, (MethodGroupExpr) base_constructor_group, argument_list,
false, loc);
- if (parent_constructor == null){
+ if (base_constructor == null){
Report.Error (1501, loc,
"Can not find a constructor for this argument list");
return false;
}
- if (parent_constructor == caller_builder){
+ if (base_constructor == caller_builder){
Report.Error (516, String.Format ("Constructor `{0}' can not call itself", TypeManager.CSharpSignature (caller_builder)));
return false;
}
public void Emit (EmitContext ec)
{
- if (parent_constructor != null){
+ if (base_constructor != null){
ec.Mark (loc, false);
if (ec.IsStatic)
- Invocation.EmitCall (ec, true, true, null, parent_constructor, argument_list, loc);
+ Invocation.EmitCall (ec, true, true, null, base_constructor, argument_list, loc);
else
- Invocation.EmitCall (ec, true, false, ec.GetThis (loc), parent_constructor, argument_list, loc);
+ Invocation.EmitCall (ec, true, false, ec.GetThis (loc), base_constructor, argument_list, loc);
}
}
}
public override void CheckObsoleteAttribute(TypeContainer tc, Location loc) {
- if (parent_constructor == null)
+ if (base_constructor == null)
return;
TypeContainer type_ds = TypeManager.LookupTypeContainer (tc.TypeBuilder.BaseType);
if (type_ds == null) {
- ObsoleteAttribute oa = AttributeTester.GetMemberObsoleteAttribute (parent_constructor);
+ ObsoleteAttribute oa = AttributeTester.GetMemberObsoleteAttribute (base_constructor);
if (oa != null)
- AttributeTester.Report_ObsoleteMessage (oa, TypeManager.CSharpSignature (parent_constructor), loc);
+ AttributeTester.Report_ObsoleteMessage (oa, TypeManager.CSharpSignature (base_constructor), loc);
return;
}
}
// Is never override
- protected override MethodInfo FindOutParentMethod (TypeContainer container, ref Type parent_ret_type)
+ protected override MethodInfo FindOutBaseMethod (TypeContainer container, ref Type base_ret_type)
{
return null;
}
if (member.InterfaceType != null){
if (implementing == null){
Report.Error (539, method.Location,
- "'{0}' in explicit interface declaration is not an interface", method_name);
+ "'{0}' in explicit interface declaration is not a member of interface", member.GetSignatureForError () );
return false;
}
}
if (member is MethodCore)
((MethodCore) member).Parameters.LabelParameters (ec, MethodBuilder, loc);
- SymbolWriter sw = CodeGen.SymbolWriter;
ToplevelBlock block = method.Block;
//
"Finalize", MemberTypes.Method, Expression.AllBindingFlags, method.Location);
if (member_lookup != null){
- MethodGroupExpr parent_destructor = ((MethodGroupExpr) member_lookup);
+ MethodGroupExpr base_destructor = ((MethodGroupExpr) member_lookup);
ig.Emit (OpCodes.Ldarg_0);
- ig.Emit (OpCodes.Call, (MethodInfo) parent_destructor.Methods [0]);
+ ig.Emit (OpCodes.Call, (MethodInfo) base_destructor.Methods [0]);
}
}
MethodAttributes.NewSlot |
MethodAttributes.Virtual;
} else {
- if (!Parent.MethodModifiersValid (ModFlags, Name, Location))
+ if (!Parent.MethodModifiersValid (this))
return false;
flags = Modifiers.MethodAttr (ModFlags);
// verify accessibility
if (!Parent.AsAccessible (MemberType, ModFlags)) {
+ Report.SymbolRelatedToPreviousError (MemberType);
if (this is Property)
Report.Error (53, Location,
"Inconsistent accessibility: property type `" +
TypeManager.CSharpName (MemberType) + "' is less " +
- "accessible than property `" + Name + "'");
+ "accessible than property `" + GetSignatureForError () + "'");
else if (this is Indexer)
Report.Error (54, Location,
"Inconsistent accessibility: indexer return type `" +
static string[] attribute_targets = new string [] { "field" };
/// <summary>
- /// Symbol with same name in parent class/struct
+ /// Symbol with same name in base class/struct
/// </summary>
public MemberInfo conflict_symbol;
if (IsInterface)
return true;
- conflict_symbol = Parent.FindMemberWithSameName (Name, false);
+ conflict_symbol = Parent.FindBaseMemberWithSameName (Name, false);
if (conflict_symbol == null) {
if ((RootContext.WarningLevel >= 4) && ((ModFlags & Modifiers.NEW) != 0)) {
Report.Warning (109, Location, "The member '{0}' does not hide an inherited member. The new keyword is not required", GetSignatureForError (Parent));
MemberType = texpr.Type;
+ if (MemberType == TypeManager.void_type) {
+ Report.Error (1547, Location, "Keyword 'void' cannot be used in this context");
+ return false;
+ }
+
+ ec.InUnsafe = old_unsafe;
+
if (!CheckBase ())
return false;
parameters = new Parameters (parms, null, method.Location);
}
+ bool old_unsafe = ec.InUnsafe;
+ ec.InUnsafe = InUnsafe;
Type [] types = parameters.GetParameterInfo (ec);
+ ec.InUnsafe = old_unsafe;
return new InternalParameters (types, parameters);
}
- public override MethodBuilder Define(TypeContainer container)
+ public override MethodBuilder Define (TypeContainer container)
{
if (container.EmitContext == null)
throw new InternalErrorException ("SetMethod.Define called too early");
: base (method, prefix)
{
this.method = method;
+ Parent = method.Parent;
}
public PropertyMethod (MethodCore method, Accessor accessor, string prefix)
: base (method, accessor, prefix)
{
this.method = method;
+ Parent = method.Parent;
this.ModFlags = accessor.ModFlags;
if (accessor.ModFlags != 0 && RootContext.Version == LanguageVersion.ISO_1) {
//
// Check for custom access modifier
//
- if (ModFlags == 0) {
- ModFlags = method.ModFlags;
- flags = method.flags;
- } else {
+ if (ModFlags == 0) {
+ ModFlags = method.ModFlags;
+ flags = method.flags;
+ } else {
CheckModifiers (container, ModFlags);
ModFlags |= (method.ModFlags & (~Modifiers.Accessibility));
flags = Modifiers.MethodAttr (ModFlags);
}
void CheckModifiers (TypeContainer container, int modflags)
- {
- int flags = 0;
- int mflags = method.ModFlags & Modifiers.Accessibility;
+ {
+ int flags = 0;
+ int mflags = method.ModFlags & Modifiers.Accessibility;
- if ((mflags & Modifiers.PUBLIC) != 0) {
- flags |= Modifiers.PROTECTED | Modifiers.INTERNAL | Modifiers.PRIVATE;
- }
- else if ((mflags & Modifiers.PROTECTED) != 0) {
- if ((mflags & Modifiers.INTERNAL) != 0)
- flags |= Modifiers.PROTECTED | Modifiers.INTERNAL;
+ if ((mflags & Modifiers.PUBLIC) != 0) {
+ flags |= Modifiers.PROTECTED | Modifiers.INTERNAL | Modifiers.PRIVATE;
+ }
+ else if ((mflags & Modifiers.PROTECTED) != 0) {
+ if ((mflags & Modifiers.INTERNAL) != 0)
+ flags |= Modifiers.PROTECTED | Modifiers.INTERNAL;
- flags |= Modifiers.PRIVATE;
- }
- else if ((mflags & Modifiers.INTERNAL) != 0)
- flags |= Modifiers.PRIVATE;
+ flags |= Modifiers.PRIVATE;
+ }
+ else if ((mflags & Modifiers.INTERNAL) != 0)
+ flags |= Modifiers.PRIVATE;
- if ((mflags == modflags) || (modflags & (~flags)) != 0)
- Report.Error (273, Location, "{0}: accessibility modifier must be more restrictive than the property or indexer",
- GetSignatureForError (container));
- }
+ if ((mflags == modflags) || (modflags & (~flags)) != 0)
+ Report.Error (273, Location, "{0}: accessibility modifier must be more restrictive than the property or indexer",
+ GetSignatureForError (container));
+ }
+
+ public override bool MarkForDuplicationCheck ()
+ {
+ caching_flags |= Flags.TestMethodDuplication;
+ return true;
+ }
}
public PropertyMethod Get, Set;
//
// Accessors modifiers check
//
-
if (Get.ModFlags != 0 && Set.ModFlags != 0) {
Report.Error (274, Location, "'{0}': cannot specify accessibility modifiers for both accessors of the property or indexer.",
GetSignatureForError ());
return TypeManager.CSharpSignature (PropertyBuilder, false);
}
-
protected override bool CheckForDuplications ()
{
ArrayList ar = Parent.Indexers;
}
// TODO: rename to Resolve......
- protected override MethodInfo FindOutParentMethod (TypeContainer container, ref Type parent_ret_type)
+ protected override MethodInfo FindOutBaseMethod (TypeContainer container, ref Type base_ret_type)
{
- PropertyInfo parent_property = container.ParentCache.FindMemberToOverride (
+ PropertyInfo base_property = container.BaseCache.FindMemberToOverride (
container.TypeBuilder, Name, ParameterTypes, true) as PropertyInfo;
- if (parent_property == null)
+ if (base_property == null)
return null;
- parent_ret_type = parent_property.PropertyType;
- MethodInfo get_accessor = parent_property.GetGetMethod (true);
- MethodInfo set_accessor = parent_property.GetSetMethod (true);
+ base_ret_type = base_property.PropertyType;
+ MethodInfo get_accessor = base_property.GetGetMethod (true);
+ MethodInfo set_accessor = base_property.GetSetMethod (true);
MethodAttributes get_accessor_access, set_accessor_access;
if ((ModFlags & Modifiers.OVERRIDE) != 0) {
if (Get != null && !Get.IsDummy && get_accessor == null) {
- Report.SymbolRelatedToPreviousError (parent_property);
- Report.Error (545, Location, "'{0}': cannot override because '{1}' does not have an overridable get accessor", GetSignatureForError (), TypeManager.GetFullNameSignature (parent_property));
+ Report.SymbolRelatedToPreviousError (base_property);
+ Report.Error (545, Location, "'{0}': cannot override because '{1}' does not have an overridable get accessor", GetSignatureForError (), TypeManager.GetFullNameSignature (base_property));
}
if (Set != null && !Set.IsDummy && set_accessor == null) {
- Report.SymbolRelatedToPreviousError (parent_property);
- Report.Error (546, Location, "'{0}': cannot override because '{1}' does not have an overridable set accessor", GetSignatureForError (), TypeManager.GetFullNameSignature (parent_property));
+ Report.SymbolRelatedToPreviousError (base_property);
+ Report.Error (546, Location, "'{0}': cannot override because '{1}' does not have an overridable set accessor", GetSignatureForError (), TypeManager.GetFullNameSignature (base_property));
}
}
//
- // Check parent accessors access
+ // Check base class accessors access
//
get_accessor_access = set_accessor_access = 0;
if ((ModFlags & Modifiers.NEW) == 0) {
if (!Get.IsDummy && !CheckAccessModifiers (get_flags & MethodAttributes.MemberAccessMask, get_accessor_access, get_accessor))
Report.Error (507, Location, "'{0}' can't change the access modifiers when overriding inherited member '{1}'",
- GetSignatureForError (), TypeManager.GetFullNameSignature (parent_property));
+ GetSignatureForError (), TypeManager.GetFullNameSignature (base_property));
}
if (set_accessor != null) {
if (!Set.IsDummy && !CheckAccessModifiers (set_flags & MethodAttributes.MemberAccessMask, set_accessor_access, set_accessor))
Report.Error (507, Location, "'{0}' can't change the access modifiers when overriding inherited member '{1}'",
- GetSignatureForError (container), TypeManager.GetFullNameSignature (parent_property));
+ GetSignatureForError (container), TypeManager.GetFullNameSignature (base_property));
}
}
Set.UpdateName (this);
}
+ protected override bool VerifyClsCompliance (DeclSpace ds)
+ {
+ if (!base.VerifyClsCompliance (ds))
+ return false;
+
+ if ((Get.ModFlags != ModFlags && !Get.IsDummy) || (Set.ModFlags != ModFlags && !Set.IsDummy)) {
+ Report.Error (3025, Get.ModFlags != ModFlags ? Get.Location : Set.Location,
+ "CLS-compliant accessors must have the same accessibility as their property");
+ }
+ return true;
+ }
public override string[] ValidAttributeTargets {
get {
}
ILGenerator ig = method_data.MethodBuilder.GetILGenerator ();
- EmitContext ec = CreateEmitContext (tc, ig);
FieldInfo field_info = (FieldInfo)method.FieldBuilder;
method_data.MethodBuilder.SetImplementationFlags (MethodImplAttributes.Synchronized);
if (!base.Define ())
return false;
+ if (MemberType == TypeManager.void_type) {
+ Report.Error (620, Location, "Indexers cannot have void type");
+ return false;
+ }
+
if (OptAttributes != null) {
Attribute indexer_attr = OptAttributes.Search (TypeManager.indexer_name_type, ec);
if (indexer_attr != null) {
}
if (InterfaceType != null) {
- string parent_IndexerName = TypeManager.IndexerPropertyName (InterfaceType);
- if (parent_IndexerName != Name)
- ShortName = parent_IndexerName;
+ string base_IndexerName = TypeManager.IndexerPropertyName (InterfaceType);
+ if (base_IndexerName != Name)
+ ShortName = base_IndexerName;
UpdateMemberName ();
}
- if (!Parent.AddToMemberContainer (this, true) ||
- !Parent.AddToMemberContainer (Get, true) || !Parent.AddToMemberContainer (Set, true))
+ if (!Parent.AddToMemberContainer (this) ||
+ !Parent.AddToMemberContainer (Get) || !Parent.AddToMemberContainer (Set))
return false;
if (!CheckBase ())
{
return String.Concat (tc.Name, ".this[", Parameters.FixedParameters [0].TypeName.ToString (), ']');
}
+
+ public override bool MarkForDuplicationCheck ()
+ {
+ caching_flags |= Flags.TestMethodDuplication;
+ return true;
+ }
+
}
public class Operator : MethodCore, IIteratorContainer {
if (!DoDefine (ds))
return false;
+ if (MemberType == TypeManager.void_type) {
+ Report.Error (590, Location, "User-defined operators cannot return void");
+ return false;
+ }
+
OperatorMethod = new Method (
Parent, null, Type, ModFlags, false, MemberName,
Parameters, OptAttributes, Location);
}
// Operator cannot be override
- protected override MethodInfo FindOutParentMethod (TypeContainer container, ref Type parent_ret_type)
+ protected override MethodInfo FindOutBaseMethod (TypeContainer container, ref Type base_ret_type)
{
return null;
}
return ToString ();
}
+ public override bool MarkForDuplicationCheck ()
+ {
+ caching_flags |= Flags.TestMethodDuplication;
+ return true;
+ }
+
public override string ToString ()
{
if (OperatorMethod == null)
DeclSpace = ds;
CheckState = RootContext.Checked;
ConstantCheckState = true;
+
+ if ((return_type is TypeBuilder) && return_type.IsGenericTypeDefinition)
+ throw new Exception ("FUCK");
IsStatic = (code_flags & Modifiers.STATIC) != 0;
InIterator = (code_flags & Modifiers.METHOD_YIELDS) != 0;
ReturnLabel = ig.DefineLabel ();
}
- public void EmitTopBlock (ToplevelBlock block, InternalParameters ip, Location loc)
- {
- EmitTopBlock (block, ip, loc, "");
- }
-
//
// Here until we can fix the problem with Mono.CSharp.Switch, which
// currently can not cope with ig == null during resolve (which must
// be fixed for switch statements to work on anonymous methods).
//
- public void EmitTopBlock (ToplevelBlock block, InternalParameters ip, Location loc, string methodName)
+ public void EmitTopBlock (ToplevelBlock block, InternalParameters ip, Location loc)
{
if (block == null)
return;
if (OptAttributes == null)
return null;
+ // Ensure that we only have GlobalAttributes, since the Search below isn't safe with other types.
+ if (!OptAttributes.CheckTargets (this))
+ return null;
+
EmitContext temp_ec = new EmitContext (RootContext.Tree.Types, Mono.CSharp.Location.Null, null, null, 0, false);
Attribute a = OptAttributes.Search (TypeManager.cls_compliant_attribute_type, temp_ec);
if (a != null) {
public AssemblyBuilder Builder;
bool is_cls_compliant;
+ public Attribute ClsCompliantAttribute;
ListDictionary declarative_security;
public void ResolveClsCompliance ()
{
- Attribute a = GetClsCompliantAttribute ();
- if (a == null)
+ ClsCompliantAttribute = GetClsCompliantAttribute ();
+ if (ClsCompliantAttribute == null)
return;
- is_cls_compliant = a.GetClsCompliantAttributeValue (null);
+ is_cls_compliant = ClsCompliantAttribute.GetClsCompliantAttributeValue (null);
}
// fix bug #56621
return;
}
- ApplyAttributeBuilder (null, new CustomAttributeBuilder (TypeManager.unverifiable_code_ctor, new object [0]));
+ Builder.SetCustomAttribute (new CustomAttributeBuilder (TypeManager.unverifiable_code_ctor, new object [0]));
}
public override void ApplyAttributeBuilder (Attribute a, CustomAttributeBuilder customBuilder)
{
- if (a != null && a.Type == TypeManager.cls_compliant_attribute_type) {
- Report.Warning (3012, a.Location, "You must specify the CLSCompliant attribute on the assembly, not the module, to enable CLS compliance checking");
+ if (a.Type == TypeManager.cls_compliant_attribute_type) {
+ if (CodeGen.Assembly.ClsCompliantAttribute == null) {
+ Report.Warning (3012, a.Location, "You must specify the CLSCompliant attribute on the assembly, not the module, to enable CLS compliance checking");
+ }
+ else if (CodeGen.Assembly.IsClsCompliant != a.GetBoolean ()) {
+ Report.SymbolRelatedToPreviousError (CodeGen.Assembly.ClsCompliantAttribute.Location, CodeGen.Assembly.ClsCompliantAttribute.Name);
+ Report.Error (3017, a.Location, "You cannot specify the CLSCompliant attribute on a module that differs from the CLSCompliant attribute on the assembly");
+ return;
+ }
}
Builder.SetCustomAttribute (customBuilder);
if (expr_type.Equals (target_type))
return true;
+
// First numeric conversions
if (expr_type == TypeManager.sbyte_type){
return true;
}
+ if (expr.eclass == ExprClass.MethodGroup){
+ if (TypeManager.IsDelegateType (target_type) && RootContext.Version != LanguageVersion.ISO_1){
+ MethodGroupExpr mg = expr as MethodGroupExpr;
+ if (mg != null){
+ //
+ // This should not happen frequently, so we can create an object
+ // to test compatibility
+ //
+ Expression c = ImplicitDelegateCreation.Create (ec, mg, target_type, Location.Null);
+ return c != null;
+ }
+ }
+ }
+
if (ImplicitReferenceConversionExists (ec, expr, target_type))
return true;
return true;
}
+ //
+ // If `expr_type' implements `target_type' (which is an iface)
+ // see TryImplicitIntConversion
+ //
+ if (target_type.IsInterface && target_type.IsAssignableFrom (expr_type))
+ return true;
+
if (target_type == TypeManager.void_ptr_type && expr_type.IsPointer)
return true;
return false;
AnonymousMethod am = (AnonymousMethod) expr;
- int errors = Report.Errors;
Expression conv = am.Compatible (ec, target_type, true);
if (conv != null)
return true;
}
-
+
return false;
}
}
/// <summary>
- /// Attemps to perform an implict constant conversion of the IntConstant
+ /// Attempts to perform an implicit constant conversion of the IntConstant
/// into a different data type using casts (See Implicit Constant
/// Expression Conversions)
/// </summary>
return new EnumConstant (e, target_type);
}
+
+ //
+ // If `target_type' is an interface and the type of `ic' implements the interface
+ // e.g. target_type is IComparable, IConvertible, IFormattable
+ //
+ if (target_type.IsInterface && target_type.IsAssignableFrom (ic.Type))
+ return new BoxedCast (ic);
+
return null;
}
}
/// <summary>
- /// Attemptes to implicityly convert `target' into `type', using
+ /// Attempts to implicitly convert `source' into `target_type', using
/// ImplicitConversion. If there is no implicit conversion, then
/// an error is signaled
/// </summary>
public string GetTypeName ()
{
- string suffix = "";
if (Left != null)
return Left.GetTypeName () + "." +
MakeName (Name, TypeArguments);
/// </summary>
public int ModFlags;
- public readonly TypeContainer Parent;
+ public /*readonly*/ TypeContainer Parent;
/// <summary>
/// Location where this declaration happens
if (obsolete_attr == null)
return null;
- ObsoleteAttribute obsolete = obsolete_attr.GetObsoleteAttribute (ds);
+ ObsoleteAttribute obsolete = obsolete_attr.GetObsoleteAttribute (ds.EmitContext);
if (obsolete == null)
return null;
TypeManager.cls_compliant_attribute_type, ds.EmitContext);
if (cls_attribute != null) {
caching_flags |= Flags.HasClsCompliantAttribute;
- return cls_attribute.GetClsCompliantAttributeValue (ds);
+ return cls_attribute.GetClsCompliantAttributeValue (ds.EmitContext);
}
}
return ds.GetClsCompliantAttributeValue ();
}
}
+ /// <summary>
+ /// It helps to handle error 102 & 111 detection
+ /// </summary>
+ public virtual bool MarkForDuplicationCheck ()
+ {
+ return false;
+ }
+
/// <summary>
/// The main virtual method for CLS-Compliant verifications.
/// The method returns true if member is CLS-Compliant and false if member is not
protected virtual bool VerifyClsCompliance (DeclSpace ds)
{
if (!IsClsCompliaceRequired (ds)) {
- if ((RootContext.WarningLevel >= 2) && HasClsCompliantAttribute && !IsExposedFromAssembly (ds)) {
- Report.Warning (3019, Location, "CLS compliance checking will not be performed on '{0}' because it is private or internal", GetSignatureForError ());
+ if (HasClsCompliantAttribute && RootContext.WarningLevel >= 2) {
+ if (!IsExposedFromAssembly (ds))
+ Report.Warning (3019, Location, "CLS compliance checking will not be performed on '{0}' because it is private or internal", GetSignatureForError ());
+ if (!CodeGen.Assembly.IsClsCompliant)
+ Report.Warning (3021, Location, "'{0}' does not need a CLSCompliant attribute because the assembly does not have a CLSCompliant attribute", GetSignatureForError ());
}
return false;
}
//
public NamespaceEntry NamespaceEntry;
- public Hashtable Cache = new Hashtable ();
+ private Hashtable Cache = new Hashtable ();
public string Basename;
/// <summary>
/// Adds the member to defined_names table. It tests for duplications and enclosing name conflicts
/// </summary>
- protected bool AddToContainer (MemberCore symbol, bool is_method, string fullname, string basename)
+ protected bool AddToContainer (MemberCore symbol, string fullname, string basename)
{
if (basename == Basename && !(this is Interface)) {
if (symbol is TypeParameter)
MemberCore mc = (MemberCore)defined_names [fullname];
- if (is_method && (mc is MethodCore || mc is IMethodData)) {
- symbol.caching_flags |= Flags.TestMethodDuplication;
- mc.caching_flags |= Flags.TestMethodDuplication;
+ if (mc == null) {
+ defined_names.Add (fullname, symbol);
return true;
}
- if (mc != null) {
- if (symbol is TypeParameter)
- Report.Error (692, symbol.Location, "Duplicate type parameter `{0}'", basename);
- else {
- Report.SymbolRelatedToPreviousError (mc);
- Report.Error (102, symbol.Location,
- "The type '{0}' already contains a definition for '{1}'",
- GetSignatureForError (), basename);
- }
- return false;
- }
+ if (symbol.MarkForDuplicationCheck () && mc.MarkForDuplicationCheck ())
+ return true;
- defined_names.Add (fullname, symbol);
- return true;
+ if (symbol is TypeParameter)
+ Report.Error (692, symbol.Location, "Duplicate type parameter `{0}'", basename);
+ else {
+ Report.SymbolRelatedToPreviousError (mc);
+ Report.Error (102, symbol.Location,
+ "The type '{0}' already contains a definition for '{1}'",
+ GetSignatureForError (), basename);
+ }
+ return false;
}
public void RecordDecl ()
in_transit = value;
}
}
-
- /// <summary>
- /// Looks up the alias for the name
- /// </summary>
- public IAlias LookupAlias (string name)
- {
- if (NamespaceEntry != null)
- return NamespaceEntry.LookupAlias (name);
- else
- return null;
- }
//
// root_types contains all the types. All TopLevel types
}
EmitContext type_resolve_ec;
- EmitContext GetTypeResolveEmitContext (TypeContainer parent, Location loc)
- {
- type_resolve_ec = new EmitContext (parent, this, loc, null, null, ModFlags, false);
- type_resolve_ec.ResolvingTypeTree = true;
- return type_resolve_ec;
- }
-
- public Type ResolveNestedType (Type t, Location loc)
+ public FullNamedExpression ResolveNestedType (FullNamedExpression t, Location loc)
{
- TypeContainer tc = TypeManager.LookupTypeContainer (t);
+ TypeContainer tc = TypeManager.LookupTypeContainer (t.Type);
if ((tc != null) && tc.IsGeneric) {
if (!IsGeneric) {
- int tnum = TypeManager.GetNumberOfTypeArguments (t);
+ int tnum = TypeManager.GetNumberOfTypeArguments (t.Type);
Report.Error (305, loc,
"Using the generic type `{0}' " +
"requires {1} type arguments",
- TypeManager.GetFullName (t), tnum);
+ TypeManager.GetFullName (t.Type), tnum);
return null;
}
else
args = TypeParameters;
- TypeExpr ctype = new ConstructedType (t, args, loc);
- ctype = ctype.ResolveAsTypeTerminal (ec);
- if (ctype == null)
- return null;
-
- t = ctype.Type;
+ TypeExpr ctype = new ConstructedType (t.Type, args, loc);
+ return ctype.ResolveAsTypeTerminal (ec);
}
return t;
// Resolves the expression `e' for a type, and will recursively define
// types. This should only be used for resolving base types.
// </summary>
- public TypeExpr ResolveTypeExpr (Expression e, Location loc)
+ public TypeExpr ResolveBaseTypeExpr (Expression e, bool silent, Location loc)
{
- if (type_resolve_ec == null)
- type_resolve_ec = GetTypeResolveEmitContext (Parent, loc);
+ if (type_resolve_ec == null) {
+ // FIXME: I think this should really be one of:
+ //
+ // a. type_resolve_ec = Parent.EmitContext;
+ // b. type_resolve_ec = new EmitContext (Parent, Parent, loc, null, null, ModFlags, false);
+ //
+ // However, if Parent == RootContext.Tree.Types, its NamespaceEntry will be null.
+ //
+ type_resolve_ec = new EmitContext (Parent, this, loc, null, null, ModFlags, false);
+ type_resolve_ec.ResolvingTypeTree = true;
+ }
type_resolve_ec.loc = loc;
if (this is GenericMethod)
type_resolve_ec.ContainerType = Parent.TypeBuilder;
return tc.DefineType ();
}
- Type LookupInterfaceOrClass (string ns, string name, out bool error)
+ FullNamedExpression LookupInterfaceOrClass (string ns, string name, out bool error)
{
DeclSpace parent;
+ FullNamedExpression result;
Type t;
object r;
error = false;
if (dh.Lookup (ns, name, out r))
- return (Type) r;
+ return (FullNamedExpression) r;
else {
if (ns != ""){
if (Namespace.IsNamespace (ns)){
}
if (t != null) {
- dh.Insert (ns, name, t);
- return t;
+ result = new TypeExpression (t, Location.Null);
+ dh.Insert (ns, name, result);
+ return result;
+ }
+
+ if (ns != "" && Namespace.IsNamespace (ns)) {
+ result = Namespace.LookupNamespace (ns, false).Lookup (this, name, Location.Null);
+ if (result != null) {
+ dh.Insert (ns, name, result);
+ return result;
+ }
+ }
+
+ if (ns == "" && Namespace.IsNamespace (name)) {
+ result = Namespace.LookupNamespace (name, false);
+ dh.Insert (ns, name, result);
+ return result;
}
//
ns = MakeFQN (ns, name.Substring (0, p));
name = name.Substring (p+1);
}
-
+
+ if (ns.IndexOf ('+') != -1)
+ ns = ns.Replace ('+', '.');
+
parent = RootContext.Tree.LookupByNamespace (ns, name);
if (parent == null) {
dh.Insert (ns, name, null);
return null;
}
- dh.Insert (ns, name, t);
- return t;
+ result = new TypeExpression (t, Location.Null);
+ dh.Insert (ns, name, result);
+ return result;
}
public static void Error_AmbiguousTypeReference (Location loc, string name, string t1, string t2)
public Type FindNestedType (Location loc, string name,
out DeclSpace containing_ds)
{
- Type t;
+ FullNamedExpression t;
bool error;
containing_ds = this;
if (error)
return null;
- if ((t != null) && containing_ds.CheckAccessLevel (t))
- return t;
+ if ((t != null) && containing_ds.CheckAccessLevel (t.Type))
+ return t.Type;
current_type = current_type.BaseType;
}
/// during the tree resolution process and potentially define
/// recursively the type
/// </remarks>
- public Type FindType (Location loc, string name)
+ public FullNamedExpression FindType (Location loc, string name)
{
- Type t;
+ FullNamedExpression t;
bool error;
//
// For the case the type we are looking for is nested within this one
// or is in any base class
//
+
DeclSpace containing_ds = this;
while (containing_ds != null){
if (error)
return null;
- if ((t != null) && containing_ds.CheckAccessLevel (t))
+ if ((t != null) && containing_ds.CheckAccessLevel (t.Type))
return ResolveNestedType (t, loc);
current_type = current_type.BaseType;
if (name.IndexOf ('.') > 0)
continue;
- IAlias alias_value = ns.LookupAlias (name);
- if (alias_value != null) {
- t = LookupInterfaceOrClass ("", alias_value.Name, out error);
- if (error)
- return null;
-
- if (t != null)
- return t;
- }
+ t = ns.LookupAlias (name);
+ if (t != null)
+ return t;
//
// Now check the using clause list
//
- Type match = null;
+ FullNamedExpression match = null;
foreach (Namespace using_ns in ns.GetUsingTable ()) {
match = LookupInterfaceOrClass (using_ns.Name, name, out error);
if (error)
return null;
- if (match != null) {
- if (t != null){
- if (CheckAccessLevel (match)) {
- Error_AmbiguousTypeReference (loc, name, t.FullName, match.FullName);
- return null;
- }
+ if ((match != null) && (match is TypeExpr)) {
+ Type matched = ((TypeExpr) match).Type;
+ if (!CheckAccessLevel (matched))
continue;
+ if (t != null){
+ Error_AmbiguousTypeReference (loc, name, t.FullName, match.FullName);
+ return null;
}
-
t = match;
}
}
return null;
}
+ //
+ // Public function used to locate types, this can only
+ // be used after the ResolveTree function has been invoked.
+ //
+ // Returns: Type or null if they type can not be found.
+ //
+ // Come to think of it, this should be a DeclSpace
+ //
+ public FullNamedExpression LookupType (string name, bool silent, Location loc)
+ {
+ FullNamedExpression e;
+
+ if (Cache.Contains (name)) {
+ e = (FullNamedExpression) Cache [name];
+ } else {
+ //
+ // For the case the type we are looking for is nested within this one
+ // or is in any base class
+ //
+ DeclSpace containing_ds = this;
+ while (containing_ds != null){
+
+ // if the member cache has been created, lets use it.
+ // the member cache is MUCH faster.
+ if (containing_ds.MemberCache != null) {
+ Type t = containing_ds.MemberCache.FindNestedType (name);
+ if (t == null) {
+ containing_ds = containing_ds.Parent;
+ continue;
+ }
+
+ e = new TypeExpression (t, Location.Null);
+ e = ResolveNestedType (e, Location.Null);
+ Cache [name] = e;
+ return e;
+ }
+
+ // no member cache. Do it the hard way -- reflection
+ Type current_type = containing_ds.TypeBuilder;
+
+ while (current_type != null &&
+ current_type != TypeManager.object_type) {
+ //
+ // nested class
+ //
+ Type t = TypeManager.LookupType (current_type.FullName + "." + name);
+ if (t != null){
+ e = new TypeExpression (t, Location.Null);
+ e = ResolveNestedType (e, Location.Null);
+ Cache [name] = e;
+ return e;
+ }
+
+ current_type = current_type.BaseType;
+ }
+
+ containing_ds = containing_ds.Parent;
+ }
+
+ e = NamespaceEntry.LookupNamespaceOrType (this, name, loc);
+ if (!silent || e != null)
+ Cache [name] = e;
+ }
+
+ if (e == null && !silent)
+ Report.Error (246, loc, "Cannot find type `"+name+"'");
+
+ return e;
+ }
+
/// <remarks>
/// This function is broken and not what you're looking for. It should only
/// be used while the type is still being created since it doesn't use the cache
Attribute cls_attribute = OptAttributes.Search (TypeManager.cls_compliant_attribute_type, ec);
if (cls_attribute != null) {
caching_flags |= Flags.HasClsCompliantAttribute;
- if (cls_attribute.GetClsCompliantAttributeValue (this)) {
+ if (cls_attribute.GetClsCompliantAttributeValue (ec)) {
caching_flags |= Flags.ClsCompliantAttributeTrue;
return true;
}
type_params [i] = new TypeParameter (Parent, name, constraints, Location);
string full_name = Name + "." + name;
- AddToContainer (type_params [i], false, full_name, name);
+ AddToContainer (type_params [i], full_name, name);
}
}
}
/// <summary>
- /// Returns the IMemberContainer of the parent class or null if this
+ /// Returns the IMemberContainer of the base class or null if this
/// is an interface or TypeManger.object_type.
/// This is used when creating the member cache for a class to get all
- /// members from the parent class.
+ /// members from the base class.
/// </summary>
- MemberCache ParentCache {
+ MemberCache BaseCache {
get;
}
Timer.IncrementCounter (CounterType.MemberCache);
Timer.StartTimer (TimerType.CacheInit);
- // If we have a parent class (we have a parent class unless we're
+ // If we have a base class (we have a base class unless we're
// TypeManager.object_type), we deep-copy its MemberCache here.
- if (Container.ParentCache != null)
- member_hash = SetupCache (Container.ParentCache);
+ if (Container.BaseCache != null)
+ member_hash = SetupCache (Container.BaseCache);
else
member_hash = new Hashtable ();
}
/// <summary>
- /// Bootstrap this member cache by doing a deep-copy of our parent.
+ /// Bootstrap this member cache by doing a deep-copy of our base.
/// </summary>
- Hashtable SetupCache (MemberCache parent)
+ Hashtable SetupCache (MemberCache base_class)
{
Hashtable hash = new Hashtable ();
- if (parent == null)
+ if (base_class == null)
return hash;
- IDictionaryEnumerator it = parent.member_hash.GetEnumerator ();
+ IDictionaryEnumerator it = base_class.member_hash.GetEnumerator ();
while (it.MoveNext ()) {
hash [it.Key] = ((ArrayList) it.Value).Clone ();
}
}
// When this method is called for the current class, the list will
- // already contain all inherited members from our parent classes.
+ // already contain all inherited members from our base classes.
// We cannot add new members in front of the list since this'd be an
// expensive operation, that's why the list is sorted in reverse order
// (ie. members from the current class are coming last).
// `applicable' is a list of all members with the given member name `name'
- // in the current class and all its parent classes. The list is sorted in
+ // in the current class and all its base classes. The list is sorted in
// reverse order due to the way how the cache is initialy created (to speed
- // things up, we're doing a deep-copy of our parent).
+ // things up, we're doing a deep-copy of our base).
for (int i = applicable.Count-1; i >= 0; i--) {
CacheEntry entry = (CacheEntry) applicable [i];
return copy;
}
+ // find the nested type @name in @this.
+ public Type FindNestedType (string name)
+ {
+ ArrayList applicable = (ArrayList) member_hash [name];
+ if (applicable == null)
+ return null;
+
+ for (int i = applicable.Count-1; i >= 0; i--) {
+ CacheEntry entry = (CacheEntry) applicable [i];
+ if ((entry.EntryType & EntryType.NestedType & EntryType.MaskType) != 0)
+ return (Type) entry.Member;
+ }
+
+ return null;
+ }
+
//
// This finds the method or property for us to override. invocationType is the type where
// the override is going to be declared, name is the name of the method/property, and
TypeAttributes attr = Modifiers.TypeAttr (ModFlags, IsTopLevel) |
TypeAttributes.Class | TypeAttributes.Sealed;
+ if (TypeManager.multicast_delegate_type == null)
+ Report.Error (-100, Location, "Internal error: delegate used before " +
+ "System.MulticastDelegate is resolved. This can only " +
+ "happen during corlib compilation, when using a delegate " +
+ "in any of the `core' classes. See bug #72015 for details.");
+
if (IsTopLevel) {
if (TypeManager.NamespaceClash (Name, Location))
return null;
param_names [i] = TypeParameters [i].Name;
GenericTypeParameterBuilder[] gen_params;
-
gen_params = TypeBuilder.DefineGenericParameters (param_names);
- for (int i = 0; i < gen_params.Length; i++)
- TypeParameters [i].Define (gen_params [i]);
+ int offset = CountTypeParameters - CurrentTypeParameters.Length;
+ for (int i = offset; i < gen_params.Length; i++)
+ CurrentTypeParameters [i - offset].Define (gen_params [i]);
- foreach (TypeParameter type_param in TypeParameters) {
- if (!type_param.DefineType (ec))
+ foreach (TypeParameter type_param in CurrentTypeParameters) {
+ if (!type_param.Resolve (this))
return null;
}
+ for (int i = offset; i < gen_params.Length; i++)
+ CurrentTypeParameters [i - offset].DefineConstraints ();
+
TypeExpr current = new ConstructedType (Name, TypeParameters, Location);
current = current.ResolveAsTypeTerminal (ec);
if (current == null)
delegate_instance_expression = ec.GetThis (loc);
if (delegate_instance_expression != null && delegate_instance_expression.Type.IsValueType)
- delegate_instance_expression = new BoxedCast (mg.InstanceExpression);
+ delegate_instance_expression = new BoxedCast (delegate_instance_expression);
method_group = mg;
eclass = ExprClass.Value;
Type e_type = e.Type;
if (!TypeManager.IsDelegateType (e_type)) {
- e.Error_UnexpectedKind ("method", loc);
+ Report.Error (149, loc, "Method name expected");
return null;
}
n.WriteTo (RootContext.Documentation.XmlCommentOutput);
}
- else if (mc.IsExposedFromAssembly (ds) &&
- // There are no warnings when the container also
- // misses documentations.
- (ds == null || ds.DocComment != null))
- {
- Report.Warning (1591, 4, mc.Location,
- "Missing XML comment for publicly visible type or member '{0}'", mc.GetSignatureForError ());
+ else if (mc.IsExposedFromAssembly (ds)) {
+ Constructor c = mc as Constructor;
+ if (c == null || !c.IsDefault ())
+ Report.Warning (1591, 4, mc.Location,
+ "Missing XML comment for publicly visible type or member '{0}'", mc.GetSignatureForError ());
}
}
// returns a full runtime type name from a name which might
// be C# specific type name.
//
- private static Type FindDocumentedType (MemberCore mc,
- string name, DeclSpace ds, bool allowAlias)
+ private static Type FindDocumentedType (MemberCore mc, string name, DeclSpace ds, string cref)
{
bool isArray = false;
string identifier = name;
isArray = true;
}
}
- Type t = FindDocumentedTypeNonArray (mc, identifier,
- ds, allowAlias);
+ Type t = FindDocumentedTypeNonArray (mc, identifier, ds, cref);
if (t != null && isArray)
t = Array.CreateInstance (t, 0).GetType ();
return t;
}
- private static Type FindDocumentedTypeNonArray (MemberCore mc,
- string identifier, DeclSpace ds, bool allowAlias)
+ private static Type FindDocumentedTypeNonArray (MemberCore mc,
+ string identifier, DeclSpace ds, string cref)
{
switch (identifier) {
case "int":
case "void":
return typeof (void);
}
- if (allowAlias) {
- IAlias alias = ds.LookupAlias (identifier);
- if (alias != null)
- identifier = alias.Name;
- }
- Type t = ds.FindType (mc.Location, identifier);
- if (t == null)
- t = TypeManager.LookupTypeDirect (identifier);
- return t;
+ FullNamedExpression e = ds.FindType (mc.Location, identifier);
+ if (e != null) {
+ if (!(e is TypeExpr))
+ return null;
+ return ((TypeExpr) e).ResolveType (ds.EmitContext);
+ }
+ int index = identifier.LastIndexOf ('.');
+ if (index < 0)
+ return null;
+ int warn;
+ Type parent = FindDocumentedType (mc, identifier.Substring (0, index), ds, cref);
+ if (parent == null)
+ return null;
+ return FindDocumentedMember (mc, parent,
+ identifier.Substring (index + 1),
+ Type.EmptyTypes,
+ ds, out warn, cref) as Type;
}
//
((PropertyInfo) mi).PropertyType :
null;
if (returnTypeName != null) {
- Type returnType = FindDocumentedType (mc, returnTypeName, ds, true);
+ Type returnType = FindDocumentedType (mc, returnTypeName, ds, cref);
if (returnType == null || returnType != expected) {
warningType = 1581;
Report.Warning (1581, 1, mc.Location, "Invalid return type in XML comment cref attribute '{0}'", cref);
return mis [0];
}
- private static Type [] emptyParamList = new Type [0];
-
//
// Processes "see" or "seealso" elements.
// Checks cref attribute.
string signature; // "x:" are stripped
string name; // method invokation "(...)" are removed
- string identifiers; // array indexer "[]" are removed
string parameters; // method parameter list
// strip 'T:' 'M:' 'F:' 'P:' 'E:' etc.
}
// check if parameters are valid
- Type [] parameterTypes = emptyParamList;
+ Type [] parameterTypes = Type.EmptyTypes;
if (parameters.Length > 0) {
string [] paramList = parameters.Split (',');
ArrayList plist = new ArrayList ();
for (int i = 0; i < paramList.Length; i++) {
string paramTypeName = paramList [i].Trim (wsChars);
- Type paramType = FindDocumentedType (mc, paramTypeName, ds, true);
+ Type paramType = FindDocumentedType (mc, paramTypeName, ds, cref);
if (paramType == null) {
Report.Warning (1580, 1, mc.Location, "Invalid type for parameter '{0}' in XML comment cref attribute '{1}'", i + 1, cref);
return;
parameters = sb.ToString ();
}
- Type type = FindDocumentedType (mc, name, ds, true);
+ Type type = FindDocumentedType (mc, name, ds, cref);
if (type != null) {
xref.SetAttribute ("cref", "T:" + type.FullName.Replace ("+", "."));
return; // a type
if (period > 0) {
string typeName = name.Substring (0, period);
string memberName = name.Substring (period + 1);
- type = FindDocumentedType (mc, typeName, ds, false);
+ type = FindDocumentedType (mc, typeName, ds, cref);
int warnResult;
if (type != null) {
MemberInfo mi = FindDocumentedMember (mc, type, memberName, parameterTypes, ds, out warnResult, cref);
paramSpec += ")";
string name = mc is Constructor ? "#ctor" : mc.Name;
- return String.Concat (mc.DocCommentHeader, ds.Name, ".", name, paramSpec);
+ string suffix = String.Empty;
+ Operator op = mc as Operator;
+ if (op != null) {
+ switch (op.OperatorType) {
+ case Operator.OpType.Implicit:
+ case Operator.OpType.Explicit:
+ suffix = "~" + op.OperatorMethodBuilder.ReturnType.FullName.Replace ('+', '.');
+ break;
+ }
+ }
+ return String.Concat (mc.DocCommentHeader, ds.Name, ".", name, paramSpec, suffix);
}
//
paramTags [xname] = xname;
}
Parameter [] plist = mc.Parameters.FixedParameters;
- Parameter parr = mc.Parameters.ArrayParameter;
if (plist != null) {
foreach (Parameter p in plist) {
if (paramTags.Count > 0 && paramTags [p.Name] == null)
using System.Text;
using System.Globalization;
using System.Xml;
- using System.Diagnostics;
public enum Target {
Library, Exe, Module, WinExe
static bool timestamps = false;
static bool pause = false;
static bool show_counters = false;
- public static bool parser_verbose = false;
//
// Whether to load the initial config file (what CSC.RSP has by default)
bool ok = MainDriver (args);
if (ok && Report.Errors == 0) {
- Console.Write("Compilation succeeded");
if (Report.Warnings > 0) {
- Console.Write(" - {0} warning(s)", Report.Warnings);
+ Console.WriteLine ("Compilation succeeded - {0} warning(s)", Report.Warnings);
}
- Console.WriteLine();
if (show_counters){
Console.WriteLine ("Counter1: " + counter1);
Console.WriteLine ("Counter2: " + counter2);
a = Assembly.LoadFrom (assembly);
} else {
string ass = assembly;
- if (ass.EndsWith (".dll"))
+ if (ass.EndsWith (".dll") || ass.EndsWith (".exe"))
ass = assembly.Substring (0, assembly.Length - 4);
a = Assembly.Load (ass);
}
} catch (FileNotFoundException){
foreach (string dir in link_paths){
string full_path = Path.Combine (dir, assembly);
- if (!assembly.EndsWith (".dll"))
+ if (!assembly.EndsWith (".dll") && !assembly.EndsWith (".exe"))
full_path += ".dll";
try {
static string [] AddArgs (string [] args, string [] extra_args)
{
string [] new_args;
-
new_args = new string [extra_args.Length + args.Length];
- args.CopyTo (new_args, 0);
- extra_args.CopyTo (new_args, args.Length);
+
+ // if args contains '--' we have to take that into account
+ // split args into first half and second half based on '--'
+ // and add the extra_args before --
+ int split_position = Array.IndexOf (args, "--");
+ if (split_position != -1)
+ {
+ Array.Copy (args, new_args, split_position);
+ extra_args.CopyTo (new_args, split_position);
+ Array.Copy (args, split_position, new_args, split_position + extra_args.Length, args.Length - split_position);
+ }
+ else
+ {
+ args.CopyTo (new_args, 0);
+ extra_args.CopyTo (new_args, args.Length);
+ }
return new_args;
}
if (tokenize)
return true;
+ //
+ // This will point to the NamespaceEntry of the last file that was parsed, and may
+ // not be meaningful when resolving classes from other files. So, reset it to prevent
+ // silent bugs.
+ //
+ RootContext.Tree.Types.NamespaceEntry = null;
+
//
// If we are an exe, require a source file for the entry point
//
//
// Load Core Library for default compilation
//
- if (RootContext.StdLib)
+ if (RootContext.StdLib)
references.Insert (0, "mscorlib");
if (load_default_config)
if (ep == null) {
if (RootContext.MainClass != null) {
- object main_cont = RootContext.Tree.Decls [RootContext.MainClass];
+ DeclSpace main_cont = RootContext.Tree.Decls [RootContext.MainClass] as DeclSpace;
if (main_cont == null) {
Report.Error (1555, output_file, "Could not find '{0}' specified for Main method", RootContext.MainClass);
return false;
Report.Error (1556, output_file, "'{0}' specified for Main method must be a valid class or struct", RootContext.MainClass);
return false;
}
+
+ Report.Error (1558, main_cont.Location, "'{0}' does not have a suitable static Main method", main_cont.GetSignatureForError ());
+ return false;
}
if (Report.Errors == 0)
// Returns a method group.
MethodGroup = 4,
- // Allows SimpleNames to be returned.
- // This is used by MemberAccess to construct long names that can not be
- // partially resolved (namespace-qualified names for example).
- SimpleName = 8,
-
// Mask of all the expression class flags.
- MaskExprClass = 15,
+ MaskExprClass = 7,
// Disable control flow analysis while resolving the expression.
// This is used when resolving the instance expression of a field expression.
- DisableFlowAnalysis = 16,
+ DisableFlowAnalysis = 8,
// Set if this is resolving the first part of a MemberAccess.
- Intermediate = 32
+ Intermediate = 16
}
//
//
if (ma == MethodAttributes.Private) {
Type declaring_type = mi.DeclaringType;
-
+
if (invocation_type != declaring_type)
- return TypeManager.IsNestedFamilyAccessible (invocation_type, declaring_type);
+ return TypeManager.IsNestedChildOf (invocation_type, declaring_type);
return true;
}
}
//
- // This is used if the expression should be resolved as a type.
- // the default implementation fails. Use this method in
- // those participants in the SimpleName chain system.
+ // This is used if the expression should be resolved as a type or namespace name.
+ // the default implementation fails.
//
- public virtual Expression ResolveAsTypeStep (EmitContext ec)
+ public virtual FullNamedExpression ResolveAsTypeStep (EmitContext ec)
{
return null;
}
{
int errors = Report.Errors;
- TypeExpr te = ResolveAsTypeStep (ec) as TypeExpr;
+ FullNamedExpression fne = ResolveAsTypeStep (ec);
- if ((te == null) || (te.eclass != ExprClass.Type) || (te.Type == null)) {
+ if (fne == null) {
if (errors == Report.Errors)
Report.Error (246, Location, "Cannot find type '{0}'", ToString ());
return null;
}
+ if (fne.eclass != ExprClass.Type) {
+ if (errors == Report.Errors)
+ Report.Error (118, Location, "'{0}' denotes a '{1}', where a type was expected",
+ fne.FullName, fne.ExprClassName ());
+ return null;
+ }
+
+ TypeExpr te = fne as TypeExpr;
+
if (!te.CheckAccessLevel (ec.DeclSpace)) {
Report.Error (122, Location, "'{0}' is inaccessible due to its protection level", te.Name);
return null;
if (e == null)
return null;
- if (e is SimpleName){
- SimpleName s = (SimpleName) e;
-
- if ((flags & ResolveFlags.SimpleName) == 0) {
- MemberLookupFailed (ec, null, ec.ContainerType, s.Name,
- ec.DeclSpace.Name, loc);
- return null;
- }
-
- return s;
- }
-
- if ((e is TypeExpr) || (e is ComposedCast)) {
+ if ((e is TypeExpr) || (e is ComposedCast) || (e is Namespace)) {
if ((flags & ResolveFlags.Type) == 0) {
e.Error_UnexpectedKind (flags, loc);
return null;
switch (e.eclass) {
case ExprClass.Type:
+ case ExprClass.Namespace:
if ((flags & ResolveFlags.VariableOrValue) == 0) {
e.Error_UnexpectedKind (flags, loc);
return null;
" ExprClass is Invalid after resolve");
}
- if (e.type == null)
+ if (e.type == null && !(e is Namespace)) {
throw new Exception (
"Expression " + e.GetType () +
" did not set its type after Resolve\n" +
"called from: " + this.GetType ());
+ }
return e;
}
return null;
}
-
- private static ArrayList almostMatchedMembers = new ArrayList (4);
+ protected static ArrayList almostMatchedMembers = new ArrayList (4);
//
// FIXME: Probably implement a cache for (t,name,current_access_set)?
if (qualifier_type != ec.ContainerType) {
// Although a derived class can access protected members of
// its base class it cannot do so through an instance of the
- // base class (CS1540). If the qualifier_type is a parent of the
+ // base class (CS1540). If the qualifier_type is a base of the
// ec.ContainerType and the lookup succeeds with the latter one,
// then we are in this situation.
- foreach (MemberInfo m in almostMatchedMembers)
+ for (int i = 0; i < almostMatchedMembers.Count; ++i) {
+ MemberInfo m = (MemberInfo) almostMatchedMembers [i];
+ for (int j = 0; j < i; ++j) {
+ if (m == almostMatchedMembers [j]) {
+ m = null;
+ break;
+ }
+ }
+ if (m == null)
+ continue;
+
+ Report.SymbolRelatedToPreviousError (m);
Report.Error (1540, loc,
"Cannot access protected member `{0}' via a qualifier of type `{1}';"
+ " the qualifier must be of type `{2}' (or derived from it)",
TypeManager.GetFullNameSignature (m),
TypeManager.CSharpName (qualifier_type),
TypeManager.CSharpName (ec.ContainerType));
+ }
return;
}
almostMatchedMembers.Clear ();
}
}
+ if (name == ".ctor" && TypeManager.FindMembers (qualifier_type, MemberTypes.Constructor,
+ BindingFlags.Static | BindingFlags.Instance | BindingFlags.Public | BindingFlags.DeclaredOnly, null, null).Count == 0)
+ {
+ Report.Error (143, loc, String.Format ("The type '{0}' has no constructors defined", TypeManager.CSharpName (queried_type)));
+ return;
+ }
-
- if (qualifier_type != null)
+ if (qualifier_type != null) {
Report.Error (122, loc, "'{0}' is inaccessible due to its protection level", TypeManager.CSharpName (qualifier_type) + "." + name);
- else if (name == ".ctor") {
- Report.Error (143, loc, String.Format ("The type {0} has no constructors defined",
- TypeManager.CSharpName (queried_type)));
} else {
Report.Error (122, loc, "'{0}' is inaccessible due to its protection level", name);
}
return operator_true;
}
- static string ExprClassName (ExprClass c)
+ public string ExprClassName ()
{
- switch (c){
+ switch (eclass){
case ExprClass.Invalid:
return "Invalid";
case ExprClass.Value:
/// </summary>
public void Error_UnexpectedKind (string expected, Location loc)
{
- string kind = "Unknown";
-
- kind = ExprClassName (eclass);
-
- Report.Error (118, loc, "Expression denotes a `" + kind +
+ Report.Error (118, loc, "Expression denotes a `" + ExprClassName () +
"' where a `" + expected + "' was expected");
}
if ((flags & ResolveFlags.MethodGroup) != 0)
valid.Add ("method group");
- if ((flags & ResolveFlags.SimpleName) != 0)
- valid.Add ("simple name");
-
if (valid.Count == 0)
valid.Add ("unknown");
sb.Append (valid [i]);
}
- string kind = ExprClassName (eclass);
-
- Error (119, "Expression denotes a `" + kind + "' where " +
+ Error (119, "Expression denotes a `" + ExprClassName () + "' where " +
"a `" + sb.ToString () + "' was expected");
}
}
s = v.ToString ();
- } else if (c is UIntConstant){
+ } else if (c is UIntConstant){
uint v = ((UIntConstant) c).Value;
if (target_type == TypeManager.int32_type){
else if (target_type == TypeManager.uint64_type)
return (ulong) v;
s = v.ToString ();
- } else if (c is LongConstant){
+ } else if (c is LongConstant){
long v = ((LongConstant) c).Value;
if (target_type == TypeManager.int32_type){
return (ulong) v;
}
s = v.ToString ();
- } else if (c is ULongConstant){
+ } else if (c is ULongConstant){
ulong v = ((ULongConstant) c).Value;
if (target_type == TypeManager.int32_type){
}
/// <summary>
- /// SimpleName expressions are initially formed of a single
- /// word and it only happens at the beginning of the expression.
+ /// SimpleName expressions are formed of a single word and only happen at the beginning
+ /// of a dotted-name.
/// </summary>
- ///
- /// <remarks>
- /// The expression will try to be bound to a Field, a Method
- /// group or a Property. If those fail we pass the name to our
- /// caller and the SimpleName is compounded to perform a type
- /// lookup. The idea behind this process is that we want to avoid
- /// creating a namespace map from the assemblies, as that requires
- /// the GetExportedTypes function to be called and a hashtable to
- /// be constructed which reduces startup time. If later we find
- /// that this is slower, we should create a `NamespaceExpr' expression
- /// that fully participates in the resolution process.
- ///
- /// For example `System.Console.WriteLine' is decomposed into
- /// MemberAccess (MemberAccess (SimpleName ("System"), "Console"), "WriteLine")
- ///
- /// The first SimpleName wont produce a match on its own, so it will
- /// be turned into:
- /// MemberAccess (SimpleName ("System.Console"), "WriteLine").
- ///
- /// System.Console will produce a TypeExpr match.
- ///
- /// The downside of this is that we might be hitting `LookupType' too many
- /// times with this scheme.
- /// </remarks>
public class SimpleName : Expression {
public string Name;
public readonly TypeArguments Arguments;
- //
- // If true, then we are a simple name, not composed with a ".
- //
- bool is_base;
-
- public SimpleName (string a, string b, Location l)
- {
- Name = String.Concat (a, ".", b);
- loc = l;
- is_base = false;
- }
-
public SimpleName (string name, Location l)
{
Name = name;
loc = l;
- is_base = true;
}
public SimpleName (string name, TypeArguments args, Location l)
Name = name;
Arguments = args;
loc = l;
- is_base = true;
}
public static void Error_ObjectRefRequired (EmitContext ec, Location l, string name)
return SimpleNameResolve (ec, null, true, intermediate);
}
- public override Expression ResolveAsTypeStep (EmitContext ec)
+ public override FullNamedExpression ResolveAsTypeStep (EmitContext ec)
{
DeclSpace ds = ec.DeclSpace;
- NamespaceEntry ns = ds.NamespaceEntry;
- Type t;
- IAlias alias_value;
-
- //
- // Since we are cheating: we only do the Alias lookup for
- // namespaces if the name does not include any dots in it
- //
- if (ns != null && is_base)
- alias_value = ns.LookupAlias (Name);
- else
- alias_value = null;
+ FullNamedExpression dt;
- TypeParameterExpr generic_type = ds.LookupGeneric (Name, loc);
- if (generic_type != null)
- return generic_type.ResolveAsTypeTerminal (ec);
+ dt = ds.LookupGeneric (Name, loc);
+ if (dt != null)
+ return dt.ResolveAsTypeStep (ec);
- if (ec.ResolvingTypeTree){
- int errors = Report.Errors;
- Type dt = ds.FindType (loc, Name);
-
- if (Report.Errors != errors)
- return null;
-
- if (dt != null)
- return new TypeExpression (dt, loc);
-
- if (alias_value != null){
- if (alias_value.IsType)
- return alias_value.ResolveAsType (ec);
- if ((t = RootContext.LookupType (ds, alias_value.Name, true, loc)) != null)
- return new TypeExpression (t, loc);
- }
- }
-
- if ((t = RootContext.LookupType (ds, Name, true, loc)) != null)
- return new TypeExpression (t, loc);
-
- if (alias_value != null) {
- if (alias_value.IsType)
- return alias_value.ResolveAsType (ec);
- if ((t = RootContext.LookupType (ds, alias_value.Name, true, loc)) != null)
- return new TypeExpression (t, loc);
-
- // we have alias value, but it isn't Type, so try if it's namespace
- return new SimpleName (alias_value.Name, loc);
- }
+ int errors = Report.Errors;
+ dt = ec.ResolvingTypeTree
+ ? ds.FindType (loc, Name)
+ : ds.LookupType (Name, true, loc);
+ if (Report.Errors != errors)
+ return null;
- // No match, maybe our parent can compose us
- // into something meaningful.
- return this;
+ return dt;
}
Expression SimpleNameResolve (EmitContext ec, Expression right_side,
Block current_block = ec.CurrentBlock;
if (current_block != null){
- //LocalInfo vi = current_block.GetLocalInfo (Name);
- if (is_base &&
- current_block.IsVariableNameUsedInChildBlock(Name)) {
+ if (current_block.IsVariableNameUsedInChildBlock (Name)) {
Report.Error (135, Location,
- "'{0}' has a different meaning in a " +
- "child block", Name);
+ "'{0}' has a different meaning in a child block", Name);
return null;
}
}
//
DeclSpace lookup_ds = ec.DeclSpace;
+ Type almost_matched_type = null;
+ ArrayList almost_matched = null;
do {
if (lookup_ds.TypeBuilder == null)
break;
if (e != null)
break;
+ if (almost_matched == null && almostMatchedMembers.Count > 0) {
+ almost_matched_type = lookup_ds.TypeBuilder;
+ almost_matched = (ArrayList) almostMatchedMembers.Clone ();
+ }
+
lookup_ds =lookup_ds.Parent;
} while (lookup_ds != null);
e = MemberLookup (ec, ec.ContainerType, Name, loc);
if (e == null) {
- //
- // Since we are cheating (is_base is our hint
- // that we are the beginning of the name): we
- // only do the Alias lookup for namespaces if
- // the name does not include any dots in it
- //
- NamespaceEntry ns = ec.DeclSpace.NamespaceEntry;
- if (is_base && ns != null){
- IAlias alias_value = ns.LookupAlias (Name);
- if (alias_value != null){
- if (alias_value.IsType)
- return alias_value.ResolveAsType (ec);
-
- Name = alias_value.Name;
- Type t;
-
- if ((t = TypeManager.LookupType (Name)) != null)
- return new TypeExpression (t, loc);
-
- // No match, maybe our parent can compose us
- // into something meaningful.
- return this;
- }
+ if (almost_matched == null && almostMatchedMembers.Count > 0) {
+ almost_matched_type = ec.ContainerType;
+ almost_matched = (ArrayList) almostMatchedMembers.Clone ();
}
+ e = ResolveAsTypeStep (ec);
+ }
- return ResolveAsTypeStep (ec);
+ if (e == null) {
+ if (almost_matched != null)
+ almostMatchedMembers = almost_matched;
+ if (almost_matched_type == null)
+ almost_matched_type = ec.ContainerType;
+ MemberLookupFailed (ec, null, almost_matched_type, ((SimpleName) this).Name, ec.DeclSpace.Name, loc);
+ return null;
}
if (e is TypeExpr)
return Name;
}
}
+
+ /// <summary>
+ /// Represents a namespace or a type. The name of the class was inspired by
+ /// section 10.8.1 (Fully Qualified Names).
+ /// </summary>
+ public abstract class FullNamedExpression : Expression {
+ public abstract string FullName {
+ get;
+ }
+ }
/// <summary>
/// Fully resolved expression that evaluates to a type
/// </summary>
- public abstract class TypeExpr : Expression, IAlias {
- override public Expression ResolveAsTypeStep (EmitContext ec)
+ public abstract class TypeExpr : FullNamedExpression {
+ override public FullNamedExpression ResolveAsTypeStep (EmitContext ec)
{
TypeExpr t = DoResolveAsTypeStep (ec);
if (t == null)
protected abstract TypeExpr DoResolveAsTypeStep (EmitContext ec);
+ public virtual Type ResolveType (EmitContext ec)
+ {
+ TypeExpr t = ResolveAsTypeTerminal (ec);
+ if (t == null)
+ return null;
+
+ return t.Type;
+ }
+
public abstract string Name {
get;
}
{
return Name;
}
-
- bool IAlias.IsType {
- get { return true; }
- }
-
- TypeExpr IAlias.ResolveAsType (EmitContext ec)
- {
- return ResolveAsTypeTerminal (ec);
- }
}
- public class TypeExpression : TypeExpr, IAlias {
+ public class TypeExpression : TypeExpr {
public TypeExpression (Type t, Location l)
{
Type = t;
}
}
- string IAlias.Name {
+ public override string FullName {
get {
return Type.FullName != null ? Type.FullName : Type.Name;
}
protected override TypeExpr DoResolveAsTypeStep (EmitContext ec)
{
if (type == null) {
- type = RootContext.LookupType (
- ec.DeclSpace, name, false, Location.Null);
- if (type == null)
+ FullNamedExpression t = ec.DeclSpace.LookupType (name, false, Location.Null);
+ if (t == null)
+ return null;
+ if (!(t is TypeExpr))
return null;
+ type = ((TypeExpr) t).ResolveType (ec);
}
return this;
return name;
}
}
+
+ public override string FullName {
+ get {
+ return name;
+ }
+ }
}
/// <summary>
{ }
}
- public class TypeAliasExpression : TypeExpr, IAlias {
- IAlias alias;
+ public class TypeAliasExpression : TypeExpr {
+ FullNamedExpression alias;
TypeExpr texpr;
TypeArguments args;
string name;
- public TypeAliasExpression (IAlias alias, TypeArguments args, Location l)
+ public TypeAliasExpression (FullNamedExpression alias, TypeArguments args, Location l)
{
this.alias = alias;
this.args = args;
eclass = ExprClass.Type;
if (args != null)
- name = alias.Name + "<" + args.ToString () + ">";
+ name = alias.FullName + "<" + args.ToString () + ">";
else
- name = alias.Name;
+ name = alias.FullName;
}
public override string Name {
+ get { return alias.FullName; }
+ }
+
+ public override string FullName {
get { return name; }
}
protected override TypeExpr DoResolveAsTypeStep (EmitContext ec)
{
- texpr = alias.ResolveAsType (ec);
+ texpr = alias.ResolveAsTypeTerminal (ec);
if (texpr == null)
return null;
LocalTemporary temp;
bool prepared;
+ internal static PtrHashtable AccessorTable = new PtrHashtable ();
+
public PropertyExpr (EmitContext ec, PropertyInfo pi, Location l)
{
PropertyInfo = pi;
PropertyInfo pi = (PropertyInfo) group [0];
if (getter == null)
- getter = pi.GetGetMethod (true);;
+ getter = pi.GetGetMethod (true);
if (setter == null)
- setter = pi.GetSetMethod (true);;
+ setter = pi.GetSetMethod (true);
MethodInfo accessor = getter != null ? getter : setter;
{
FindAccessors (ec.ContainerType);
- is_static = getter != null ? getter.IsStatic : setter.IsStatic;
+ if (getter != null) {
+ AccessorTable [getter] = PropertyInfo;
+ is_static = getter.IsStatic;
+ }
+
+ if (setter != null) {
+ AccessorTable [setter] = PropertyInfo;
+ is_static = setter.IsStatic;
+ }
}
bool InstanceResolve (EmitContext ec, bool must_do_cs1540_check)
public override void Emit (EmitContext ec)
{
if (instance_expr is This)
- Report.Error (79, loc, "The event `{0}' can only appear on the left hand side of += or -=, try calling the actual delegate");
+ Report.Error (79, loc, "The event `{0}' can only appear on the left hand side of += or -=, try calling the actual delegate", Name);
else
Report.Error (70, loc, "The event `{0}' can only appear on the left hand side of += or -= "+
"(except on the defining type)", Name);
EnumMember em = new EnumMember (this, expr, name, loc, opt_attrs);
em.DocComment = documentation;
- if (!AddToContainer (em, false, name, ""))
+ if (!AddToContainer (em, name, ""))
return;
return null;
}
- TypeExpr texpr = ResolveTypeExpr (BaseType, Location);
- if (texpr == null)
+ TypeExpr ute = ResolveBaseTypeExpr (BaseType, false, Location);
+ if (ute == null)
return null;
- UnderlyingType = texpr.Type;
+ UnderlyingType = ute.Type;
if (UnderlyingType != TypeManager.int32_type &&
UnderlyingType != TypeManager.uint32_type &&
((oper == Operator.LogicalAnd && (bool)lc.GetValue () == false) ||
(oper == Operator.LogicalOr && (bool)lc.GetValue () == true))) {
- // TODO: make a sence to resolve unreachable expression as we do for statement
+ // TODO: make a sense to resolve unreachable expression as we do for statement
Report.Warning (429, 4, loc, "Unreachable expression code detected");
return left;
}
}
}
+ // Dead code optimalization
if (expr is BoolConstant){
BoolConstant bc = (BoolConstant) expr;
- if (bc.Value)
- return trueExpr;
- else
- return falseExpr;
+ Report.Warning (429, 4, bc.Value ? falseExpr.Location : trueExpr.Location, "Unreachable expression code detected");
+ return bc.Value ? trueExpr : falseExpr;
}
return this;
pr.AddressOf (ec, mode);
}
} else {
- ((IMemoryLocation)Expr).AddressOf (ec, mode);
+ if (Expr is IMemoryLocation)
+ ((IMemoryLocation) Expr).AddressOf (ec, mode);
+ else {
+ Report.Error (
+ 1510, Expr.Location,
+ "An lvalue is required as an argument to out or ref");
+ return;
+ }
}
} else
Expr.Emit (ec);
if (Arguments != null)
arg_count = Arguments.Count;
-
-#if REVIEW_IFDEF
+
if ((me.Name == "Invoke") &&
TypeManager.IsDelegateType (me.DeclaringType)) {
Error_InvokeOnDelegate (loc);
return null;
}
-#endif
MethodBase[] methods = me.Methods;
}
method = Invocation.OverloadResolve (
- ec, (MethodGroupExpr) ml, Arguments, false, loc);
+ ec, (MethodGroupExpr) ml, Arguments, true, loc);
}
- if (method == null) {
+ if (method == null) {
+ if (almostMatchedMembers.Count != 0) {
+ MemberLookupFailed (ec, type, type, ".ctor", null, loc);
+ return null;
+ }
+
if (!is_struct || Arguments.Count > 0) {
Error (1501, String.Format (
"New invocation: Can not find a constructor in `{0}' for this argument list",
if (sn == null || left == null || left.Type.Name != sn.Name)
return false;
- return RootContext.LookupType (ec.DeclSpace, sn.Name, true, loc) != null;
+ return ec.DeclSpace.LookupType (sn.Name, true, loc) != null;
}
// TODO: possible optimalization
if (expr == null)
return null;
- if (expr is SimpleName){
- SimpleName child_expr = (SimpleName) expr;
- string fqname = DeclSpace.MakeFQN (child_expr.Name, Identifier);
-
- Expression new_expr;
- if (args != null)
- new_expr = new ConstructedType (fqname, args, loc);
- else
- new_expr = new SimpleName (fqname, loc);
-
- return new_expr.Resolve (ec, flags);
+ if (expr is Namespace) {
+ Namespace ns = (Namespace) expr;
+ string lookup_id = MemberName.MakeName (Identifier, args);
+ FullNamedExpression retval = ns.Lookup (ec.DeclSpace, lookup_id, loc);
+ if ((retval != null) && (args != null))
+ retval = new ConstructedType (retval, args, loc).ResolveAsTypeStep (ec);
+ if (retval == null)
+ Report.Error (234, loc, "The type or namespace name `{0}' could not be found in namespace `{1}'", Identifier, ns.FullName);
+ return retval;
}
//
return null;
}
- int errors = Report.Errors;
-
Expression member_lookup;
member_lookup = MemberLookup (
ec, expr_type, expr_type, Identifier, loc);
}
if (member_lookup is TypeExpr) {
- if (!(expr is TypeExpr) && !(expr is SimpleName)) {
+ if (!(expr is TypeExpr) &&
+ !IdenticalNameAndTypeName (ec, original, expr, loc)) {
Error (572, "Can't reference type `" + Identifier + "' through an expression; try `" +
member_lookup.Type + "' instead");
return null;
public override Expression DoResolve (EmitContext ec)
{
- return DoResolve (ec, null, ResolveFlags.VariableOrValue |
- ResolveFlags.SimpleName | ResolveFlags.Type);
+ return DoResolve (ec, null, ResolveFlags.VariableOrValue | ResolveFlags.Type);
}
public override Expression DoResolveLValue (EmitContext ec, Expression right_side)
{
- return DoResolve (ec, right_side, ResolveFlags.VariableOrValue |
- ResolveFlags.SimpleName | ResolveFlags.Type);
+ return DoResolve (ec, right_side, ResolveFlags.VariableOrValue | ResolveFlags.Type);
}
- public override Expression ResolveAsTypeStep (EmitContext ec)
+ public override FullNamedExpression ResolveAsTypeStep (EmitContext ec)
{
- string fname = null;
- MemberAccess full_expr = this;
- while (full_expr != null) {
- if (fname != null)
- fname = String.Concat (full_expr.Identifier, ".", fname);
- else
- fname = full_expr.Identifier;
-
- fname = MemberName.MakeName (fname, args);
-
- if (full_expr.Expr is SimpleName) {
- string full_name = String.Concat (((SimpleName) full_expr.Expr).Name, ".", fname);
- Type fully_qualified = ec.DeclSpace.FindType (loc, full_name);
- if (fully_qualified != null) {
- if (args == null)
- return new TypeExpression (fully_qualified, loc);
-
- ConstructedType ctype = new ConstructedType (fully_qualified, args, loc);
- return ctype.ResolveAsTypeStep (ec);
- }
- }
-
- full_expr = full_expr.Expr as MemberAccess;
- }
-
- Expression new_expr = expr.ResolveAsTypeStep (ec);
+ FullNamedExpression new_expr = expr.ResolveAsTypeStep (ec);
if (new_expr == null)
return null;
- if (new_expr is SimpleName){
- SimpleName child_expr = (SimpleName) new_expr;
- string fqname = DeclSpace.MakeFQN (child_expr.Name, Identifier);
-
- if (args != null)
- new_expr = new ConstructedType (fqname, args, loc);
- else
- new_expr = new SimpleName (fqname, loc);
+ string lookup_id = MemberName.MakeName (Identifier, args);
- return new_expr.ResolveAsTypeStep (ec);
+ if (new_expr is Namespace) {
+ Namespace ns = (Namespace) new_expr;
+ FullNamedExpression retval = ns.Lookup (ec.DeclSpace, lookup_id, loc);
+ if ((retval != null) && (args != null))
+ retval = new ConstructedType (retval, args, loc).ResolveAsTypeStep (ec);
+ if (retval == null)
+ Report.Error (234, loc, "The type or namespace name `{0}' could not be found in namespace `{1}'", Identifier, ns.FullName);
+ return retval;
}
TypeExpr tnew_expr = new_expr.ResolveAsTypeTerminal (ec);
}
Expression member_lookup;
- string lookup_id;
- lookup_id = MemberName.MakeName (Identifier, args);
- member_lookup = MemberLookupFinal (
- ec, expr_type, expr_type, lookup_id, loc);
- if (member_lookup == null)
+ member_lookup = MemberLookupFinal (ec, expr_type, expr_type, lookup_id, loc);
+ if (member_lookup == null) {
+ Report.Error (234, loc, "The type name `{0}' could not be found in type `{1}'",
+ Identifier, new_expr.FullName);
return null;
+ }
- TypeExpr texpr = member_lookup as TypeExpr;
- if (texpr == null)
+ if (!(member_lookup is TypeExpr)) {
+ Report.Error (118, loc, "'{0}.{1}' denotes a '{2}', where a type was expected",
+ new_expr.FullName, Identifier, member_lookup.ExprClassName ());
return null;
+ }
- texpr = texpr.ResolveAsTypeTerminal (ec);
+ TypeExpr texpr = member_lookup.ResolveAsTypeTerminal (ec);
if (texpr == null)
return null;
//
// For now, fall back to the full lookup in that case.
//
- type = RootContext.LookupType (ec.DeclSpace, cname, false, loc);
+ FullNamedExpression e = ec.DeclSpace.LookupType (cname, false, loc);
+ if (e is TypeExpr)
+ type = ((TypeExpr) e).ResolveType (ec);
if (type == null)
return null;
}
UnsafeError (loc);
return null;
}
+
+ if (type.IsArray && (type.GetElementType () == TypeManager.arg_iterator_type ||
+ type.GetElementType () == TypeManager.typed_reference_type)) {
+ Report.Error (611, loc, "Array elements cannot be of type '{0}'", TypeManager.CSharpName (type.GetElementType ()));
+ return null;
+ }
eclass = ExprClass.Type;
return this;
return left + dim;
}
}
+
+ public override string FullName {
+ get {
+ return type.FullName;
+ }
+ }
}
//
if (result.ParameterVector != null)
parameters.Or (result.ParameterVector);
- reachability.Or (new_r);
+ if ((branching.Type == BranchingType.Block) && branching.Block.Implicit)
+ reachability = new_r.Clone ();
+ else
+ reachability.Or (new_r);
Report.Debug (2, " MERGING CHILD DONE", this, result,
new_r, reachability);
throw new NotSupportedException ();
UsageVector vector = new UsageVector (
- SiblingType.Conditional, null, Block, Location,
+ SiblingType.Block, null, Block, Location,
param_map.Length, local_map.Length);
UsageVector result = vector.MergeChild (this);
public bool Resolve (EmitContext ec)
{
- DeclSpace ds = ec.DeclSpace;
-
iface_constraints = new ArrayList ();
type_param_constraints = new ArrayList ();
get { return Name; }
}
- MemberCache IMemberContainer.ParentCache {
+ MemberCache IMemberContainer.BaseCache {
get { return null; }
}
}
}
+ public override string FullName {
+ get {
+ return type_parameter.Name;
+ }
+ }
+
public TypeParameter TypeParameter {
get {
return type_parameter;
public bool Resolve (EmitContext ec)
{
- DeclSpace ds = ec.DeclSpace;
int count = args.Count;
bool ok = true;
full_name = name + "<" + args.ToString () + ">";
}
+ public ConstructedType (FullNamedExpression fname, TypeArguments args, Location l)
+ {
+ loc = l;
+ this.name = fname.FullName;
+ this.args = args;
+
+ eclass = ExprClass.Type;
+ full_name = name + "<" + args.ToString () + ">";
+ }
+
protected ConstructedType (TypeArguments args, Location l)
{
loc = l;
return type == cobj.type;
}
+ public override int GetHashCode ()
+ {
+ return base.GetHashCode ();
+ }
+
public string Basename {
get {
int pos = name.LastIndexOf ('`');
return full_name;
}
}
+
+
+ public override string FullName {
+ get {
+ return full_name;
+ }
+ }
}
public class GenericMethod : DeclSpace
public override MemberCache MemberCache {
get {
- throw new Exception ();
+ return null;
}
}
}
if (a.IsGenericInstance && b.IsGenericInstance) {
- Type at = a.GetGenericTypeDefinition ();
- Type bt = b.GetGenericTypeDefinition ();
-
if (a.GetGenericTypeDefinition () != b.GetGenericTypeDefinition ())
return false;
if (a.GetGenericTypeDefinition () != b.GetGenericTypeDefinition ())
return false;
- Type[] aargs = GetTypeArguments (a);
- Type[] bargs = GetTypeArguments (b);
-
return MayBecomeEqualGenericInstances (
GetTypeArguments (a), GetTypeArguments (b), class_infered, method_infered);
}
if (aargs.Length != bargs.Length)
return false;
- Type[] args = new Type [aargs.Length];
for (int i = 0; i < aargs.Length; i++) {
if (!MayBecomeEqualGenericTypes (aargs [i], bargs [i], class_infered, method_infered))
return false;
//
// TODO:
// Flow analysis for Yield.
-// Emit calls to parent object constructor.
+// Emit calls to base object constructor.
//
// Generics note:
// Current should be defined to return T, and IEnumerator.Current returns object
string path = Path.GetFullPath (name);
if (source_files.Contains (path)){
- Report.Warning (2002, name, "Source file '{0}' specified multiple times");
+ Report.Warning (2002, name, "Source file '{0}' specified multiple times", path);
return;
}
/// <summary>
/// Keeps track of the namespaces defined in the C# code.
+ ///
+ /// This is an Expression to allow it to be referenced in the
+ /// compiler parse/intermediate tree during name resolution.
/// </summary>
- public class Namespace : IAlias {
+ public class Namespace : FullNamedExpression, IAlias {
static ArrayList all_namespaces = new ArrayList ();
static Hashtable namespaces_map = new Hashtable ();
/// </summary>
public Namespace (Namespace parent, string name)
{
+ // Expression members.
+ this.eclass = ExprClass.Namespace;
+ this.Type = null;
+ this.loc = Location.Null;
+
this.parent = parent;
string pname = parent != null ? parent.Name : "";
namespaces_map [fullname] = true;
}
+ public override Expression DoResolve (EmitContext ec)
+ {
+ return this;
+ }
+
+ public override void Emit (EmitContext ec)
+ {
+ throw new InternalErrorException ("Expression tree referenced namespace " + fullname + " during Emit ()");
+ }
+
public static bool IsNamespace (string name)
{
return namespaces_map [name] != null;
return Root.GetNamespace (name, create);
}
- public IAlias Lookup (DeclSpace ds, string name, Location loc)
+ public FullNamedExpression Lookup (DeclSpace ds, string name, Location loc)
{
- IAlias o = Lookup (name);
+ IAlias o = (IAlias) defined_names [name];
Type t;
DeclSpace tdecl = o as DeclSpace;
return null;
if ((ds == null) || ds.CheckAccessLevel (t))
- return new TypeExpression (t, loc);
+ return new TypeExpression (t, Location.Null);
}
Namespace ns = GetNamespace (name, false);
if ((t == null) || ((ds != null) && !ds.CheckAccessLevel (t)))
return null;
- return new TypeExpression (t, loc);
+ return new TypeExpression (t, Location.Null);
}
public void AddNamespaceEntry (NamespaceEntry entry)
defined_names.Add (name, o);
}
- public IAlias Lookup (string name)
- {
- return (IAlias) defined_names [name];
- }
-
static public ArrayList UserDefinedNamespaces {
get {
return all_namespaces;
}
}
+ public override string FullName {
+ get {
+ return fullname;
+ }
+ }
+
/// <summary>
/// The parent of this namespace, used by the parser to "Pop"
/// the current namespace declaration
if (resolved_ns != null)
return resolved_ns;
- object resolved = NamespaceEntry.LookupForUsing (Name, Location);
+ FullNamedExpression resolved = NamespaceEntry.LookupForUsing (Name, Location);
resolved_ns = resolved as Namespace;
return resolved_ns;
}
Location = loc;
}
- IAlias resolved;
+ FullNamedExpression resolved;
- public IAlias Resolve ()
+ public FullNamedExpression Resolve ()
{
if (resolved != null)
return resolved;
if (resolved == null)
return null;
- if (resolved.IsType)
- resolved = new TypeAliasExpression (
- resolved, Alias.TypeArguments, Location);
+ if (Alias.TypeArguments == null)
+ return resolved;
+
+ EmitContext ec = RootContext.Tree.Types.EmitContext;
+ resolved = new TypeAliasExpression (resolved, Alias.TypeArguments, Location);
+ resolved = resolved.ResolveAsTypeStep (ec);
return resolved;
}
aliases [name] = new AliasEntry (this, name, alias, loc);
}
- protected AliasEntry GetAliasEntry (string alias)
+ public FullNamedExpression LookupAlias (string alias)
{
AliasEntry entry = null;
-
if (aliases != null)
entry = (AliasEntry) aliases [alias];
- if (entry == null && Parent != null)
- entry = Parent.GetAliasEntry (alias);
- return entry;
- }
-
- public IAlias LookupAlias (string alias)
- {
- AliasEntry entry = GetAliasEntry (alias);
-
- if (entry == null)
- return null;
-
- return entry.Resolve ();
+ return entry == null ? null : entry.Resolve ();
}
//
// Section 16.3.2 says that the same rule is applied when resolving the namespace-name
// in the using-namespace-directive.
//
- public IAlias LookupForUsing (string dotted_name, Location loc)
+ public FullNamedExpression LookupForUsing (string dotted_name, Location loc)
{
int pos = dotted_name.IndexOf ('.');
string simple_name = dotted_name;
rest = dotted_name.Substring (pos + 1);
}
- IAlias o = NS.Lookup (null, simple_name, loc);
+ FullNamedExpression o = NS.Lookup (null, simple_name, loc);
if (o == null && ImplicitParent != null)
o = ImplicitParent.LookupNamespaceOrType (null, simple_name, loc);
if (ns != null)
return ns.Lookup (null, rest, loc);
- Type nested = TypeManager.LookupType (o.Name + "." + rest);
+ Type nested = TypeManager.LookupType (o.FullName + "." + rest);
if (nested == null)
return null;
- return new TypeExpression (nested, loc);
+ return new TypeExpression (nested, Location.Null);
}
- public IAlias LookupNamespaceOrType (DeclSpace ds, string name, Location loc)
+ public FullNamedExpression LookupNamespaceOrType (DeclSpace ds, string name, Location loc)
{
- IAlias resolved = null;
+ FullNamedExpression resolved = null;
for (NamespaceEntry curr_ns = this; curr_ns != null; curr_ns = curr_ns.ImplicitParent) {
if ((resolved = curr_ns.Lookup (ds, name, loc)) != null)
break;
return resolved;
}
- private IAlias Lookup (DeclSpace ds, string name, Location loc)
+ private FullNamedExpression Lookup (DeclSpace ds, string name, Location loc)
{
- IAlias o;
+ FullNamedExpression o;
Namespace ns;
//
return o;
}
- Type nested = TypeManager.LookupType (o.Name + "." + last);
+ Type nested = TypeManager.LookupType (o.FullName + "." + last);
if ((nested == null) || ((ds != null) && !ds.CheckAccessLevel (nested)))
return null;
- return new TypeExpression (nested, loc);
+ return new TypeExpression (nested, Location.Null);
}
//
//
// Check aliases.
//
- AliasEntry entry = GetAliasEntry (name);
- if (entry != null) {
- IAlias alias = entry.Resolve ();
- if (alias != null)
- return alias;
- }
+ o = LookupAlias (name);
+ if (o != null)
+ return o;
if (name.IndexOf ('.') > 0)
return null;
//
// Check using entries.
//
- IAlias t = null, match = null;
+ FullNamedExpression t = null, match = null;
foreach (Namespace using_ns in GetUsingTable ()) {
match = using_ns.Lookup (ds, name, loc);
- if ((match != null) && match.IsType){
+ if ((match != null) && (match is TypeExpr)) {
if (t != null) {
- DeclSpace.Error_AmbiguousTypeReference (loc, name, t.Name, match.Name);
+ DeclSpace.Error_AmbiguousTypeReference (loc, name, t.FullName, match.FullName);
return null;
} else {
t = match;
{
if (namespace_using_table != null)
return namespace_using_table;
-
- if (using_clauses == null)
- return new Namespace [0];
+
+ if (using_clauses == null) {
+ namespace_using_table = new Namespace [0];
+ return namespace_using_table;
+ }
ArrayList list = new ArrayList (using_clauses.Count);
/// </summary>
public void VerifyUsing ()
{
- TypeContainer dummy = new RootTypes ();
- EmitContext ec = new EmitContext (
- dummy, Location.Null, null, null, 0, false);
-
if (using_clauses != null){
foreach (UsingEntry ue in using_clauses){
if (ue.Resolve () != null)
if (aliases != null){
foreach (DictionaryEntry de in aliases){
- AliasEntry entry = (AliasEntry) de.Value;
-
- IAlias alias = entry.Resolve ();
- if (alias != null) {
- if (alias.IsType)
- alias.ResolveAsType (ec);
+ AliasEntry alias = (AliasEntry) de.Value;
+ if (alias.Resolve () != null)
continue;
- }
- error246 (entry.Location, entry.Alias.GetTypeName ());
+ error246 (alias.Location, alias.Alias.GetTypeName ());
}
}
}
public override void ApplyAttributeBuilder(Attribute a, CustomAttributeBuilder cb)
{
+ if (a.Type == TypeManager.cls_compliant_attribute_type) {
+ Report.Warning (3023, 1, a.Location, "CLSCompliant attribute has no meaning when applied to return types. Try putting it on the method instead");
+ }
+
// This occurs after Warning -28
if (builder == null)
return;
GenericConstraints constraints;
Type parameter_type;
+ EmitContext ec; // because ApplyAtrribute doesn't have ec
+
/* These two fields are mbas specific. The corresponding
changes need to be merged from mbas */
public override void ApplyAttributeBuilder (Attribute a, CustomAttributeBuilder cb)
{
+ if (a.Type == TypeManager.in_attribute_type && Attributes == ParameterAttributes.Out) {
+ Report.Error (36, a.Location, "Can not use [In] attribute on out parameter");
+ return;
+ }
+
if (a.Type == TypeManager.param_array_type) {
Report.Error (674, a.Location, "Do not use 'System.ParamArrayAttribute'. Use the 'params' keyword instead");
return;
}
+
+ if (a.Type == TypeManager.out_attribute_type && (ModFlags & Modifier.REF) != 0 &&
+ !OptAttributes.Contains (TypeManager.in_attribute_type, ec)) {
+ Report.Error (662, a.Location,
+ "'{0}' cannot specify only Out attribute on a ref parameter. Use both In and Out attributes, or neither", GetSignatureForError ());
+ return;
+ }
+
+ if (a.Type == TypeManager.cls_compliant_attribute_type) {
+ Report.Warning (3022, 1, a.Location, "CLSCompliant attribute has no meaning when applied to parameters. Try putting it on the method instead");
+ }
+
base.ApplyAttributeBuilder (a, cb);
}
public bool Resolve (EmitContext ec, Location l)
{
TypeExpr texpr = TypeName.ResolveAsTypeTerminal (ec);
+ this.ec = ec;
+
if (texpr == null)
return false;
}
if (parameter_type == TypeManager.void_type){
- Report.Error (1536, l, "`void' parameter is not permitted");
+ Report.Error (1536, l, "Invalid parameter type 'void'");
return false;
}
if (OptAttributes != null) {
OptAttributes.Emit (ec, this);
-
- if (par_attr == ParameterAttributes.Out){
- if (OptAttributes.Contains (TypeManager.in_attribute_type, ec))
- Report.Error (36, loc, "Can not use [In] attribute on out parameter");
- }
}
}
return attribute_targets;
}
}
-
}
/// <summary>
// Note: as per the spec, the `params' arguments (ArrayParameter)
// are not used in the signature computation for a method
//
-
}
void Error_DuplicateParameterName (string name)
types [i] = t;
i++;
-
}
}
//
// Whether it is optional, this is used to allow the explicit/implicit
- // implementation when a parent class already implements an interface.
+ // implementation when a base class already implements an interface.
//
// For example:
//
/// <summary>
/// This is the array of TypeAndMethods that describes the pending implementations
- /// (both interfaces and abstract methods in parent class)
+ /// (both interfaces and abstract methods in base class)
/// </summary>
TypeAndMethods [] pending_implementations;
// <remarks>
// Returns a list of the abstract methods that are exposed by all of our
- // parents that we must implement. Notice that this `flattens' the
+ // bases that we must implement. Notice that this `flattens' the
// method search space, and takes into account overrides.
// </remarks>
static ArrayList GetAbstractMethods (Type t)
if (type_builder.BaseType == null)
return ret;
- Type [] parent_impls = TypeManager.GetInterfaces (type_builder.BaseType);
+ Type [] base_impls = TypeManager.GetInterfaces (type_builder.BaseType);
- foreach (Type t in parent_impls) {
+ foreach (Type t in base_impls) {
for (int i = 0; i < ret.Length; i ++) {
if (t == ret [i].Type) {
ret [i].Optional = true;
/// For that case, we create an explicit implementation function
/// I.M in Y.
/// </summary>
- void DefineProxy (Type iface, MethodInfo parent_method, MethodInfo iface_method,
+ void DefineProxy (Type iface, MethodInfo base_method, MethodInfo iface_method,
Type [] args)
{
MethodBuilder proxy;
MethodAttributes.NewSlot |
MethodAttributes.Virtual,
CallingConventions.Standard | CallingConventions.HasThis,
- parent_method.ReturnType, args);
+ base_method.ReturnType, args);
ParameterData pd = Invocation.GetParameterData (iface_method);
proxy.DefineParameter (0, ParameterAttributes.None, "");
for (int i = 0; i < pd.Count; i++) {
string name = pd.ParameterName (i);
ParameterAttributes attr = Parameter.GetParameterAttributes (pd.ParameterModifier (i));
- ParameterBuilder pb = proxy.DefineParameter (i + 1, attr, name);
+ proxy.DefineParameter (i + 1, attr, name);
}
int top = args.Length;
ILGenerator ig = proxy.GetILGenerator ();
- ig.Emit (OpCodes.Ldarg_0);
- for (int i = 0; i < top; i++){
- switch (i){
- case 0:
- ig.Emit (OpCodes.Ldarg_1); break;
- case 1:
- ig.Emit (OpCodes.Ldarg_2); break;
- case 2:
- ig.Emit (OpCodes.Ldarg_3); break;
- default:
- ig.Emit (OpCodes.Ldarg, i - 1); break;
- }
- }
- ig.Emit (OpCodes.Call, parent_method);
+ for (int i = 0; i <= top; i++)
+ ParameterReference.EmitLdArg (ig, i);
+
+ ig.Emit (OpCodes.Call, base_method);
ig.Emit (OpCodes.Ret);
container.TypeBuilder.DefineMethodOverride (proxy, iface_method);
}
/// <summary>
- /// This function tells whether one of our parent classes implements
+ /// This function tells whether one of our base classes implements
/// the given method (which turns out, it is valid to have an interface
- /// implementation in a parent
+ /// implementation in a base
/// </summary>
- bool ParentImplements (Type iface_type, MethodInfo mi)
+ bool BaseImplements (Type iface_type, MethodInfo mi)
{
MethodSignature ms;
if (list.Count == 0)
return false;
- MethodInfo parent = (MethodInfo) list [0];
- if (!parent.IsAbstract)
- DefineProxy (iface_type, parent, mi, args);
+ MethodInfo base_method = (MethodInfo) list [0];
+ if (!base_method.IsAbstract)
+ DefineProxy (iface_type, base_method, mi, args);
return true;
}
continue;
}
- if (ParentImplements (type, mi))
+ if (BaseImplements (type, mi))
continue;
if (pending_implementations [i].optional)
//
// Whether we are being linked against the standard libraries.
// This is only used to tell whether `System.Object' should
- // have a parent or not.
+ // have a base class or not.
//
public static bool StdLib = true;
// This keeps track of the order in which classes were defined
// so that we can poulate them in that order.
//
- // Order is important, because we need to be able to tell by
- // examining the parent's list of methods which ones are virtual
+ // Order is important, because we need to be able to tell, by
+ // examining the list of methods of the base class, which ones are virtual
// or abstract as well as the parent names (to implement new,
// override).
//
static TypeBuilder impl_details_class;
- public static int WarningLevel = 2;
+ public static int WarningLevel = 3;
public static Target Target = Target.Exe;
public static string TargetExt = ".exe";
"System.Runtime.CompilerServices.IndexerNameAttribute",
"System.Runtime.CompilerServices.DecimalConstantAttribute",
"System.Runtime.InteropServices.InAttribute",
+ "System.Runtime.InteropServices.OutAttribute",
"System.Runtime.InteropServices.StructLayoutAttribute",
"System.Runtime.InteropServices.FieldOffsetAttribute",
"System.InvalidOperationException",
helper_classes.Add (helper_class);
}
- //
- // This idea is from Felix Arrese-Igor
- //
- // Returns : the implicit parent of a composite namespace string
- // eg. Implicit parent of A.B is A
- //
- static public string ImplicitParent (string ns)
- {
- int i = ns.LastIndexOf ('.');
- if (i < 0)
- return null;
-
- return ns.Substring (0, i);
- }
-
- static Type NamespaceLookup (DeclSpace ds, string name, int num_type_args, Location loc)
- {
- IAlias result = ds.NamespaceEntry.LookupNamespaceOrType (ds, name, loc);
- if (result == null)
- return null;
-
- if (!result.IsType)
- return null;
-
- TypeExpr texpr = result.ResolveAsType (ds.EmitContext);
- if (texpr == null)
- return null;
-
- return texpr.Type;
- }
-
- static public Type LookupType (DeclSpace ds, string name, bool silent, Location loc)
- {
- return LookupType (ds, name, silent, 0, loc);
- }
-
- //
- // Public function used to locate types, this can only
- // be used after the ResolveTree function has been invoked.
- //
- // Returns: Type or null if they type can not be found.
- //
- // Come to think of it, this should be a DeclSpace
- //
- static public Type LookupType (DeclSpace ds, string name, bool silent,
- int num_type_params, Location loc)
- {
- Type t;
-
- if (ds.Cache.Contains (name)){
- t = (Type) ds.Cache [name];
- if (t != null)
- return t;
- } else {
- //
- // For the case the type we are looking for is nested within this one
- // or is in any base class
- //
- DeclSpace containing_ds = ds;
- while (containing_ds != null){
- Type current_type = containing_ds.TypeBuilder;
-
- while (current_type != null) {
- //
- // nested class
- //
- Type type = TypeManager.LookupType (current_type.FullName + "." + name);
- if (type != null){
- t = ds.ResolveNestedType (type, loc);
- ds.Cache [name] = t;
- return t;
- }
-
- current_type = current_type.BaseType;
- }
-
- containing_ds = containing_ds.Parent;
- }
-
- t = NamespaceLookup (ds, name, num_type_params, loc);
- if (!silent || t != null){
- ds.Cache [name] = t;
- return t;
- }
- }
-
- if (!silent)
- Report.Error (246, loc, "Cannot find type `"+name+"'");
-
- return null;
- }
-
- // <summary>
- // This is the silent version of LookupType, you can use this
- // to `probe' for a type
- // </summary>
- static public Type LookupType (TypeContainer tc, string name, Location loc)
- {
- return LookupType (tc, name, true, loc);
- }
-
static void Report1530 (Location loc)
{
Report.Error (1530, loc, "Keyword new not allowed for namespace elements");
return false;
}
+ Assign ass = expr as Assign;
+ if (ass != null && ass.Source is Constant) {
+ Report.Warning (665, 3, loc, "Assignment in conditional expression is always constant; did you mean to use == instead of = ?");
+ }
+
//
// Dead code elimination
//
bool defined;
bool referenced;
Label label;
+ ILGenerator ig;
FlowBranching.UsageVector vectors;
{
if (defined)
return label;
+ ig = ec.ig;
label = ec.ig.DefineLabel ();
defined = true;
protected override void DoEmit (EmitContext ec)
{
+ if (ig != null && ig != ec.ig) {
+ Report.Error (1632, "Control cannot leave body of anonymous method");
+ return;
+ }
LabelTarget (ec);
ec.ig.MarkLabel (label);
}
public override bool Resolve (EmitContext ec)
{
- bool in_catch = ec.CurrentBranching.InCatch ();
ec.CurrentBranching.CurrentUsageVector.Throw ();
if (expr != null){
ExprClass eclass = expr.eclass;
if (!(eclass == ExprClass.Variable || eclass == ExprClass.PropertyAccess ||
- eclass == ExprClass.Value || eclass == ExprClass.IndexerAccess)) {
+ eclass == ExprClass.Value || eclass == ExprClass.IndexerAccess)) {
expr.Error_UnexpectedKind ("value, variable, property or indexer access ", loc);
return false;
}
Type t = expr.Type;
if ((t != TypeManager.exception_type) &&
- !t.IsSubclassOf (TypeManager.exception_type) &&
- !(expr is NullLiteral)) {
+ !t.IsSubclassOf (TypeManager.exception_type) &&
+ !(expr is NullLiteral)) {
Error (155,
- "The type caught or thrown must be derived " +
- "from System.Exception");
+ "The type caught or thrown must be derived " +
+ "from System.Exception");
return false;
}
- } else if (!in_catch) {
- Error (156,
- "A throw statement with no argument is only " +
- "allowed in a catch clause");
+ return true;
+ }
+
+ if (ec.CurrentBranching.InFinally (true)) {
+ Error (724, "A throw statement with no argument is only allowed in a catch clause nested inside of the innermost catch clause");
return false;
}
+ if (!ec.CurrentBranching.InCatch ()) {
+ Error (156, "A throw statement with no argument is only allowed in a catch clause");
+ return false;
+ }
return true;
}
// </summary>
public LocalInfo ThisVariable {
get {
- if (this_variable != null)
- return this_variable;
- else if (Parent != null)
- return Parent.ThisVariable;
- else
- return null;
+ for (Block b = this; b != null; b = b.Parent) {
+ if (b.this_variable != null)
+ return b.this_variable;
+ }
+
+ return null;
}
}
/// </remarks>
public void ResolveMeta (ToplevelBlock toplevel, EmitContext ec, InternalParameters ip)
{
- ILGenerator ig = ec.ig;
-
bool old_unsafe = ec.InUnsafe;
// If some parent block was unsafe, we remain unsafe even if this block
Report.Debug (4, "RESOLVE BLOCK", StartLocation, ec.CurrentBranching);
- bool unreachable = false;
+ bool unreachable = unreachable_shown;
int statement_count = statements.Count;
for (int ix = 0; ix < statement_count; ix++){
else
s.loc = Location.Null;
- statements [ix] = EmptyStatement.Value;
- continue;
+ if (ok && !(s is Block)) {
+ statements [ix] = EmptyStatement.Value;
+ continue;
+ }
}
if (s.Resolve (ec) == false) {
public override bool ResolveUnreachable (EmitContext ec, bool warn)
{
unreachable_shown = true;
- return base.ResolveUnreachable (ec, warn);
+
+ if (warn && (RootContext.WarningLevel >= 2))
+ Report.Warning (162, loc, "Unreachable code detected");
+
+ if (Implicit)
+ return Resolve (ec);
+
+ ec.StartFlowBranching (FlowBranching.BranchingType.Block, loc);
+ bool ok = Resolve (ec);
+ ec.KillFlowBranching ();
+
+ return ok;
}
protected override void DoEmit (EmitContext ec)
// Check whether we are the last statement in a
// top-level block.
- if ((Parent == null) && (ix+1 == num_statements))
+ if (((Parent == null) || Implicit) && (ix+1 == num_statements) && !(s is Block))
ec.IsLastStatement = true;
else
ec.IsLastStatement = false;
static int did = 0;
- int my_id = did++;
-
public void RegisterCaptureContext (CaptureContext cc)
{
ILGenerator ig = ec.ig;
int i = assign.Length;
- foreach (DictionaryEntry e in var_list){
+ for (int ii = 0; ii < var_list.Count; ++ii){
Expression var = resolved_vars [--i];
Label skip = ig.DefineLabel ();
if (expr == null)
return false;
+ if (expr is NullLiteral) {
+ Report.Error (186, expr.Location, "Use of null is not valid in this context");
+ return false;
+ }
+
TypeExpr texpr = type.ResolveAsTypeTerminal (ec);
if (texpr == null)
return false;
return false;
}
ForeachHelperMethods hm = (ForeachHelperMethods) criteria;
- EmitContext ec = hm.ec;
// Check whether GetEnumerator is public
if ((mi.Attributes & MethodAttributes.Public) != MethodAttributes.Public)
ig.Emit (OpCodes.Brfalse, end_try);
if (ec.InIterator)
- enumerator.EmitThis (ig);
+ ig.Emit (OpCodes.Ldarg_0);
+
enumerator.EmitCall (ig, hm.get_current);
if (ec.InIterator){
ig.MarkLabel (loop);
if (ec.InIterator)
- ec.EmitThis ();
+ ig.Emit (OpCodes.Ldarg_0);
copy.EmitThis (ig);
copy.EmitLoad (ig);
}
if (ec.InIterator)
- ec.EmitThis ();
+ ig.Emit (OpCodes.Ldarg_0);
+
copy.EmitThis (ig);
copy.EmitLoad (ig);
for (dim = 0; dim < rank; dim++){
public Parameter.Modifier ParameterModifier (int pos)
{
- int len = pi.Length;
-
if (last_arg_is_params && pos >= pi.Length - 1)
return Parameter.Modifier.PARAMS;
else if (is_varargs && pos >= pi.Length)
// buffer.
if ((value >= buffer_start) && (value < buffer_start + buffer_size)) {
int byte_offset = value - buffer_start;
+
+ // pos is an index into a char
+ // buffer so it might be
+ // greater than the buffer
+ // length now, if the buffer
+ // contains multibyte chars
pos = byte_offset;
- // encoded characters can take more than 1 byte length
- while (reader.CurrentEncoding.GetByteCount (buffer, 0, pos) > byte_offset)
+
+ // encoded characters can take
+ // more than 1 byte length.
+ while ((pos > buffer.Length) ||
+ reader.CurrentEncoding.GetByteCount (buffer, 0, pos) > byte_offset) {
pos--;
+ }
return;
}
{
throw new InvalidOperationException ();
}
+
+ public override bool IsClsCompliaceRequired (DeclSpace ds)
+ {
+ return true;
+ }
+
}
}
static public Type obsolete_attribute_type;
static public Type conditional_attribute_type;
static public Type in_attribute_type;
+ static public Type out_attribute_type;
static public Type anonymous_method_type;
static public Type cls_compliant_attribute_type;
static public Type typed_reference_type;
return TypeHandle.GetMemberCache (t);
}
- public static MemberCache LookupParentInterfacesCache (Type t)
+ public static MemberCache LookupBaseInterfacesCache (Type t)
{
Type [] ifaces = t.GetInterfaces ();
}
//
- // We know that System.Object does not have children, and since its the parent of
+ // We know that System.Object does not have children, and since its the base of
// all the objects, it always gets probbed for inner classes.
//
if (top_level_type == "System.Object")
@"Single|Double|Char|Decimal|Byte|SByte|Object|" +
@"Boolean|String|Void|Null)" +
@"(\W+|\b)",
- new MatchEvaluator (CSharpNameMatch));
+ new MatchEvaluator (CSharpNameMatch)).Replace ('+', '.');
}
static String CSharpNameMatch (Match match)
/// </summary>
static public string GetFullNameSignature (MemberInfo mi)
{
- return mi.DeclaringType.FullName.Replace ('+', '.') + '.' + mi.Name;
+ // Unfortunately, there's no dynamic dispatch on the arguments of a function.
+ return (mi is MethodBase)
+ ? GetFullNameSignature (mi as MethodBase)
+ : mi.DeclaringType.FullName.Replace ('+', '.') + '.' + mi.Name;
}
static public string GetFullNameSignature (MethodBase mb)
marshal_as_attr_type = CoreLookupType ("System.Runtime.InteropServices.MarshalAsAttribute");
param_array_type = CoreLookupType ("System.ParamArrayAttribute");
in_attribute_type = CoreLookupType ("System.Runtime.InteropServices.InAttribute");
+ out_attribute_type = CoreLookupType ("System.Runtime.InteropServices.OutAttribute");
typed_reference_type = CoreLookupType ("System.TypedReference");
arg_iterator_type = CoreLookupType ("System.ArgIterator");
mbr_type = CoreLookupType ("System.MarshalByRefObject");
return tc.Kind == Kind.Interface;
}
- public static bool IsSubclassOf (Type type, Type parent)
+ public static bool IsSubclassOf (Type type, Type base_type)
{
TypeParameter tparam = LookupTypeParameter (type);
- TypeParameter pparam = LookupTypeParameter (parent);
+ TypeParameter pparam = LookupTypeParameter (base_type);
if ((tparam != null) && (pparam != null)) {
if (tparam == pparam)
return true;
- return tparam.IsSubclassOf (parent);
+ return tparam.IsSubclassOf (base_type);
}
do {
- if (type.Equals (parent))
+ if (type.Equals (base_type))
return true;
type = type.BaseType;
}
if (type.IsGenericInstance && parent.IsGenericInstance) {
- Type tdef = type.GetGenericTypeDefinition ();
- Type pdef = parent.GetGenericTypeDefinition ();
-
if (type.GetGenericTypeDefinition () != parent.GetGenericTypeDefinition ())
return false;
}
//
- // Checks whether `type' is a subclass or nested child of `parent'.
+ // Checks whether `type' is a subclass or nested child of `base_type'.
//
- public static bool IsNestedFamilyAccessible (Type type, Type parent)
+ public static bool IsNestedFamilyAccessible (Type type, Type base_type)
{
do {
- if (IsFamilyAccessible (type, parent))
+ if (IsFamilyAccessible (type, base_type))
return true;
// Handle nested types.
return true;
foreach (Field field in tc.Fields) {
- if (field.FieldBuilder.IsStatic)
+ if (field.FieldBuilder == null || field.FieldBuilder.IsStatic)
continue;
Type ftype = field.FieldBuilder.FieldType;
t = TypeManager.array_type;
if (t is TypeBuilder){
- Type[] parent_ifaces;
+ Type [] base_ifaces;
if (t.BaseType == null)
- parent_ifaces = NoTypes;
+ base_ifaces = NoTypes;
else
- parent_ifaces = GetInterfaces (t.BaseType);
+ base_ifaces = GetInterfaces (t.BaseType);
Type[] type_ifaces = (Type []) builder_to_ifaces [t];
if (type_ifaces == null)
type_ifaces = NoTypes;
- int parent_count = parent_ifaces.Length;
- Type[] result = new Type [parent_count + type_ifaces.Length];
- parent_ifaces.CopyTo (result, 0);
- type_ifaces.CopyTo (result, parent_count);
+ int base_count = base_ifaces.Length;
+ Type [] result = new Type [base_count + type_ifaces.Length];
+ base_ifaces.CopyTo (result, 0);
+ type_ifaces.CopyTo (result, base_count);
iface_cache [t] = result;
return result;
// as soon as we hit a non-TypeBuiler in the interface
// chain, we could return, as the `Type.GetInterfaces'
// will return all the interfaces implement by the type
- // or its parents.
+ // or its bases.
//
do {
interfaces = GetInterfaces (t);
if (invocation_type == null)
return false;
+ Debug.Assert (IsNestedFamilyAccessible (invocation_type, m.DeclaringType));
+
if (is_static)
return true;
// works if we already used the cache in the first iteration of this loop.
//
// If we used the cache in any further iteration, we can still terminate the
- // loop since the cache always looks in all parent classes.
+ // loop since the cache always looks in all base classes.
//
if (used_cache)
private string full_name;
private bool is_interface;
private MemberCache member_cache;
- private MemberCache parent_cache;
+ private MemberCache base_cache;
private TypeHandle (Type type)
{
full_name = type.FullName != null ? type.FullName : type.Name;
if (type.BaseType != null) {
BaseType = GetTypeHandle (type.BaseType);
- parent_cache = BaseType.MemberCache;
+ base_cache = BaseType.MemberCache;
} else if (type.IsInterface)
- parent_cache = TypeManager.LookupParentInterfacesCache (type);
+ base_cache = TypeManager.LookupBaseInterfacesCache (type);
this.is_interface = type.IsInterface || type.IsGenericParameter;
this.member_cache = new MemberCache (this);
}
}
}
- public MemberCache ParentCache {
+ public MemberCache BaseCache {
get {
- return parent_cache;
+ return base_cache;
}
}