Skip to content

Commit

Permalink
Java CG: improve pattern handling for value definitions
Browse files Browse the repository at this point in the history
  • Loading branch information
peterwvj committed Feb 28, 2019
1 parent b522455 commit e26ae7f
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 3 deletions.
@@ -0,0 +1,12 @@
class Entry

values

- = 2;

operations

public static Run : () ==> ?
Run () == return 52;

end Entry
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<testResult type="org.overture.codegen.tests.exec.PatternJavaGenTest">
<result>
<output object="rO0ABXNyAC9vcmcub3ZlcnR1cmUuaW50ZXJwcmV0ZXIudmFsdWVzLk5hdHVyYWxPbmVWYWx1ZQAAAAAAAAABAgAAeHIALG9yZy5vdmVydHVyZS5pbnRlcnByZXRlci52YWx1ZXMuTmF0dXJhbFZhbHVlAAAAAAAAAAECAAB4cgAsb3JnLm92ZXJ0dXJlLmludGVycHJldGVyLnZhbHVlcy5JbnRlZ2VyVmFsdWUAAAAAAAAAAQIAAUoAB2xvbmdWYWx4cgAtb3JnLm92ZXJ0dXJlLmludGVycHJldGVyLnZhbHVlcy5SYXRpb25hbFZhbHVlAAAAAAAAAAECAAB4cgApb3JnLm92ZXJ0dXJlLmludGVycHJldGVyLnZhbHVlcy5SZWFsVmFsdWUAAAAAAAAAAQIAAHhyACxvcmcub3ZlcnR1cmUuaW50ZXJwcmV0ZXIudmFsdWVzLk51bWVyaWNWYWx1ZQAAAAAAAAABAgABRAAFdmFsdWV4cgAlb3JnLm92ZXJ0dXJlLmludGVycHJldGVyLnZhbHVlcy5WYWx1ZQAAAAAAAAABAgAAeHBASgAAAAAAAAAAAAAAAAA0" resource="ValueDefIgnorePattern.vdmpp" value="52"/>
</result>
</testResult>
@@ -0,0 +1,22 @@

import java.util.*;
import org.overture.codegen.runtime.*;

@SuppressWarnings("all")
public class Entry {
private static final Number ignorePattern_1 = 2L;

public static Object Run() {

return 52L;
}

public Entry() {}

public String toString() {

return "Entry{" + "ignorePattern_1 = " + Utils.toString(ignorePattern_1) + "}";
}
}

##########
Expand Up @@ -25,7 +25,6 @@
import java.util.List;

import org.apache.log4j.Logger;
import org.overture.ast.patterns.ATuplePattern;
import org.overture.codegen.ir.INode;
import org.overture.codegen.ir.PIR;
import org.overture.codegen.ir.SExpIR;
Expand All @@ -39,8 +38,22 @@
import org.overture.codegen.ir.declarations.AMethodDeclIR;
import org.overture.codegen.ir.declarations.ARecordDeclIR;
import org.overture.codegen.ir.declarations.AVarDeclIR;
import org.overture.codegen.ir.expressions.*;
import org.overture.codegen.ir.expressions.ABoolLiteralExpIR;
import org.overture.codegen.ir.expressions.ACastUnaryExpIR;
import org.overture.codegen.ir.expressions.ACharLiteralExpIR;
import org.overture.codegen.ir.expressions.AEqualsBinaryExpIR;
import org.overture.codegen.ir.expressions.AFieldExpIR;
import org.overture.codegen.ir.expressions.AFieldNumberExpIR;
import org.overture.codegen.ir.expressions.AIdentifierVarExpIR;
import org.overture.codegen.ir.expressions.AIntLiteralExpIR;
import org.overture.codegen.ir.expressions.AIsOfClassExpIR;
import org.overture.codegen.ir.expressions.ANotUnaryExpIR;
import org.overture.codegen.ir.expressions.APatternMatchRuntimeErrorExpIR;
import org.overture.codegen.ir.expressions.AQuoteLiteralExpIR;
import org.overture.codegen.ir.expressions.ARealLiteralExpIR;
import org.overture.codegen.ir.expressions.ATupleCompatibilityExpIR;
import org.overture.codegen.ir.expressions.AUndefinedExpIR;
import org.overture.codegen.ir.expressions.SVarExpIR;
import org.overture.codegen.ir.name.ATypeNameIR;
import org.overture.codegen.ir.patterns.ABoolPatternIR;
import org.overture.codegen.ir.patterns.ACharPatternIR;
Expand All @@ -62,7 +75,18 @@
import org.overture.codegen.ir.statements.AIfStmIR;
import org.overture.codegen.ir.statements.ALocalPatternAssignmentStmIR;
import org.overture.codegen.ir.statements.ARaiseErrorStmIR;
import org.overture.codegen.ir.types.*;
import org.overture.codegen.ir.types.ABoolBasicTypeIR;
import org.overture.codegen.ir.types.ACharBasicTypeIR;
import org.overture.codegen.ir.types.AErrorTypeIR;
import org.overture.codegen.ir.types.AIntNumericBasicTypeIR;
import org.overture.codegen.ir.types.AQuoteTypeIR;
import org.overture.codegen.ir.types.ARealNumericBasicTypeIR;
import org.overture.codegen.ir.types.ARecordTypeIR;
import org.overture.codegen.ir.types.ASeqSeqTypeIR;
import org.overture.codegen.ir.types.AStringTypeIR;
import org.overture.codegen.ir.types.ATupleTypeIR;
import org.overture.codegen.ir.types.AUnionTypeIR;
import org.overture.codegen.ir.types.AUnknownTypeIR;
import org.overture.codegen.trans.DeclarationTag;
import org.overture.codegen.trans.IterationVarPrefixes;
import org.overture.codegen.trans.assistants.TransAssistantIR;
Expand Down Expand Up @@ -90,6 +114,16 @@ public PatternTrans(IterationVarPrefixes iteVarPrefixes,

this.casesExpNamePrefix = casesExpNamePrefix;
}

@Override
public void caseAFieldDeclIR(AFieldDeclIR node) throws AnalysisException {

//TODO: currently values patterns are replaced by strings
if(node.getName().equals("-"))
{
node.setName(transAssistant.getInfo().getTempVarNameGen().nextVarName(config.getIgnorePatternPrefix()));
}
}

@Override
public void caseALocalPatternAssignmentStmIR(
Expand Down
Expand Up @@ -556,6 +556,7 @@ public SDeclIR caseAValueDefinition(AValueDefinition node, IRInfo question)
throws AnalysisException
{
String access = node.getAccess().getAccess().toString();
//FIXME: patterns should be handled by transformations
String name = node.getPattern().toString();
boolean isStatic = true;
boolean isFinal = true;
Expand Down

0 comments on commit e26ae7f

Please sign in to comment.