Skip to content

Commit cd7172d

Browse files
committed
Added stub for complex_try
1 parent b8ca993 commit cd7172d

File tree

3 files changed

+86
-8
lines changed

3 files changed

+86
-8
lines changed

src/main/java/com/laytonsmith/core/compiler/keywords/TryKeyword.java

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,9 @@
22

33
import com.laytonsmith.core.ParseTree;
44
import com.laytonsmith.core.compiler.Keyword;
5-
import com.laytonsmith.core.constructs.CClassType;
65
import com.laytonsmith.core.constructs.CFunction;
76
import com.laytonsmith.core.constructs.CKeyword;
87
import com.laytonsmith.core.constructs.Construct;
9-
import com.laytonsmith.core.constructs.IVariable;
10-
import com.laytonsmith.core.constructs.Target;
118
import com.laytonsmith.core.exceptions.ConfigCompileException;
129
import java.util.List;
1310

@@ -19,7 +16,6 @@ public class TryKeyword extends Keyword {
1916

2017
// TODO dynamically name this once the class exists.
2118
private static final String COMPLEX_TRY = "complex_try";
22-
private static final String DEFAULT_EXCEPTION_TYPE = "Exception";
2319

2420
@Override
2521
public int process(List<ParseTree> list, int keywordPosition) throws ConfigCompileException {
@@ -109,10 +105,6 @@ public int process(List<ParseTree> list, int keywordPosition) throws ConfigCompi
109105
return keywordPosition;
110106
}
111107

112-
private Construct getData(List<ParseTree> list, int index){
113-
return list.get(index).getData();
114-
}
115-
116108
private boolean nodeIsCatchKeyword(ParseTree node){
117109
return
118110
(node.getData() instanceof CKeyword ||

src/main/java/com/laytonsmith/core/functions/Exceptions.java

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,21 @@
11
package com.laytonsmith.core.functions;
22

33
import com.laytonsmith.PureUtilities.Common.StreamUtils;
4+
import com.laytonsmith.PureUtilities.Version;
45
import com.laytonsmith.abstraction.Implementation;
56
import com.laytonsmith.annotations.MEnum;
67
import com.laytonsmith.annotations.api;
78
import com.laytonsmith.annotations.core;
9+
import com.laytonsmith.annotations.hide;
810
import com.laytonsmith.annotations.seealso;
911
import com.laytonsmith.core.CHVersion;
1012
import com.laytonsmith.core.ObjectGenerator;
13+
import com.laytonsmith.core.Optimizable;
1114
import com.laytonsmith.core.ParseTree;
1215
import com.laytonsmith.core.Prefs;
1316
import com.laytonsmith.core.Script;
1417
import com.laytonsmith.core.SimpleDocumentation;
18+
import com.laytonsmith.core.compiler.FileOptions;
1519
import com.laytonsmith.core.constructs.CArray;
1620
import com.laytonsmith.core.constructs.CClosure;
1721
import com.laytonsmith.core.constructs.CNull;
@@ -28,7 +32,9 @@
2832
import com.laytonsmith.core.exceptions.ConfigRuntimeException;
2933
import java.util.ArrayList;
3034
import java.util.Arrays;
35+
import java.util.EnumSet;
3136
import java.util.List;
37+
import java.util.Set;
3238

3339
/**
3440
*
@@ -595,4 +601,78 @@ public ExampleScript[] examples() throws ConfigCompileException {
595601
}
596602

597603
}
604+
605+
@api
606+
@hide("In general, this should never be used in the functional syntax, and should only be"
607+
+ " automatically generated by the try keyword.")
608+
public static class complex_try extends AbstractFunction implements Optimizable {
609+
610+
@Override
611+
public ExceptionType[] thrown() {
612+
return new ExceptionType[]{};
613+
}
614+
615+
@Override
616+
public boolean isRestricted() {
617+
return false;
618+
}
619+
620+
@Override
621+
public Boolean runAsync() {
622+
return null;
623+
}
624+
625+
@Override
626+
public Construct exec(Target t, Environment environment, Construct... args) throws ConfigRuntimeException {
627+
return CVoid.VOID;
628+
}
629+
630+
@Override
631+
public Construct execs(Target t, Environment env, Script parent, ParseTree... nodes) {
632+
// TODO
633+
return CVoid.VOID;
634+
}
635+
636+
@Override
637+
public String getName() {
638+
return "complex_try";
639+
}
640+
641+
@Override
642+
public Integer[] numArgs() {
643+
return new Integer[]{Integer.MAX_VALUE};
644+
}
645+
646+
@Override
647+
public String docs() {
648+
return "void {tryBlock, [catchVariable, catchBlock]+, [catchBlock]}";
649+
}
650+
651+
@Override
652+
public Version since() {
653+
return CHVersion.V3_3_1;
654+
}
655+
656+
@Override
657+
public ParseTree optimizeDynamic(Target t, List<ParseTree> children, FileOptions fileOptions) throws ConfigCompileException, ConfigRuntimeException {
658+
//TODO
659+
return super.optimizeDynamic(t, children, fileOptions); //To change body of generated methods, choose Tools | Templates.
660+
}
661+
662+
@Override
663+
public Set<OptimizationOption> optimizationOptions() {
664+
return EnumSet.of(OptimizationOption.OPTIMIZE_DYNAMIC);
665+
}
666+
667+
@Override
668+
public boolean preResolveVariables() {
669+
return false;
670+
}
671+
672+
@Override
673+
public boolean useSpecialExec() {
674+
return true;
675+
}
676+
677+
}
598678
}

src/test/java/com/laytonsmith/core/OptimizationTest.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,12 @@ public void testSwitch2() throws Exception {
281281
assertEquals("assign(@b,subtract(dec(@a),2))", optimize("@b = dec(@a)- 2"));
282282
}
283283

284+
@Test public void testTryCatchKeyword() throws Exception {
285+
assertEquals("complex_try(noop(),noop())", optimize("try { noop(); } catch { noop(); }"));
286+
// The remainder of these tests should be written once the feature is complete
287+
//assertEquals("complex_try(noop(),noop())", optimize("try { noop(); } catch(IOException @e) { noop(); }"));
288+
}
289+
284290

285291
//TODO: This is a bit ambitious for now, put this back at some point, and then make it pass.
286292
// @Test public void testAssign() throws Exception{

0 commit comments

Comments
 (0)