Skip to content

Commit

Permalink
Improve processDeclarations() implementation, fixing #142
Browse files Browse the repository at this point in the history
Took 32 minutes
  • Loading branch information
Darkyenus committed Mar 6, 2019
1 parent abbefc1 commit 1af6f93
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,13 @@ protected String getDeclaratorsString() {
@Override
public boolean processDeclarations(@NotNull PsiScopeProcessor processor, @NotNull ResolveState state, @Nullable PsiElement lastParent, @NotNull PsiElement place) {
for (GLSLDeclarator declarator : getDeclarators()) {
if (!processor.execute(declarator, state)) return false;
if (declarator == lastParent)
continue;
if (!processor.execute(declarator, state))
return false;
}

GLSLTypeSpecifier specifier = getTypeSpecifierNode();
return specifier == null || specifier.processDeclarations(processor, state, lastParent, place);
return specifier == null || lastParent == specifier || specifier.processDeclarations(processor, state, lastParent, place);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@
package glslplugin.lang.elements.declarations;

import com.intellij.lang.ASTNode;
import com.intellij.psi.PsiElement;
import com.intellij.psi.ResolveState;
import com.intellij.psi.scope.PsiScopeProcessor;
import glslplugin.lang.elements.statements.GLSLCompoundStatement;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

/**
Expand All @@ -40,6 +44,23 @@ public GLSLCompoundStatement getBody() {
return findChildByClass(GLSLCompoundStatement.class);
}

@Override
public boolean processDeclarations(@NotNull PsiScopeProcessor processor, @NotNull ResolveState state, @Nullable PsiElement lastParent, @NotNull PsiElement place) {
if (lastParent == null) {
// Do not show declarations of parameters to outside scopes
return true;
}

for (GLSLParameterDeclaration parameter : getParameters()) {
if (parameter == lastParent) // TODO(jp): sloppy, parameter is probably not direct child, so this will fail
continue;

if (!parameter.processDeclarations(processor, state, lastParent, place)) return false;
}

return true;
}

@Override
public String toString() {
return "Function Definition: " + getSignature();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,19 @@ public GLSLDeclarator getDeclarator(@NotNull String name) {

@Override
public boolean processDeclarations(@NotNull PsiScopeProcessor processor, @NotNull ResolveState state, @Nullable PsiElement lastParent, @NotNull PsiElement place) {
if (!processor.execute(this, state)) return false;
if (!processor.execute(this, state))
return false;

if (lastParent == null) {
// Do not show declarations of parameters to outside scopes
return true;
}

for (GLSLDeclarator declarator : getDeclarators()) {
if (!processor.execute(declarator, state)) return false;
if (declarator == lastParent)
continue;
if (!processor.execute(declarator, state))
return false;
}
return true;
}
Expand Down
17 changes: 11 additions & 6 deletions src/glslplugin/lang/elements/statements/GLSLCompoundStatement.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
import org.jetbrains.annotations.Nullable;

/**
* GLSLCompoundStatement is ...
* A block of statements, surrounded by {@code { and } }.
* Appears as a scope creator inside functions and as a function body itself.
*
* @author Yngve Devik Hammersland
* Date: Jan 28, 2009
Expand Down Expand Up @@ -62,15 +63,19 @@ public TerminatorScope getTerminatorScope() {
}

@Override
public boolean processDeclarations(@NotNull PsiScopeProcessor processor, @NotNull ResolveState state, @Nullable PsiElement lastParent, @NotNull PsiElement place) {
public boolean processDeclarations(@NotNull PsiScopeProcessor processor, @NotNull ResolveState state,
@Nullable PsiElement lastParent, @NotNull PsiElement place) {
if (lastParent == null) {
// Do not show declarations of nested variables to outside scopes
return true;
}
PsiElement child = lastParent.getPrevSibling();
while (child != null) {
if (!child.processDeclarations(processor, state, lastParent, place)) return false;
child = child.getPrevSibling();

for (GLSLStatement statement : getStatements()) {
if (statement == null)
continue;
if (!statement.processDeclarations(processor, state, lastParent, place)) return false;
}

return true;
}
}
2 changes: 1 addition & 1 deletion src/glslplugin/lang/elements/statements/GLSLStatement.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import org.jetbrains.annotations.NotNull;

/**
* GLSLStatement is ...
* Base for all code statements, such as variable declarations, procedure calls, assignments, compound statements, etc.
*
* @author Yngve Devik Hammersland
* Date: Jan 28, 2009
Expand Down

0 comments on commit 1af6f93

Please sign in to comment.