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

Add type info action #92

Merged
merged 2 commits into from
Sep 3, 2020
Merged

Conversation

YaPravaATyNet
Copy link
Contributor

No description provided.

Copy link
Owner

@kornilova203 kornilova203 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would add an interface e.g. MatabTypedExpr and add mixins for different expressions that will implement this interface. E.g. one mixin for binary expressions, one mixin for literal expression.
Then you'll be able to show type info for all expressions not only references.

Comment on lines 89 to 94
fun MatlabFunctionDeclaration.isConstructor(): MatlabClassDeclaration? {
val classDeclaration = this.parentOfTypes(MatlabClassDeclaration::class) ?: return null
val className = classDeclaration.getChildOfType(IDENTIFIER)?.text ?: return null
val functionName = this.getChildOfType(IDENTIFIER)?.text ?: return null
return if (className == functionName) classDeclaration else null
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's better to use MatlabClassDeclarationImpl.getName method instead of searching for identifier

Comment on lines 63 to 87
fun getTypeFromBinaryExpr(expr: MatlabBinaryExpr): MatlabType {
val left = getTypeFromExpr(expr.left)
val right = getTypeFromExpr(expr.right)
return when (expr) {
is MatlabAndExpr, is MatlabOrExpr, is MatlabMatrixAndExpr, is MatlabMatrixOrExpr, is MatlabUnaryNegationExpr, is MatlabEqualExpr,
is MatlabNotEqualExpr, is MatlabLessExpr, is MatlabLessOrEqualExpr, is MatlabMoreExpr, is MatlabMoreOrEqualExpr -> MatlabTypeBool()
is MatlabPlusExpr, is MatlabMinusExpr, is MatlabMulExpr, is MatlabRdivExpr, is MatlabLdivExpr, is MatlabPowExpr,
is MatlabElementWiseMulExpr, is MatlabElementWiseLdivExpr, is MatlabElementWiseRdivExpr, is MatlabElementWisePowExpr -> {
when {
left is MatlabTypeScalar && right is MatlabTypeScalar -> MatlabTypeScalar()
left is MatlabTypeMatrix && right is MatlabTypeMatrix -> MatlabTypeMatrix()
left is MatlabTypeMatrix && right is MatlabTypeScalar || right is MatlabTypeMatrix && left is MatlabTypeScalar -> MatlabTypeMatrix()
else -> MatlabTypeUnknown()
}
}
is MatlabUnaryPlusExpr, is MatlabUnaryMinExpr -> {
when (left) {
is MatlabTypeScalar -> MatlabTypeScalar()
is MatlabTypeMatrix -> MatlabTypeMatrix()
else -> MatlabTypeUnknown()
}
}
else -> MatlabTypeUnknown()
}
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be moved to binary expression class. Maybe create a mixin for it?

return SyntaxTraverser.psiApi()
.parents(elementAt)
.takeWhile { it !is PsiFile }
.filter(MatlabRefExpr::class.java)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are able to get type of all expressions not only reference expressions

@YaPravaATyNet
Copy link
Contributor Author

YaPravaATyNet commented Aug 31, 2020

Ok, I thought about mixins and getting type for all expressions (not only for references), but I don't know, how can I cash in this case because ResolveCashe is only for references

@kornilova203
Copy link
Owner

Probably it's okay not to cache types of these elements

@kornilova203 kornilova203 merged commit 1110720 into kornilova203:master Sep 3, 2020
kornilova203 added a commit that referenced this pull request Dec 21, 2020
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

Successfully merging this pull request may close these issues.

2 participants