Skip to content

Commit

Permalink
Fixing macro keyword and restoring macro exprOf unwrap in canAssign
Browse files Browse the repository at this point in the history
  • Loading branch information
m0rkeulv committed Jan 28, 2024
1 parent 8c2f421 commit 8137da9
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ CONDITIONAL_ERROR="#error"[^\r\n]*
"never" { return emitToken( KNEVER); }
"override" { return emitToken( KOVERRIDE); }
"inline" { return emitToken( KINLINE); }
"macro" ({WHITE_SPACE_CHAR}+) { return emitToken( KMACRO2); }
"macro" /({WHITE_SPACE_CHAR}+) { return emitToken( KMACRO2); }
"macro:"
{
yypushback(1); // do not consume the colon (but catch the macro keyword)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public interface HaxePsiModifier extends PsiModifier, HaxePsiCompositeElement {
@NonNls String VAR = "var";
@NonNls String OVERRIDE = "override";
@NonNls String OVERLOAD = "overload";
@NonNls String MACRO = "macro";

@NonNls String FINAL_META = "@:final";
@NonNls String INLINE_META = "@:inline"; // HaxeMeta.INLINE
Expand All @@ -48,7 +49,7 @@ public interface HaxePsiModifier extends PsiModifier, HaxePsiCompositeElement {
@NonNls String BIND = "@:bind";
@NonNls String HACK = "@:hack";

@NonNls String MACRO = "@:macro";
@NonNls String MACRO2 = "@:macro";
@NonNls String UNREFLECTIVE = "@:unreflective";

@NonNls String NATIVE = "@:native";
Expand All @@ -66,7 +67,7 @@ public interface HaxePsiModifier extends PsiModifier, HaxePsiCompositeElement {
@NonNls String DEPRECATED = "@:deprecated";

@MagicConstant(stringValues = {
PUBLIC, PRIVATE, EMPTY, STATIC, FINAL, DYNAMIC, ABSTRACT, OVERRIDE, OVERLOAD, FINAL_META, KEEP, IS_VAR, COREAPI, BIND, MACRO, HACK,
PUBLIC, PRIVATE, EMPTY, STATIC, FINAL, DYNAMIC, ABSTRACT, OVERRIDE, OVERLOAD, FINAL_META, KEEP, IS_VAR, COREAPI, BIND, MACRO, MACRO2, HACK,
REQUIRE, FAKEENUM, NATIVE, JSREQUIRE, BITMAP, NS, META, BUILD,
AUTOBUILD, UNREFLECTIVE, DEPRECATED, INLINE
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,15 @@
package com.intellij.plugins.haxe.model;

import com.intellij.openapi.progress.ProcessCanceledException;
import com.intellij.openapi.util.Key;
import com.intellij.plugins.haxe.lang.lexer.HaxeTokenTypes;
import com.intellij.plugins.haxe.lang.psi.*;
import com.intellij.plugins.haxe.lang.psi.impl.AbstractHaxeNamedComponent;
import com.intellij.plugins.haxe.metadata.psi.HaxeMeta;
import com.intellij.plugins.haxe.metadata.util.HaxeMetadataUtils;
import com.intellij.plugins.haxe.model.type.*;
import com.intellij.plugins.haxe.model.type.SpecificFunctionReference.Argument;
import com.intellij.plugins.haxe.model.type.resolver.ResolveSource;
import com.intellij.plugins.haxe.util.UsefulPsiTreeUtil;
import com.intellij.psi.PsiElement;
import com.intellij.psi.util.CachedValue;
import com.intellij.psi.util.CachedValueProvider;
import com.intellij.psi.util.CachedValuesManager;
import lombok.EqualsAndHashCode;
Expand Down Expand Up @@ -188,6 +185,9 @@ public HaxeMethodModel getParentMethod(@Nullable HaxeGenericResolver resolver) {
public boolean isAbstract() {
return hasModifier(HaxePsiModifier.ABSTRACT);
}
public boolean isMacro() {
return hasModifier(HaxePsiModifier.MACRO) || hasModifier(HaxePsiModifier.MACRO2);
}

@Override
public String toString() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,18 +48,25 @@ private static SpecificFunctionReference.Argument resolveMacroTypeForArgument(Sp
return argument;
}

public static ResultHolder resolveMacroType(ResultHolder returnType) {
SpecificHaxeClassReference classReference = returnType.getClassType();
if (classReference == null || classReference.getHaxeClass() == null) return returnType;
public static ResultHolder resolveMacroType(ResultHolder returntype) {
SpecificHaxeClassReference type = returntype.getClassType();
SpecificTypeReference reference = resolveMacroType(type);
return reference == null ? returntype : reference.createHolder();
}
public static SpecificTypeReference resolveMacroType(SpecificHaxeClassReference classReference) {

if (classReference == null || classReference.getHaxeClass() == null) return classReference;
String qualifiedName = classReference.getHaxeClass().getQualifiedName();
return switch (qualifiedName) {
case "haxe.macro.Expr" -> SpecificTypeReference.getDynamic(returnType.getElementContext()).createHolder();
case "haxe.macro.Expr.ExprOf" -> classReference.getSpecifics()[0];
default -> returnType;
case "haxe.macro.Expr" -> SpecificTypeReference.getDynamic(classReference.getElementContext());
case "haxe.macro.Expr.ExprOf" -> classReference.getSpecifics()[0].getClassType();
default -> classReference;
};
}
public static boolean isMacroType(ResultHolder returnType) {
SpecificHaxeClassReference classReference = returnType.getClassType();
return isMacroType(returnType.getClassType());
}
public static boolean isMacroType(SpecificHaxeClassReference classReference) {
if (classReference == null || classReference.getHaxeClass() == null) return false;
String qualifiedName = classReference.getHaxeClass().getQualifiedName();
return switch (qualifiedName) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ static public boolean canAssignToFrom(
if (to == null || from == null) return false;
if (to.isDynamic() || from.isDynamic()) return true;

from = replaceMacroExprIfFromMacroMethod(from, fromOrigin);

if (to instanceof SpecificHaxeClassReference classReference) {
if (classReference.isTypeDef() || classReference.isNullType()) {
Expand Down Expand Up @@ -229,6 +230,18 @@ static public boolean canAssignToFrom(
return false;
}

private static SpecificTypeReference replaceMacroExprIfFromMacroMethod(@NotNull SpecificTypeReference from, @Nullable PsiElement fromOrigin) {
if (from instanceof SpecificHaxeClassReference classReference) {
if (fromOrigin instanceof HaxeMethodDeclaration methodDeclaration) {
HaxeMethodModel model = methodDeclaration.getModel();
if (model != null && model.isMacro() && HaxeMacroUtil.isMacroType(classReference)) {
from = HaxeMacroUtil.resolveMacroType(classReference);
}
}
}
return from;
}

private static List<SpecificTypeReference> getImplicitCast(@NotNull SpecificHaxeClassReference classReference, boolean from) {

HaxeAbstractTypeDeclaration abstractType = (HaxeAbstractTypeDeclaration)classReference.getHaxeClass();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,9 @@ public ResultHolder access(String name, HaxeExpressionEvaluatorContext context,
return null;
}

public void isExprOf() {
}

public enum Compatibility {
ASSIGNABLE_TO, // Assignable via @:to or "to <Type>" on an abstract.
ASSIGNABLE_FROM // Assignable via @:from or "from <Type>" on an abstract.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ Haxe File
HaxePsiToken:{('{')
RETURN_STATEMENT
HaxePsiToken:return('return')
HaxePsiToken:macro('macro ')
HaxePsiToken:macro('macro')
WHILE_STATEMENT
HaxePsiToken:while('while')
HaxePsiToken:(('(')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Haxe File
HaxePsiToken:{('{')
METHOD_DECLARATION
METHOD_MODIFIER
HaxePsiToken:macro('macro ')
HaxePsiToken:macro('macro')
METHOD_MODIFIER
HaxePsiToken:public('public')
HaxePsiToken:function('function')
Expand Down Expand Up @@ -67,7 +67,7 @@ Haxe File
HaxePsiToken:}('}')
METHOD_DECLARATION
METHOD_MODIFIER
HaxePsiToken:macro('macro ')
HaxePsiToken:macro('macro')
METHOD_MODIFIER
HaxePsiToken:public('public')
HaxePsiToken:function('function')
Expand Down Expand Up @@ -101,7 +101,7 @@ Haxe File
HaxePsiToken:;(';')
RETURN_STATEMENT
HaxePsiToken:return('return')
HaxePsiToken:macro('macro ')
HaxePsiToken:macro('macro')
BLOCK_STATEMENT
HaxePsiToken:{('{')
VALUE_EXPRESSION
Expand Down Expand Up @@ -153,7 +153,7 @@ Haxe File
HaxePsiToken:{('{')
RETURN_STATEMENT
HaxePsiToken:return('return')
HaxePsiToken:macro('macro ')
HaxePsiToken:macro('macro')
VALUE_EXPRESSION
MACRO_EXPRESSION_REIFICATION
MACRO_BLOCK_REIFICATION
Expand Down Expand Up @@ -192,7 +192,7 @@ Haxe File
HaxePsiToken:{('{')
RETURN_STATEMENT
HaxePsiToken:return('return')
HaxePsiToken:macro('macro ')
HaxePsiToken:macro('macro')
VALUE_EXPRESSION
MACRO_EXPRESSION_REIFICATION
MACRO_IDENTIFIER_REIFICATION
Expand Down Expand Up @@ -293,7 +293,7 @@ Haxe File
HaxePsiToken:{('{')
RETURN_STATEMENT
HaxePsiToken:return('return')
HaxePsiToken:macro('macro ')
HaxePsiToken:macro('macro')
PARENTHESIZED_EXPRESSION
HaxePsiToken:(('(')
FUNCTION_LITERAL
Expand Down

0 comments on commit 8137da9

Please sign in to comment.