Skip to content

Commit d78a050

Browse files
committed
Merge branch 'develop'
2 parents 15f7b74 + ec63486 commit d78a050

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+790
-6247
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ jdk:
77

88
#
99
script:
10-
ant build-all test-all
10+
ant test-all

CONTRIBUTING.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,4 @@ Signed-off-by: Henry J. Wylde <public@hjwylde.com>
6363
Signed-off-by: Mark Utting <bm.utting@gmail.com>
6464
Signed-off-by: Drew Stratford <drewstratford@outlook.com>
6565
Signed-off-by: Rich Dougherty <rich@rd.gen.nz>
66+
Signed-off-by: Sebastian Schweizer <sebastian@schweizer.tel>

config.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<!-- Get the root directory of the project by looking at the directory enclosing this file. -->
33
<dirname property="rootdir" file="${ant.file.BuildConfig}"/>
44
<!-- Set the current Whiley version -->
5-
<property name="version" value="0.3.38"/>
5+
<property name="version" value="0.3.39"/>
66
<!-- Load the Maven Ant tasks so that we can work with Maven repositories. -->
77
<typedef uri="urn:maven-ant"
88
classpath="${rootdir}/lib/maven-ant-tasks-2.1.3.jar"

modules/wyc/build.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,18 @@
4141
</javac>
4242
</target>
4343

44+
<!-- Set the default value of this property. Since Ant properties are immutable
45+
if the value has already been set by the user with -Dtest.name.contains=...
46+
this will not override that value. -->
47+
<property name="test.name.contains" value=""/>
48+
4449
<target name="test" depends="test-compile-wyc">
4550
<junit fork="true" dir="${basedir}" failureProperty="tests.failed" printsummary="yes" outputtoformatters="true">
4651
<classpath>
4752
<pathelement path="src:../wyil/src:../wybs/src/:../wycs/src:../../${WYRL_JAR}"/>
4853
<path refid="junit.classpath"/>
4954
</classpath>
55+
<sysproperty key="test.name.contains" value="${test.name.contains}"/>
5056
<batchtest>
5157
<fileset dir="src" includes="wyc/testing/*Tests.java"/>
5258
</batchtest>

modules/wyc/src/wyc/builder/CodeGenerator.java

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,8 @@ private void generate(Stmt stmt, Environment environment,
390390
generate((Return) stmt, environment, codes, context);
391391
} else if (stmt instanceof Debug) {
392392
generate((Debug) stmt, environment, codes, context);
393+
} else if (stmt instanceof Fail) {
394+
generate((Fail) stmt, environment, codes, context);
393395
} else if (stmt instanceof IfElse) {
394396
generate((IfElse) stmt, environment, codes, context);
395397
} else if (stmt instanceof Switch) {
@@ -809,6 +811,36 @@ private void generate(Stmt.Debug s, Environment environment,
809811
codes.add(Codes.Debug(operand), attributes(s));
810812
}
811813

814+
/**
815+
* Translate a fail statement into WyIL bytecodes.
816+
*
817+
* <pre>
818+
* fail
819+
* </pre>
820+
*
821+
* A fail statement is always translated into a WyIL fail bytecode:
822+
*
823+
* <pre>
824+
* fail
825+
* </pre>
826+
*
827+
* @param stmt
828+
* --- Statement to be translated.
829+
* @param environment
830+
* --- Mapping from variable names to block registers.
831+
* @param codes
832+
* --- Code block into which this statement is to be translated.
833+
* @param context
834+
* --- Enclosing context of this statement (i.e. type, constant,
835+
* function or method declaration). The context is used to aid
836+
* with error reporting as it determines the enclosing file.
837+
* @return
838+
*/
839+
private void generate(Stmt.Fail s, Environment environment,
840+
AttributedCodeBlock codes, Context context) {
841+
codes.add(Codes.Fail(), attributes(s));
842+
}
843+
812844
/**
813845
* Translate an if statement into WyIL bytecodes. This is done by first
814846
* translating the condition into one or more conditional branches. The true
@@ -2274,8 +2306,8 @@ public void buildVariableDeclarations(Stmt stmt,
22742306
WhileyFile.Context context) {
22752307
if (stmt instanceof Assign || stmt instanceof Assert
22762308
|| stmt instanceof Assume || stmt instanceof Return
2277-
|| stmt instanceof Debug || stmt instanceof Break
2278-
|| stmt instanceof Continue
2309+
|| stmt instanceof Debug || stmt instanceof Fail
2310+
|| stmt instanceof Break || stmt instanceof Continue
22792311
|| stmt instanceof Expr.MethodCall
22802312
|| stmt instanceof Expr.IndirectMethodCall
22812313
|| stmt instanceof Expr.FunctionCall

modules/wyc/src/wyc/builder/FlowTypeChecker.java

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,10 @@ private Environment propagate(ArrayList<Stmt> block, Environment environment) {
351351
* @return
352352
*/
353353
private Environment propagate(Stmt stmt, Environment environment) {
354-
354+
if (environment == BOTTOM) {
355+
syntaxError(errorMessage(UNREACHABLE_CODE), filename, stmt);
356+
return null; // dead code
357+
}
355358
try {
356359
if (stmt instanceof Stmt.VariableDeclaration) {
357360
return propagate((Stmt.VariableDeclaration) stmt, environment);
@@ -375,6 +378,8 @@ private Environment propagate(Stmt stmt, Environment environment) {
375378
return propagate((Stmt.Assert) stmt, environment);
376379
} else if (stmt instanceof Stmt.Assume) {
377380
return propagate((Stmt.Assume) stmt, environment);
381+
} else if (stmt instanceof Stmt.Fail) {
382+
return propagate((Stmt.Fail) stmt, environment);
378383
} else if (stmt instanceof Stmt.Debug) {
379384
return propagate((Stmt.Debug) stmt, environment);
380385
} else if (stmt instanceof Stmt.Skip) {
@@ -428,6 +433,21 @@ private Environment propagate(Stmt.Assume stmt, Environment environment) {
428433
return environment;
429434
}
430435

436+
/**
437+
* Type check a fail statement. The environment after a fail statement is
438+
* "bottom" because that represents an unreachable program point.
439+
*
440+
* @param stmt
441+
* Statement to type check
442+
* @param environment
443+
* Determines the type of all variables immediately going into
444+
* this block
445+
* @return
446+
*/
447+
private Environment propagate(Stmt.Fail stmt, Environment environment) {
448+
return BOTTOM;
449+
}
450+
431451
/**
432452
* Type check a variable declaration statement. This must associate the
433453
* given variable with either its declared and actual type in the
@@ -525,8 +545,8 @@ private Expr.AssignedVariable inferAfterType(Expr.LVal lv, Nominal afterType) {
525545
} else if (lv instanceof Expr.Dereference) {
526546
Expr.Dereference pa = (Expr.Dereference) lv;
527547
// The before and after types are the same since an assignment
528-
// through a reference does not change its type.
529-
checkIsSubtype(pa.srcType, Nominal.Reference(afterType), lv);
548+
// through a reference does not change its type.
549+
checkIsSubtype(pa.srcType.element(), afterType, lv);
530550
return inferAfterType((Expr.LVal) pa.src, pa.srcType);
531551
} else if (lv instanceof Expr.IndexOf) {
532552
Expr.IndexOf la = (Expr.IndexOf) lv;

0 commit comments

Comments
 (0)