Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Does this have support for inline namespaces? #6

Open
friuns2 opened this issue May 12, 2022 · 3 comments
Open

Does this have support for inline namespaces? #6

friuns2 opened this issue May 12, 2022 · 3 comments

Comments

@friuns2
Copy link
Contributor

friuns2 commented May 12, 2022

for example this works fine
using UnityEngine;
Debug.Log("test");

but when i type
UnityEngine.Debug.Log("test");

it says UnityEngine not found

@friuns2 friuns2 changed the title Does this have support for inline namespaces Does this have support for inline namespaces? May 12, 2022
@pjc0247
Copy link
Owner

pjc0247 commented May 12, 2022

No, that's one of the misimplemented part of this project.

TypeResolver only tries to find the typename with the first token. (in this case, it will be UnityEngine not a Debug)

public HybType GetType(string id, Assembly hintAssembly = null)
{
HybType type = null;
if (cache.TryGetValue(id, out type))
return type;
type = FindType(id, hintAssembly);
cache[id] = type;
return type;
}
private HybType FindType(string id, Assembly hintAssembly = null)
{
if (id == "void") return HybType.Void;
else if (id == "int") return HybType.Int32;
else if (id == "char") return HybType.Char;
else if (id == "byte") return HybType.Byte;
else if (id == "sbyte") return HybType.Sbyte;
else if (id == "bool") return HybType.Bool;
else if (id == "short") return HybType.Short;
else if (id == "ushort") return HybType.Ushort;
else if (id == "string") return HybType.String;
else if (id == "float") return HybType.Float;
else if (id == "double") return HybType.Double;
else if (id == "decimal") return HybType.Decimal;
else if (id == "uint") return HybType.Uint32;
else if (id == "long") return HybType.Int64;
else if (id == "ulong") return HybType.Uint64;
else if (id == "object") return HybType.Object;
if (ctx.Types.ContainsKey(id))
return new HybType(ctx.Types[id]);
if (hintAssembly != null)
{
var type = FindTypeFromAssembly(id, hintAssembly);
if (type != null)
return type;
}
foreach (var asm in assemblies)
{
if (asm == hintAssembly)
continue;
var type = FindTypeFromAssembly(id, asm);
if (type != null)
return type;
}
return null;
}
private HybType FindTypeFromAssembly(string id, Assembly assembly)
{
foreach (var type in assembly.GetTypesSafe())
{
if (type.Name == id &&
namespaces.Contains(type.Namespace))
return HybTypeCache.GetHybType(type);
if (type.FullName == id)
return HybTypeCache.GetHybType(type);
}
return null;
}
}
}

@pjc0247
Copy link
Owner

pjc0247 commented May 12, 2022

Oh, forget about the answer abote.
FindType seems fine.

I think the problem is here:

private HybInstance RunInvocation(InvocationExpressionSyntax node)
{
string calleeId = "";
string targetId = "";
HybInstance callee = null;
SSMethodInfo[] callsite = null;
HybType[] implicitGenericArgs = null;
var (args, hasRefOrOut) = ResolveArgumentList(node.ArgumentList);
if (node.Expression is MemberAccessExpressionSyntax ma)
{
var leftIsType = false;
var rightName = $"{ma.Name.Identifier}";
implicitGenericArgs = ResolveGenericArgumentsFromName(ma.Name);
if (ma.Expression is PredefinedTypeSyntax pd)
{
HybType leftType = null;
leftIsType = true;
leftType = Resolver.GetType($"{pd}");
callsite = leftType.GetStaticMethods(rightName);
}
else if (ma.Expression is IdentifierNameSyntax id)
{
HybType leftType = null;
if (Resolver.TryGetType($"{id.Identifier}", out leftType))
{
leftIsType = true;
callsite = leftType.GetStaticMethods(rightName);
}
else
{
callee = ResolveId(id);
callsite = callee.GetMethods(rightName);
}
calleeId = $"{id.Identifier}";
}
else if (ma.Expression is ExpressionSyntax expr)
{
callee = RunExpression(expr);
callsite = callee.GetMethods($"{ma.Name}");
}
if (leftIsType == false &&
callsite.Length == 0)
{
callsite = ExtResolver.GetCallableExtensions(callee, $"{ma.Name}");
args = (new HybInstance[] { callee }).Concat(args).ToArray();
}
targetId = $"{ma.Name}";
//callsite = ResolveMemberAccess(node.Expression as MemberAccessExpressionSyntax);
}
else if (node.Expression is SimpleNameSyntax ||
node.Expression is MemberBindingExpressionSyntax)
{
if (node.Expression is IdentifierNameSyntax ids)
{
HybInstance v;
if (TryResolveId(ids.Identifier.Text, out v))
{
implicitGenericArgs = ResolveGenericArgumentsFromName(ids);
callee = v;
callsite = v.GetMethods("Invoke");
}
}
if (callsite == null)
{
SimpleNameSyntax id = node.Expression as SimpleNameSyntax;
if (id == null)
{
id = (node.Expression as MemberBindingExpressionSyntax)?.Name;
callee = Ctx._bound;
}
else
callee = Ctx._this;
implicitGenericArgs = ResolveGenericArgumentsFromName(id);
callsite =
ResolveLocalMember(id)
.Concat(Ctx.Method.DeclaringType.GetStaticMethods(id.Identifier.Text))
.ToArray();
targetId = id.Identifier.Text;
}
}
if (callsite.Length == 0)
throw new NoSuchMethodException($"{calleeId}", targetId);
var method = OverloadingResolver.FindMethodWithArguments(
Resolver,
callsite,
implicitGenericArgs.ToArray(),
ref args);
if (method == null)
throw new SemanticViolationException($"No matching override for `{targetId}`");
if (callee != null && method.DeclaringType.Parent == callee.GetHybType())
callee = callee.Parent;
var target = method.Target;
if (target.IsCompiled && traps.ContainsKey(target.CompiledMethod))
target = new Invokable(traps[target.CompiledMethod]);
var ret = target.Invoke(callee, args, hasRefOrOut);
// post-invoke
if (hasRefOrOut)
{
var count = 0;
foreach (var arg in node.ArgumentList.Arguments)
{
if (arg.RefKindKeyword != null)
RunAssign(arg.Expression, args[count]);
count++;
}
}
return ret;
}

which is really complicated. (so many cases to resolve call syntax)

@friuns2
Copy link
Contributor Author

friuns2 commented May 13, 2022

then i use namespaces for now :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants