Skip to content

Commit

Permalink
**** Merged from MCS ****
Browse files Browse the repository at this point in the history
svn path=/trunk/mcs/; revision=35947
  • Loading branch information
Martin Baulig committed Nov 10, 2004
1 parent dba4e47 commit 23e223e
Show file tree
Hide file tree
Showing 21 changed files with 694 additions and 106 deletions.
2 changes: 1 addition & 1 deletion mcs/gmcs/AssemblyInfo.cs
@@ -1,7 +1,7 @@
using System.Reflection;
using System.Runtime.CompilerServices;

[assembly: AssemblyVersion("1.1.1")]
[assembly: AssemblyVersion("1.1.2")]
[assembly: AssemblyTitle ("Mono C# Compiler")]
[assembly: AssemblyDescription ("Mono C# Compiler with Generics")]
[assembly: AssemblyCopyright ("2001, 2002, 2003 Ximian, Inc.")]
Expand Down
164 changes: 164 additions & 0 deletions mcs/gmcs/ChangeLog
@@ -1,3 +1,167 @@
2004-11-07 Miguel de Icaza <miguel@ximian.com>

* expression.cs (Invocation.OverloadResolve): Flag error if we are
calling an unsafe method from a safe location.

2004-11-06 Marek Safar <marek.safar@seznam.cz>

Fix #69167
* codegen.cs (ApplyAttributeBuilder): Do not return; it is only warning.

2004-11-06 Miguel de Icaza <miguel@ximian.com>

* namespace.cs (VerifyUsing): use GetPartialName instead of
ToString.

2004-11-05 Miguel de Icaza <miguel@ximian.com>

