package de.peeeq.wurstscript.attributes; import de.peeeq.immutablecollections.ImmutableList; import de.peeeq.wurstscript.ast.*; public class ReadVariables { public static ImmutableList calculate(WStatement e) { return generic(e); } public static ImmutableList calculate(StmtSet e) { return e.getRight().attrReadVariables() .cons(generic(e.getUpdatedExpr())); } public static ImmutableList calculate(LocalVarDef e) { return generic(e); } private static ImmutableList generic(Element e) { ImmutableList r = ImmutableList.emptyList(); for (int i = 0; i < e.size(); i++) { if (e.get(i) instanceof HasReadVariables) { HasReadVariables child = (HasReadVariables) e.get(i); r = r.cons(child.attrReadVariables()); } else { r = r.cons(generic(e.get(i))); } } return r; } public static ImmutableList calculate(ExprVarAccess e) { if (e.attrNameLink() != null) { return ImmutableList.of(e.attrNameDef()); } else { return ImmutableList.emptyList(); } } public static ImmutableList calculate(ExprVarArrayAccess e) { ImmutableList r = ImmutableList.emptyList(); if (e.attrNameLink() != null) { r = ImmutableList.of(e.attrNameDef()); } r = r.cons(generic(e.getIndexes())); return r; } public static ImmutableList calculate(ExprMemberArrayVar e) { ImmutableList r = ImmutableList.emptyList(); if (e.attrNameLink() != null) { r = ImmutableList.of(e.attrNameDef()); } r = r.cons(e.getLeft().attrReadVariables()); r = r.cons(generic(e.getIndexes())); return r; } public static ImmutableList calculate(ExprBinary e) { return e.getLeft().attrReadVariables() .cons(e.getRight().attrReadVariables()); } public static ImmutableList calculate(ExprCast e) { return e.getExpr().attrReadVariables(); } public static ImmutableList calculate(ExprIncomplete e) { return ImmutableList.emptyList(); } public static ImmutableList calculate(ExprInstanceOf e) { return e.getExpr().attrReadVariables(); } public static ImmutableList calculate(ExprUnary e) { return e.getRight().attrReadVariables(); } public static ImmutableList calculate(ExprBoolVal e) { return ImmutableList.emptyList(); } public static ImmutableList calculate(ExprIntVal e) { return ImmutableList.emptyList(); } public static ImmutableList calculate(ExprNull e) { return ImmutableList.emptyList(); } public static ImmutableList calculate(ExprRealVal e) { return ImmutableList.emptyList(); } public static ImmutableList calculate(ExprStringVal e) { return ImmutableList.emptyList(); } public static ImmutableList calculate(ExprSuper e) { return generic(e); } public static ImmutableList calculate(ExprThis e) { return ImmutableList.emptyList(); } public static ImmutableList calculate(ExprFuncRef exprFuncRef) { return ImmutableList.emptyList(); } public static ImmutableList calculate(ExprTypeId e) { return e.getLeft().attrReadVariables(); } public static ImmutableList calculate(ExprClosure e) { return e.getImplementation().attrReadVariables(); } public static ImmutableList calculate(ExprStatementsBlock e) { // TODO not sure what to do here return generic(e); // return ImmutableList.emptyList(); } public static ImmutableList calculate(ExprDestroy e) { return e.getDestroyedObj().attrReadVariables(); } public static ImmutableList calculate(FunctionImplementation e) { return generic(e); } public static ImmutableList calculate(ClassDef e) { return generic(e); } public static ImmutableList calculate(CompilationUnit e) { return generic(e); } public static ImmutableList calculate(ConstructorDef e) { return generic(e); } public static ImmutableList calculate(EnumDef e) { return generic(e); } public static ImmutableList calculate(InitBlock e) { return generic(e); } public static ImmutableList calculate(InterfaceDef e) { return generic(e); } public static ImmutableList calculate(ModuleDef e) { return generic(e); } public static ImmutableList calculate(ModuleInstanciation e) { return generic(e); } public static ImmutableList calculate(NativeFunc e) { return generic(e); } public static ImmutableList calculate(OnDestroyDef e) { return generic(e); } public static ImmutableList calculate(TupleDef e) { return generic(e); } public static ImmutableList calculate(WEntities e) { return generic(e); } public static ImmutableList calculate(WPackage e) { return generic(e); } public static ImmutableList calculate(WurstModel e) { return generic(e); } public static ImmutableList calculate(WStatements e) { return generic(e); } public static ImmutableList calculate(ExprEmpty exprEmpty) { return ImmutableList.emptyList(); } public static ImmutableList calculate(ExprIfElse e) { return generic(e); } }