Skip to content

Commit

Permalink
GH-392 Support effective lookup for return statement
Browse files Browse the repository at this point in the history
  • Loading branch information
dzikoysk committed Mar 14, 2020
1 parent a140bba commit eb8f0a0
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@

package org.panda_lang.framework.design.architecture.statement;

import org.panda_lang.framework.design.architecture.dynamic.Executable;

/**
* Represents block scopes
*/
public interface Block extends Scope {
public interface Block extends Scope, Executable {

}
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,17 @@ public interface Scope extends Statement {
* Add given statement to the current scope
*
* @param statement the statement to add
* @return a cell where the statement was placed
* @return the statement
*/
Cell addStatement(Statement statement);
Statement addStatement(Statement statement);

/**
* Check if scope has effective (statement that is always reachable) statement of the given type
*
* @param statementClass type of statements to search for
* @return true if scope has effective statement of the given type, otherwise false
*/
boolean hasEffective(Class<? extends Statement> statementClass);

/**
* Create variable with given properties in the current scope
Expand Down Expand Up @@ -71,11 +79,11 @@ public interface Scope extends Statement {
List<? extends Variable> getVariables();

/**
* Get all statements wrapped into cells
* Get all statements
*
* @return list of all cells
* @return list of all statements
*/
List<? extends Cell> getCells();
List<? extends Statement> getStatements();

/**
* Get parent scope
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,14 @@ public ConditionalBlock(Scope parent, SourceLocation location, Expression condit
return null;
}

@Override
public boolean hasEffective(Class<? extends Statement> statementClass) {
boolean current = super.hasEffective(statementClass);
boolean otherwise = elseBlock == null || elseBlock.hasEffective(statementClass);

return current && otherwise;
}

public void setElseBlock(Scope elseBlock) {
this.elseBlock = elseBlock;
}
Expand Down

0 comments on commit eb8f0a0

Please sign in to comment.