* statement.cs (Return.Resolve): Fix regression in typo: if
`in_exc', we have to request a NeedReturnLabel, this was a typo
introduced in the anonymous method check-in. Fixes #69131.

* Indexers were using the ShortName when defining themselves,
causing a regression in the compiler bootstrap when applying the
patch from 2004-11-02 (first part), now they use their full name
and the bug is gone.

2004-11-04 Zoltan Varga <vargaz@freemail.hu>

* driver.cs: Strip the path from the names of embedded resources. Fixes
#68519.

2004-11-04 Raja R Harinath <rharinath@novell.com>

Fix error message regression: cs0104-2.cs.
* namespace.cs (NamespaceEntry.Lookup): Remove 'silent' flag.
(AliasEntry.Resolve): Update.
* rootcontext.cs (RootContext.NamespaceLookup): Update. Remove
'silent' flag.
(RootContext.LookupType): Update.

2004-11-03 Carlos Alberto Cortez <carlos@unixmexico.org>

* cs-parser.jay: Add support for handling accessor modifiers
* class: Add support port accessor modifiers and error checking,
define PropertyMethod.Define as virtual (not abstract anymore)
* ecore.cs: Add checking for proeprties access with access modifiers
* iterators.cs: Modify Accessor constructor call based in the modified
constructor
2004-11-02 Ben Maurer <bmaurer@ximian.com>

* expression.cs (StringConcat): Handle being called twice,
as when we have a concat in a field init with more than two
ctors in the class

2004-11-02 Miguel de Icaza <miguel@ximian.com>

* class.cs (Event.Define, Indexer.Define, Property.Define): Do not
special case explicit implementations, we should always produce
the .property or .event declaration.

* decl.cs (MemberName): Renamed GetFullName to GetPartialName
since it will not return correct data if people use this
unresolved in the presence of using statements (see test-313).

* class.cs (MethodData.Define): If we are an explicit interface
implementation, set the method name to the full name of the
interface plus the name of the method.

Notice that using the method.MethodName.GetFullName() does not
work, as it will only contain the name as declared on the source
file (it can be a shorthand in the presence of using statements)
and not the fully qualifed type name, for example:

using System;

class D : ICloneable {
object ICloneable.Clone () {
}
}

Would produce a method called `ICloneable.Clone' instead of
`System.ICloneable.Clone'.

* namespace.cs (Alias.Resolve): Use GetPartialName.

2004-11-01 Marek Safar <marek.safar@seznam.cz>

* cs-parser.jay: Add error 1055 report.

2004-11-01 Miguel de Icaza <miguel@ximian.com>

* assign.cs (Assign.DoResolve): Only do the transform of
assignment into a New if the types are compatible, if not, fall
through and let the implicit code deal with the errors and with
the necessary conversions.

2004-11-01 Marek Safar <marek.safar@seznam.cz>

* cs-parser.jay: Add error 1031 report.

* cs-tokenizer.cs: Add location for error 1038.

2004-10-31 Marek Safar <marek.safar@seznam.cz>

* cs-parser.jay: Add error 1016 report.

2004-10-31 Marek Safar <marek.safar@seznam.cz>

* cs-parser.jay: Add errors 1575,1611 report.

2004-10-31 Marek Safar <marek.safar@seznam.cz>

* cs-parser.jay: Add error 1001 report.

2004-10-31 Marek Safar <marek.safar@seznam.cz>

Fix #68850
* attribute.cs (GetMarshal): Add method argument for
caller identification.

* class.cs, codegen.cs, enum.cs, parameter.cs: Added
agument for GetMarshal and RuntimeMissingSupport.

2004-10-31 Marek Safar <marek.safar@seznam.cz>

* attribute.cs (ExtractSecurityPermissionSet): Removed
TypeManager.code_access_permission_type.

* typemanager.cs: Removed TypeManager.code_access_permission_type.

2004-10-27 Miguel de Icaza <miguel@ximian.com>

* expression.cs (LocalVariableReference.DoResolveLValue): Check
for obsolete use of a variable here. Fixes regression on errors
cs0619-25 and cs0619-26.

2004-10-27 Marek Safar <marek.safar@seznam.cz>

Fix #62358, implemented security attribute encoding.

* attribute.cs (Attribute.CheckSecurityActionValididy): New method.
Tests permitted SecurityAction for assembly or other types.
(Assembly.ExtractSecurityPermissionSet): New method. Transforms
data from SecurityPermissionAttribute to PermisionSet class.

* class.cs (ApplyAttributeBuilder): Added special handling
for System.Security.Permissions.SecurityAttribute based types.

* codegen.cs (AssemblyClass.ApplyAttributeBuilder): Added
special handling for System.Security.Permissions.SecurityAttribute
based types.

* enum.cs (ApplyAttributeBuilder): Added special handling
for System.Security.Permissions.SecurityAttribute based types.

* parameter.cs (ApplyAttributeBuilder): Added special handling
for System.Security.Permissions.SecurityAttribute based types.

* rootcontext.cs: Next 2 core types.

* typemanager.cs (TypeManager.security_permission_attr_type):
Built in type for the SecurityPermission Attribute.
(code_access_permission_type): Build in type.

2004-10-17 Miguel de Icaza <miguel@ximian.com>

* expression.cs (LocalVariableReference.DoResolveBase, Emit):
Expand Down
25 changes: 13 additions & 12 deletions mcs/gmcs/assign.cs
Expand Up @@ -393,16 +393,6 @@ public override Expression DoResolve (EmitContext ec)
return null;
}

if (source is New && target_type.IsValueType &&
(target.eclass != ExprClass.IndexerAccess) && (target.eclass != ExprClass.PropertyAccess)){
New n = (New) source;

if (n.SetValueTypeVariable (target))
return n;
else
return null;
}

if ((source.eclass == ExprClass.Type) && (source is TypeExpr)) {
source.Error_UnexpectedKind ("variable or value", loc);
return null;
Expand All @@ -413,9 +403,20 @@ public override Expression DoResolve (EmitContext ec)

}

if (target_type == source_type)
if (target_type == source_type){
if (source is New && target_type.IsValueType &&
(target.eclass != ExprClass.IndexerAccess) && (target.eclass != ExprClass.PropertyAccess)){
New n = (New) source;

if (n.SetValueTypeVariable (target))
return n;
else
return null;
}

return this;

}

//
// If this assignemnt/operator was part of a compound binary
// operator, then we allow an explicit conversion, as detailed
Expand Down
135 changes: 133 additions & 2 deletions mcs/gmcs/attribute.cs
Expand Up @@ -18,6 +18,8 @@
using System.Reflection.Emit;
using System.Runtime.InteropServices;
using System.Runtime.CompilerServices;
using System.Security;
using System.Security.Permissions;
using System.Text;

namespace Mono.CSharp {
Expand Down Expand Up @@ -130,6 +132,20 @@ static void Error_TypeParameterInAttribute (Location loc)
-202, loc, "Can not use a type parameter in an attribute");
}

/// <summary>
/// This is rather hack. We report many emit attribute error with same error to be compatible with
/// csc. But because csc has to report them this way because error came from ilasm we needn't.
/// </summary>
public void Error_AttributeEmitError (string inner)
{
Report.Error (647, Location, "Error emitting '{0}' attribute because '{1}'", Name, inner);
}

public void Error_InvalidSecurityParent ()
{
Error_AttributeEmitError ("it is attached to invalid parent");
}

void Error_AttributeConstructorMismatch ()
{
Report.Error (-6, Location,
Expand Down Expand Up @@ -718,6 +734,108 @@ public bool GetClsCompliantAttributeValue (DeclSpace ds)
return (bool)pos_values [0];
}

/// <summary>
/// Tests permitted SecurityAction for assembly or other types
/// </summary>
public bool CheckSecurityActionValidity (bool for_assembly)
{
SecurityAction action = GetSecurityActionValue ();

if ((action == SecurityAction.RequestMinimum || action == SecurityAction.RequestOptional || action == SecurityAction.RequestRefuse) && for_assembly)
return true;

if (!for_assembly) {
if (action < SecurityAction.Demand || action > SecurityAction.InheritanceDemand) {
Error_AttributeEmitError ("SecurityAction is out of range");
return false;
}

if ((action != SecurityAction.RequestMinimum && action != SecurityAction.RequestOptional && action != SecurityAction.RequestRefuse) && !for_assembly)
return true;
}

Error_AttributeEmitError (String.Concat ("SecurityAction '", action, "' is not valid for this declaration"));
return false;
}

System.Security.Permissions.SecurityAction GetSecurityActionValue ()
{
return (SecurityAction)pos_values [0];
}

/// <summary>
/// Creates instance of SecurityAttribute class and add result of CreatePermission method to permission table.
/// </summary>
/// <returns></returns>
public void ExtractSecurityPermissionSet (ListDictionary permissions)
{
if (TypeManager.LookupDeclSpace (Type) != null && RootContext.StdLib) {
Error_AttributeEmitError ("security custom attributes can not be referenced from defining assembly");
return;
}

SecurityAttribute sa;
// For all assemblies except corlib we can avoid all hacks
if (RootContext.StdLib) {
sa = (SecurityAttribute) Activator.CreateInstance (Type, pos_values);

if (prop_info_arr != null) {
for (int i = 0; i < prop_info_arr.Length; ++i) {
PropertyInfo pi = prop_info_arr [i];
pi.SetValue (sa, prop_values_arr [i], null);
}
}
} else {
Type temp_type = Type.GetType (Type.FullName);
// HACK: All mscorlib attributes have same ctor syntax
sa = (SecurityAttribute) Activator.CreateInstance (temp_type, new object[] { GetSecurityActionValue () } );

// All types are from newly created corlib but for invocation with old we need to convert them
if (prop_info_arr != null) {
for (int i = 0; i < prop_info_arr.Length; ++i) {
PropertyInfo emited_pi = prop_info_arr [i];
PropertyInfo pi = temp_type.GetProperty (emited_pi.Name, emited_pi.PropertyType);

object old_instance = pi.PropertyType.IsEnum ?
System.Enum.ToObject (pi.PropertyType, prop_values_arr [i]) :
prop_values_arr [i];

pi.SetValue (sa, old_instance, null);
}
}
}

IPermission perm = sa.CreatePermission ();
SecurityAction action;

// 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 ()) {
case SecurityAction.Demand:
action = (SecurityAction)13;
break;
case SecurityAction.LinkDemand:
action = (SecurityAction)14;
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);
permissions.Add (action, ps);
}
ps.AddPermission (sa.CreatePermission ());
}

object GetValue (object value)
{
if (value is EnumConstant)
Expand Down Expand Up @@ -745,17 +863,25 @@ object GetFieldValue (string name)
return null;
}

public UnmanagedMarshal GetMarshal ()
public UnmanagedMarshal GetMarshal (Attributable attr)
{
object value = GetFieldValue ("SizeParamIndex");
if (value != null && UnmanagedType != UnmanagedType.LPArray) {
Error_AttributeEmitError ("SizeParamIndex field is not valid for the specified unmanaged type");
return null;
}

object o = GetFieldValue ("ArraySubType");
UnmanagedType array_sub_type = o == null ? UnmanagedType.I4 : (UnmanagedType) o;

switch (UnmanagedType) {
case UnmanagedType.CustomMarshaler:
MethodInfo define_custom = typeof (UnmanagedMarshal).GetMethod ("DefineCustom",
BindingFlags.Static | BindingFlags.Public);
if (define_custom == null)
if (define_custom == null) {
Report.RuntimeMissingSupport (Location, "set marshal info");
return null;
}

object [] args = new object [4];
args [0] = GetFieldValue ("MarshalTypeRef");
Expand All @@ -771,6 +897,11 @@ public UnmanagedMarshal GetMarshal ()
return UnmanagedMarshal.DefineSafeArray (array_sub_type);

case UnmanagedType.ByValArray:
FieldMember fm = attr as FieldMember;
if (fm == null) {
Error_AttributeEmitError ("Specified unmanaged type is only valid on fields");
return null;
}
return UnmanagedMarshal.DefineByValArray ((int) GetFieldValue ("SizeConst"));

case UnmanagedType.ByValTStr:
Expand Down

0 comments on commit 23e223e

Please sign in to comment.