Permalink
Browse files

A few changes that should go in before merge

  • Loading branch information...
LadyCailin committed Nov 28, 2018
1 parent dca7070 commit 5b15353b0a8d23a6bcf7619263f4383ca9143667
Showing with 218 additions and 44 deletions.
  1. +122 −5 src/main/java/com/laytonsmith/core/MethodScriptCompiler.java
  2. +21 −2 src/main/java/com/laytonsmith/core/Static.java
  3. +1 −1 src/main/java/com/laytonsmith/core/constructs/CBoolean.java
  4. +1 −1 src/main/java/com/laytonsmith/core/constructs/CByteArray.java
  5. +1 −1 src/main/java/com/laytonsmith/core/constructs/CClosure.java
  6. +1 −1 src/main/java/com/laytonsmith/core/constructs/CDecimal.java
  7. +1 −1 src/main/java/com/laytonsmith/core/constructs/CDouble.java
  8. +1 −1 src/main/java/com/laytonsmith/core/constructs/CIClosure.java
  9. +1 −1 src/main/java/com/laytonsmith/core/constructs/CInt.java
  10. +1 −1 src/main/java/com/laytonsmith/core/constructs/CNumberRunner.java
  11. +2 −2 src/main/java/com/laytonsmith/core/constructs/CPackage.java
  12. +1 −1 src/main/java/com/laytonsmith/core/constructs/CPrimitiveRunner.java
  13. +1 −1 src/main/java/com/laytonsmith/core/constructs/CResource.java
  14. +1 −1 src/main/java/com/laytonsmith/core/constructs/CSecureString.java
  15. +1 −1 src/main/java/com/laytonsmith/core/constructs/CSlice.java
  16. +4 −0 src/main/java/com/laytonsmith/core/constructs/CSymbol.java
  17. +1 −1 src/main/java/com/laytonsmith/core/exceptions/CRE/CREThrowable.java
  18. +5 −0 src/main/java/com/laytonsmith/core/functions/Compiler.java
  19. +1 −1 src/main/java/com/laytonsmith/core/natives/interfaces/ArrayAccessRunner.java
  20. +2 −2 src/main/java/com/laytonsmith/core/natives/interfaces/MEnumType.java
  21. +3 −0 src/main/java/com/laytonsmith/core/natives/interfaces/Mixed.java
  22. +2 −2 src/main/java/com/laytonsmith/core/natives/interfaces/MixedRunner.java
  23. +2 −2 src/main/java/com/laytonsmith/core/natives/interfaces/{SizableRunner.java → SizeableRunner.java}
  24. +10 −0 src/test/java/com/laytonsmith/core/MethodScriptCompilerTest.java
  25. +31 −15 src/test/java/com/laytonsmith/core/constructs/TestCClassType.java
