1
0
mirror of https://github.com/twiglet/cs2j.git synced 2025-01-18 13:15:17 +01:00

fix resolve for enums

This commit is contained in:
Kevin Glynn 2011-01-17 18:24:26 +01:00
parent 19550129d8
commit 66094e129b
2 changed files with 105 additions and 84 deletions

View File

@ -838,7 +838,7 @@ namespace RusticiSoftware.Translator.CLR
} }
public override string mkJava() { public override string mkJava() {
return Name; return "${this}." + Name;
} }
@ -908,6 +908,29 @@ namespace RusticiSoftware.Translator.CLR
} }
private string[] _inherits;
[XmlArrayItem("Type")]
public string[] Inherits {
get {
if (_inherits == null)
{
_inherits = new string[] { "System.Object" };
}
return _inherits;
}
set {
if (value != null) {
_inherits= new string[value.Length];
for (int i = 0; i < value.Length; i++) {
_inherits[i] = value[i].Replace('<','[').Replace('>',']');
}
}
else {
_inherits = null;
}
}
}
protected TypeRepTemplate (string typeName) : this() protected TypeRepTemplate (string typeName) : this()
{ {
TypeName = typeName; TypeName = typeName;
@ -937,8 +960,59 @@ namespace RusticiSoftware.Translator.CLR
} }
} }
public virtual ResolveResult Resolve(String name, List<TypeRepTemplate> args, DirectoryHT<TypeRepTemplate> AppEnv)
{
if (Inherits != null)
{
foreach (String b in Inherits)
{
TypeRepTemplate baseType = AppEnv.Search(Uses, b);
if (baseType != null)
{
ResolveResult ret = baseType.Resolve(name,args,AppEnv);
if (ret != null)
return ret;
}
}
}
return null;
}
public virtual ResolveResult Resolve(String name, DirectoryHT<TypeRepTemplate> AppEnv)
{
if (Inherits != null)
{
foreach (String b in Inherits)
{
TypeRepTemplate baseType = AppEnv.Search(Uses, b);
if (baseType != null)
{
ResolveResult ret = baseType.Resolve(name,AppEnv);
if (ret != null)
return ret;
}
}
}
return null;
}
// Returns true if other is a subclass, or implements our interface // Returns true if other is a subclass, or implements our interface
public virtual bool IsA (TypeRepTemplate other, DirectoryHT<TypeRepTemplate> AppEnv) { public virtual bool IsA (TypeRepTemplate other, DirectoryHT<TypeRepTemplate> AppEnv) {
if (other.TypeName == this.TypeName)
{
return true;
}
if (Inherits != null)
{
foreach (String ibase in Inherits)
{
TypeRepTemplate tbase = AppEnv.Search(ibase, new UnknownRepTemplate(ibase));
if (tbase.IsA(other,AppEnv))
{
return true;
}
}
}
return false; return false;
} }
@ -1123,6 +1197,24 @@ namespace RusticiSoftware.Translator.CLR
return new EnumRep (); return new EnumRep ();
} }
public override ResolveResult Resolve(String name, DirectoryHT<TypeRepTemplate> AppEnv)
{
if (Members != null)
{
foreach (EnumMemberRepTemplate m in Members)
{
if (m.Name == name)
{
ResolveResult res = new ResolveResult();
res.Result = m;
res.ResultType = this;
return res;
}
}
}
return base.Resolve(name, AppEnv);
}
#region Equality #region Equality
public bool Equals (EnumRepTemplate other) public bool Equals (EnumRepTemplate other)
{ {
@ -1273,30 +1365,6 @@ namespace RusticiSoftware.Translator.CLR
[XmlType("Interface")] [XmlType("Interface")]
public class InterfaceRepTemplate : TypeRepTemplate, IEquatable<InterfaceRepTemplate> public class InterfaceRepTemplate : TypeRepTemplate, IEquatable<InterfaceRepTemplate>
{ {
private string[] _inherits;
[XmlArrayItem("Type")]
public string[] Inherits {
get {
if (_inherits == null)
{
_inherits = new string[] { "System.Object" };
}
return _inherits;
}
set {
if (value != null) {
_inherits= new string[value.Length];
for (int i = 0; i < value.Length; i++) {
_inherits[i] = value[i].Replace('<','[').Replace('>',']');
}
}
else {
_inherits = null;
}
}
}
private List<MethodRepTemplate> _methods = null; private List<MethodRepTemplate> _methods = null;
[XmlArrayItem("Method")] [XmlArrayItem("Method")]
public List<MethodRepTemplate> Methods { public List<MethodRepTemplate> Methods {
@ -1368,18 +1436,7 @@ namespace RusticiSoftware.Translator.CLR
{ {
return true; return true;
} }
if (Inherits != null) return base.IsA(other,AppEnv);
{
foreach (String ibase in Inherits)
{
TypeRepTemplate tbase = AppEnv.Search(ibase, new UnknownRepTemplate(ibase));
if (tbase.IsA(other,AppEnv))
{
return true;
}
}
}
return false;
} }
public override TypeRep mkEmptyRep () public override TypeRep mkEmptyRep ()
@ -1387,7 +1444,7 @@ namespace RusticiSoftware.Translator.CLR
return new InterfaceRep (); return new InterfaceRep ();
} }
public virtual ResolveResult Resolve(String name, DirectoryHT<TypeRepTemplate> AppEnv) public override ResolveResult Resolve(String name, DirectoryHT<TypeRepTemplate> AppEnv)
{ {
if (Properties != null) if (Properties != null)
@ -1403,23 +1460,10 @@ namespace RusticiSoftware.Translator.CLR
} }
} }
} }
if (Inherits != null) return base.Resolve(name,AppEnv);
{
foreach (String b in Inherits)
{
InterfaceRepTemplate baseType = AppEnv.Search(Uses, b) as InterfaceRepTemplate;
if (baseType != null)
{
ResolveResult ret = baseType.Resolve(name,AppEnv);
if (ret != null)
return ret;
}
}
}
return null;
} }
public virtual ResolveResult Resolve(String name, List<TypeRepTemplate> args, DirectoryHT<TypeRepTemplate> AppEnv) public override ResolveResult Resolve(String name, List<TypeRepTemplate> args, DirectoryHT<TypeRepTemplate> AppEnv)
{ {
if (Methods != null) if (Methods != null)
@ -1464,20 +1508,7 @@ namespace RusticiSoftware.Translator.CLR
} }
} }
} }
if (Inherits != null) return base.Resolve(name, args, AppEnv);
{
foreach (String b in Inherits)
{
InterfaceRepTemplate baseType = AppEnv.Search(Uses, b) as InterfaceRepTemplate;
if (baseType != null)
{
ResolveResult ret = baseType.Resolve(name,args,AppEnv);
if (ret != null)
return ret;
}
}
}
return null;
} }
@ -1553,7 +1584,7 @@ namespace RusticiSoftware.Translator.CLR
public static bool operator != (InterfaceRepTemplate a1, InterfaceRepTemplate a2) public static bool operator != (InterfaceRepTemplate a1, InterfaceRepTemplate a2)
{ {
return !(a1 == a2); return !(a1 == a2);
} }
public override int GetHashCode () public override int GetHashCode ()
{ {

View File

@ -147,16 +147,6 @@ scope SymTab {
return (CommonTree)adaptor.RulePostProcessing(root); return (CommonTree)adaptor.RulePostProcessing(root);
} }
// Resolve Routines
// protected ResolveResult ResolveGetter(InterfaceRepTemplate thisType, String name) {
// ResolveResult ret = null;
// PropRepTemplate entity = thisType.Resolve(name, AppEnv) as PropRepTemplate;
// if (entity != null) {
// ret = entity.JavaGet;
// }
// return ret;
// }
protected CommonTree dupTree(CommonTree t) { protected CommonTree dupTree(CommonTree t) {
return (CommonTree)adaptor.DupTree(t); return (CommonTree)adaptor.DupTree(t);
} }
@ -219,7 +209,7 @@ scope {
@init { @init {
$primary_expression::parentIsApply = false; $primary_expression::parentIsApply = false;
CommonTree ret = null; CommonTree ret = null;
InterfaceRepTemplate expType = SymTabLookup("this") as InterfaceRepTemplate; TypeRepTemplate expType = SymTabLookup("this");
bool implicitThis = true; bool implicitThis = true;
} }
@after { @after {
@ -228,7 +218,7 @@ scope {
}: }:
^(INDEX expression expression_list?) ^(INDEX expression expression_list?)
| (^(APPLY (^('.' expression identifier)|identifier) argument_list?)) => | (^(APPLY (^('.' expression identifier)|identifier) argument_list?)) =>
^(APPLY (^('.' e2=expression {expType = $e2.dotNetType as InterfaceRepTemplate; implicitThis = false;} i2=identifier)|i2=identifier) argument_list?) ^(APPLY (^('.' e2=expression {expType = $e2.dotNetType; implicitThis = false;} i2=identifier)|i2=identifier) argument_list?)
{ {
if (expType != null) { if (expType != null) {
ResolveResult methodResult = expType.Resolve($i2.thetext, $argument_list.argTypes ?? new List<TypeRepTemplate>(), AppEnv); ResolveResult methodResult = expType.Resolve($i2.thetext, $argument_list.argTypes ?? new List<TypeRepTemplate>(), AppEnv);
@ -257,7 +247,7 @@ scope {
// - accessing a property/field of some object // - accessing a property/field of some object
// - a qualified type name // - a qualified type name
// - part of a qualified type name // - part of a qualified type name
expType = $e1.dotNetType as InterfaceRepTemplate; expType = $e1.dotNetType;
// Is it a property read? Ensure we are not being applied to arguments or about to be assigned // Is it a property read? Ensure we are not being applied to arguments or about to be assigned
if (expType != null && if (expType != null &&
@ -307,7 +297,7 @@ scope {
} }
if (!found) { if (!found) {
// Not a variable, is it a property? // Not a variable, is it a property?
InterfaceRepTemplate thisType = SymTabLookup("this") as InterfaceRepTemplate; TypeRepTemplate thisType = SymTabLookup("this");
// Is it a property read? Ensure we are not being applied to arguments or about to be assigned // Is it a property read? Ensure we are not being applied to arguments or about to be assigned
if (thisType != null && if (thisType != null &&
@ -650,7 +640,7 @@ assignment
((^('.' expression identifier generic_argument_list?) | identifier) '=') => ((^('.' expression identifier generic_argument_list?) | identifier) '=') =>
(^('.' se=expression i=identifier generic_argument_list?) | i=identifier { isThis = true;}) a='=' rhs=expression (^('.' se=expression i=identifier generic_argument_list?) | i=identifier { isThis = true;}) a='=' rhs=expression
{ {
InterfaceRepTemplate seType = (isThis ? SymTabLookup("this") : $se.dotNetType) as InterfaceRepTemplate; TypeRepTemplate seType = (isThis ? SymTabLookup("this") : $se.dotNetType);
if (seType != null) { if (seType != null) {
ResolveResult fieldResult = seType.Resolve($i.thetext, AppEnv); ResolveResult fieldResult = seType.Resolve($i.thetext, AppEnv);
if (fieldResult != null && fieldResult.Result is PropRepTemplate) { if (fieldResult != null && fieldResult.Result is PropRepTemplate) {
@ -890,7 +880,7 @@ scope NSContext,SymTab;
$SymTab::symtab["this"] = classTypeRep; $SymTab::symtab["this"] = classTypeRep;
ClassRepTemplate baseType = ObjectType; ClassRepTemplate baseType = ObjectType;
if (classTypeRep.Inherits != null && classTypeRep.Inherits.Length > 0) { if (classTypeRep.Inherits != null && classTypeRep.Inherits.Length > 0) {
// if Inherits[0] is a class tyhen it is parent, else system.object // if Inherits[0] is a class then it is parent, else system.object
ClassRepTemplate parent = AppEnv.Search(classTypeRep.Uses, classTypeRep.Inherits[0], ObjectType) as ClassRepTemplate; ClassRepTemplate parent = AppEnv.Search(classTypeRep.Uses, classTypeRep.Inherits[0], ObjectType) as ClassRepTemplate;
if (parent != null) if (parent != null)
baseType = parent; baseType = parent;