@@ -9,6 +9,8 @@
import com.laytonsmith.core.compiler.FileOptions;
import com.laytonsmith.core.compiler.KeywordList;
import com.laytonsmith.core.compiler.TokenStream;
import com.laytonsmith.core.constructs.CBareString;
import com.laytonsmith.core.constructs.CClassType;
import com.laytonsmith.core.constructs.CDecimal;
import com.laytonsmith.core.constructs.CDouble;
import com.laytonsmith.core.constructs.CFunction;
@@ -24,6 +26,7 @@
import com.laytonsmith.core.constructs.CVoid;
import com.laytonsmith.core.constructs.Construct;
import com.laytonsmith.core.constructs.IVariable;
import com.laytonsmith.core.constructs.NativeTypeList;
import com.laytonsmith.core.constructs.Target;
import com.laytonsmith.core.constructs.Token;
import com.laytonsmith.core.constructs.Token.TType;
@@ -1240,6 +1243,7 @@ public static ParseTree compile(TokenStream stream) throws ConfigCompileExceptio
//Array notation handling
if(t.type.equals(TType.LSQUARE_BRACKET)) {
//tree.addChild(new ParseTree(new CFunction("__cbracket__", t.getTarget()), fileOptions));
arrayStack.push(new AtomicInteger(tree.getChildren().size() - 1));
continue;
} else if(t.type.equals(TType.RSQUARE_BRACKET)) {
@@ -1484,10 +1488,8 @@ public static ParseTree compile(TokenStream stream) throws ConfigCompileExceptio
throw new ConfigCompileException(ex);
}
} else if(t.type == TType.LIT) {
Construct c = Static.resolveConstruct(t.val(), t.target);
if(c instanceof CString && fileOptions.isStrict()) {
compilerErrors.add(new ConfigCompileException("Bare strings are not allowed in strict mode", t.target));
} else if((c instanceof CInt || c instanceof CDecimal) && next1.type == TType.DOT && next2.type == TType.LIT) {
Construct c = Static.resolveConstruct(t.val(), t.target, true);
if((c instanceof CInt || c instanceof CDecimal) && next1.type == TType.DOT && next2.type == TType.LIT) {
// make CDouble/CDecimal here because otherwise Long.parseLong() will remove
// minus zero before decimals and leading zeroes after decimals
try {
@@ -1623,7 +1625,7 @@ public static ParseTree compile(TokenStream stream) throws ConfigCompileExceptio
}
Stack<List<Procedure>> procs = new Stack<>();
procs.add(new ArrayList<Procedure>());
procs.add(new ArrayList<>());
processKeywords(tree);
optimizeAutoconcats(tree, compilerErrors);
optimize(tree, procs, compilerErrors);
@@ -1746,6 +1748,121 @@ private static void checkBreaks0(ParseTree tree, long currentLoops, String lastU
}
}
// private static void processLinearComponents(ParseTree tree, Set<ConfigCompileException> compilerErrors) {
// if(tree.hasChildren()) {
// for(ParseTree child : tree.getChildren()) {
// processLinearComponents(child, compilerErrors);
// }
// // Process bare string "concatenation"
// for(int i = 0; i < tree.getChildren().size(); i++) {
// ParseTree data = tree.getChildAt(i);
// ParseTree data2 = null;
// if(i < tree.getChildren().size() - 1) {
// data2 = tree.getChildAt(i + 1);
// }
// if(data2 != null) {
// if(data.getData() instanceof CBareString && data2.getData() instanceof CSymbol
// && ((CSymbol) data2.getData()).isConcatenation()) {
//
// }
// }
// }
// }
// // If there are no children, there's nothing to do right now, so just skip this invocation
// }
// private static void processBareStrings(ParseTree root, Set<ConfigCompileException> compilerExceptions) {
// if(root.hasChildren()) {
// for(ParseTree child : root.getChildren()) {
// processBareStrings(child, compilerExceptions);
// }
// }
// // We need to first remove the CBareStrings, and convert them to CStrings (or CClassType or issue a compiler
// // warning, depending on the case), as the rest of these methods assume CStrings.
// List<ParseTree> temp = new ArrayList<>(root.getChildren());
// checkClassType: for(int i = 0; i < temp.size() - 1; i++) {
// ParseTree node = temp.get(i);
// ParseTree next = temp.get(i + 1);
// if(node.getData() instanceof CBareString && next.getData() instanceof CSymbol
// && ((CSymbol) next.getData()).isConcatenation()) {
// // Concatenation of bare strings. We need to look at the whole chain and see if it's a valid
// // type or not, and if not, issue an error.
// String type = node.getData().val() + ".";
// temp.remove(i);
// temp.remove(i);
// for(int j = i; j < temp.size(); j++) {
// ParseTree jNode = temp.get(j);
// ParseTree jNext = null;
// if(j < temp.size() - 1) {
// jNext = temp.get(j + 1);
// }
// if(jNode.getData() instanceof CBareString) {
// type += jNode.getData().val();
// temp.remove(j);
// if(jNext != null && jNext.getData() instanceof CSymbol
// && ((CSymbol) jNext.getData()).isConcatenation()) {
// // Continue the chain
// type += ".";
// temp.remove(j);
// j--;
// } else {
// // End of the chain, break here.
// break;
// }
// } else {
// // This is completely unexpected, and means that we are concatenating a bare string with
// // some other data type. We'll reset list, and let the rest of the code take over.
// temp = root.getChildren();
// break checkClassType;
// }
// }
// // TODO: Once compiler environments are added, we would need to check to see if the value here is a custom
// // type. However, as it stands, since we only support the native types, we will just hardcode the check here.
// String fqType = NativeTypeList.resolveNativeType(type);
// if(fqType != null) {
// try {
// temp.add(i, new ParseTree(CClassType.get(FullyQualifiedClassName
// .forFullyQualifiedClass(fqType)), node.getFileOptions()));
// } catch(ClassNotFoundException ex) {
// throw new RuntimeException(ex);
// }
// } else {
// compilerExceptions.add(new ConfigCompileException("Invalid/Unknown type: " + type, node.getTarget()));
// return;
// }
// i--;
// }
// }
// root.setChildren(temp);
// // Now, any bare strings that remain are an error in strict mode, or need to be converted to CStrings
// // in non-strict mode. There is one exception though, if the string is a class type, then it was a
// // not fully qualified class name, which is allowed, so in that case, we convert it to CClassType.
// for(int i = 0; i < root.getChildren().size(); i++) {
// ParseTree node = root.getChildren().get(i);
// if(node.getData() instanceof CBareString) {
// String fqType = NativeTypeList.resolveNativeType(node.getData().val());
// if(fqType != null) {
// root.getChildren().remove(i);
// try {
// root.getChildren().add(i, new ParseTree(CClassType.get(FullyQualifiedClassName
// .forFullyQualifiedClass(fqType)), node.getFileOptions()));
// } catch(ClassNotFoundException ex) {
// throw new RuntimeException(ex);
// }
// continue;
// }
// if(node.getFileOptions().isStrict()) {
// compilerExceptions.add(new ConfigCompileException("Bare strings are not allowed in strict mode.",
// node.getTarget()));
// } else {
// root.getChildren().remove(i);
// root.getChildren().add(i, new ParseTree(new CString(node.getData().val(), node.getTarget()),
// node.getFileOptions()));
// }
// }
// }
// }
/**
* Optimizing __autoconcat__ out should happen early, and should happen regardless of whether or not optimizations
* are on or off. So this is broken off into a separate optimization procedure, so that the intricacies of the
@@ -22,6 +22,7 @@
import com.laytonsmith.annotations.typeof;
import com.laytonsmith.commandhelper.CommandHelperPlugin;
import com.laytonsmith.core.constructs.CArray;
import com.laytonsmith.core.constructs.CBareString;
import com.laytonsmith.core.constructs.CBoolean;
import com.laytonsmith.core.constructs.CByteArray;
import com.laytonsmith.core.constructs.CClassType;
@@ -458,6 +459,7 @@ public static void checkPlugin(String name, Target t) throws ConfigRuntimeExcept
private static final Pattern VALID_DECIMAL = Pattern.compile("-?0m[0-9]+");
private static final Pattern INVALID_DECIMAL = Pattern.compile("-?0m[0-9]*[^0-9]+[0-9]*");
/**
* Given a string input, creates and returns a Construct of the appropriate type. This takes into account that null,
* true, and false are keywords.
@@ -468,6 +470,22 @@ public static void checkPlugin(String name, Target t) throws ConfigRuntimeExcept
* @throws ConfigRuntimeException If the value is a hex or binary value, but has invalid characters in it.
*/
public static Construct resolveConstruct(String val, Target t) throws ConfigRuntimeException {
return resolveConstruct(val, t, false);
}
/**
* Given a string input, creates and returns a Construct of the appropriate type. This takes into account that null,
* true, and false are keywords.
*
* If returnBareStrings is true, then we don't return CString, we return CBareString.
* @param val
* @param t
* @param returnBareStrings
* @return
* @throws ConfigRuntimeException
*/
public static Construct resolveConstruct(String val, Target t, boolean returnBareStrings)
throws ConfigRuntimeException {
if(val == null) {
return new CString("", t);
}
@@ -523,11 +541,12 @@ public static Construct resolveConstruct(String val, Target t) throws ConfigRunt
// Not a double either
}
}
// TODO: Once compiler environments are added, we would need to check to see if the value here is a custom
// type. However, as it stands, since we only support the native types, we will just hardcode the check here.
String fqType = NativeTypeList.resolveNativeType(val);
if(fqType != null) {
return CClassType.get(fqType);
}
if(returnBareStrings) {
return new CBareString(val, t);
} else {
return new CString(val, t);
}
@@ -126,7 +126,7 @@ public Version since() {
@Override
public CClassType[] getInterfaces() {
return new CClassType[]{};
return CClassType.EMPTY_CLASS_ARRAY;
}
@Override
@@ -609,7 +609,7 @@ public Version since() {
@Override
public CClassType[] getInterfaces() {
return new CClassType[0];
return CClassType.EMPTY_CLASS_ARRAY;
}
@Override
@@ -246,7 +246,7 @@ public Version since() {
@Override
public CClassType[] getInterfaces() {
return new CClassType[]{};
return CClassType.EMPTY_CLASS_ARRAY;
}
}
@@ -70,7 +70,7 @@ public Version since() {
@Override
public CClassType[] getInterfaces() {
return new CClassType[]{};
return CClassType.EMPTY_CLASS_ARRAY;
}
}
@@ -64,7 +64,7 @@ public Version since() {
@Override
public CClassType[] getInterfaces() {
return new CClassType[]{};
return CClassType.EMPTY_CLASS_ARRAY;
}
}
@@ -145,7 +145,7 @@ public Version since() {
@Override
public CClassType[] getInterfaces() {
return new CClassType[]{};
return CClassType.EMPTY_CLASS_ARRAY;
}
}
@@ -63,7 +63,7 @@ public Version since() {
@Override
public CClassType[] getInterfaces() {
return new CClassType[]{};
return CClassType.EMPTY_CLASS_ARRAY;
}
}
@@ -29,7 +29,7 @@ public Version since() {
@Override
public CClassType[] getInterfaces() {
return new CClassType[]{};
return CClassType.EMPTY_CLASS_ARRAY;
}
}
@@ -41,12 +41,12 @@ public Version since() {
@Override
public CClassType[] getSuperclasses() {
return new CClassType[0];
return CClassType.EMPTY_CLASS_ARRAY;
}
@Override
public CClassType[] getInterfaces() {
return new CClassType[0];
return CClassType.EMPTY_CLASS_ARRAY;
}
}
@@ -30,6 +30,6 @@ public Version since() {
@Override
public CClassType[] getInterfaces() {
return new CClassType[]{};
return CClassType.EMPTY_CLASS_ARRAY;
}
}
@@ -118,7 +118,7 @@ public Version since() {
@Override
public CClassType[] getInterfaces() {
return new CClassType[]{};
return CClassType.EMPTY_CLASS_ARRAY;
}
}
@@ -137,7 +137,7 @@ public Version since() {
@Override
public CClassType[] getInterfaces() {
return new CClassType[]{};
return CClassType.EMPTY_CLASS_ARRAY;
}
@Override
@@ -211,6 +211,6 @@ public Version since() {
@Override
public CClassType[] getInterfaces() {
return new CClassType[]{};
return CClassType.EMPTY_CLASS_ARRAY;
}
}
@@ -101,6 +101,10 @@ public String convert() {
return conversion;
}
public boolean isConcatenation() {
return symbolType.equals(Token.TType.CONCAT);
}
public boolean isPostfix() {
return symbolType.isPostfix();
}
@@ -67,7 +67,7 @@ public Version since() {
if(this.getClass() == CREThrowable.class) {
return new CClassType[]{ArrayAccess.TYPE};
} else {
return new CClassType[]{};
return CClassType.EMPTY_CLASS_ARRAY;
}
}
@@ -6,11 +6,13 @@
import com.laytonsmith.annotations.hide;
import com.laytonsmith.annotations.noboilerplate;
import com.laytonsmith.annotations.noprofile;
import com.laytonsmith.core.FullyQualifiedClassName;
import com.laytonsmith.core.MSVersion;
import com.laytonsmith.core.Optimizable;
import com.laytonsmith.core.ParseTree;
import com.laytonsmith.core.Script;
import com.laytonsmith.core.compiler.FileOptions;
import com.laytonsmith.core.constructs.CBareString;
import com.laytonsmith.core.constructs.CBracket;
import com.laytonsmith.core.constructs.CClassType;
import com.laytonsmith.core.constructs.CEntry;
@@ -22,6 +24,7 @@
import com.laytonsmith.core.constructs.CVoid;
import com.laytonsmith.core.constructs.Construct;
import com.laytonsmith.core.constructs.IVariable;
import com.laytonsmith.core.constructs.NativeTypeList;
import com.laytonsmith.core.constructs.Target;
import com.laytonsmith.core.environments.Environment;
import com.laytonsmith.core.exceptions.CRE.CREThrowable;
@@ -34,6 +37,8 @@
import java.util.HashMap;
import java.util.List;
import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
*
Oops, something went wrong.

0 comments on commit 5b15353

Please sign in to comment.