public InOpReference(InOpDeclaration op, Expression lhs, Expression rhs, SourcePosition start = null, SourcePosition end = null) : base(ASTNodeType.InOpRef, start, end) { Operator = op; LeftOperand = lhs; RightOperand = rhs; }
public InOpReference(InOpDeclaration op, Expression lhs, Expression rhs, SourcePosition start, SourcePosition end) : base(ASTNodeType.InOpRef, start, end) { Operator = op; LeftOperand = lhs; RightOperand = rhs; }
public bool GetInOperator(out InOpDeclaration op, String name, VariableType lhs, VariableType rhs) { op = null; var lookup = Operators.FirstOrDefault(opdecl => opdecl.Value.Type == ASTNodeType.InfixOperator && opdecl.Value.OperatorKeyword == name && (opdecl.Value as InOpDeclaration).LeftOperand.VarType.Name.ToLower() == lhs.Name.ToLower() && (opdecl.Value as InOpDeclaration).RightOperand.VarType.Name.ToLower() == rhs.Name.ToLower()); if (lookup.Equals(new KeyValuePair<String, OperatorDeclaration>())) return false; op = lookup.Value as InOpDeclaration; return true; }
// TODO: replace this ugly-ass hack with proper AST support. public Expression DecompileNew() { PopByte(); var parameters = new List<Expression>(); for (int n = 0; n < 5; n++) { if (CurrentIs(StandardByteCodes.Nothing)) { parameters.Add(null); continue; } var param = DecompileExpression(); if (param == null) return null; // ERROR parameters.Add(param); } Expression first = null; if ((parameters[0] ?? parameters[1] ?? parameters[2]) != null) { var innerParms = new List<Expression>(); if (parameters[0] != null) innerParms.Add(parameters[0]); if (parameters[1] != null) innerParms.Add(parameters[1]); if (parameters[2] != null) innerParms.Add(parameters[2]); first = new FunctionCall(new SymbolReference(null, null, null, "new"), innerParms, null, null); } else { first = new SymbolReference(null, null, null, "new"); } var second = parameters[3] ?? new SymbolReference(null, null, null, "NoClass??"); var op = new InOpDeclaration("", 0, true, null, null, null, null, null, null, null); var firstHalf = new InOpReference(op, first, second, null, null); StartPositions.Pop(); if (parameters[4] != null) return new InOpReference(op, firstHalf, parameters[4], null, null); else return firstHalf; }
public Expression DecompileNativeFunction(UInt16 index) { var parameters = new List<Expression>(); while (!CurrentIs(StandardByteCodes.EndFunctionParms)) { var param = DecompileExpression(); if (param == null) return null; // ERROR parameters.Add(param); } PopByte(); var entry = NativeTable[index]; Expression call = null; switch (entry.Type) { case NativeType.Function: var func = new SymbolReference(null, null, null, entry.Name); call = new FunctionCall(func, parameters, null, null); break; case NativeType.Operator: // TODO: table should hold precedence, currently all have 0 and it'll be a mess. var op = new InOpDeclaration(entry.Name, entry.Precedence, false, null, null, null, null, null, null, null); call = new InOpReference(op, parameters[0], parameters[1], null, null); break; case NativeType.PreOperator: // TODO: table should hold precedence, currently all have 0 and it'll be a mess. var preOp = new PreOpDeclaration(entry.Name, false, null, null, null, null, null, null); call = new PreOpReference(preOp, parameters[0], null, null); break; case NativeType.PostOperator: // TODO: table should hold precedence, currently all have 0 and it'll be a mess. var postOp = new PostOpDeclaration(entry.Name, false, null, null, null, null, null, null); call = new PostOpReference(postOp, parameters[0], null, null); break; } StartPositions.Pop(); return call; }
public Expression DecompileInOpNaive(String opName, bool useEndOfParms = false, bool isStruct = false) { // TODO: ugly, wrong. PopByte(); if (isStruct) ReadObject(); // struct type? var left = DecompileExpression(); if (left == null) return null; // ERROR var right = DecompileExpression(); if (right == null) return null; // ERROR if (useEndOfParms) PopByte(); StartPositions.Pop(); var op = new InOpDeclaration(opName, 0, true, null, null, null, null, null, null, null); return new InOpReference(op, left, right, null, null); }
public Expression DecompileGoW_DefaultValue() { PopByte(); var unkn = ReadByte(); var expr = DecompileExpression(); StartPositions.Pop(); var op = new InOpDeclaration("", 0, true, null, null, null, null, null, null, null); var objRef = new SymbolReference(null, null, null, "UNSUPPORTED: GoW_DefaultValue: Byte:" + unkn + " - "); return new InOpReference(op, objRef, expr, null, null); }
// TODO: only skips one object? see code. public Expression DecompileEatReturn() { PopByte(); var obj = ReadObject(); var expr = DecompileExpression(); StartPositions.Pop(); var op = new InOpDeclaration("", 0, true, null, null, null, null, null, null, null); var objRef = new SymbolReference(null, null, null, "UNSUPPORTED: EatReturnValue: " + obj.ObjectName + "|" + obj.ClassName + " -"); return new InOpReference(op, objRef, expr, null, null); }
public void BasicClassTest() { var source = "class Test Deprecated Transient; \n" + "var enum ETestnumeration {\n" + " TEST_value1,\n" + " TEST_value2,\n" + " TEST_value3,\n" + "} inlineNumeration, testnum2;\n" + "var private deprecated int X; \n" + "VAR INT Y, Z; \n" + "var ETestnumeration testnum;\n" + "struct transient testStruct\n" + "{ var float a, b, c; };\n" + "var private struct transient twoStruct extends testStruct\n" + "{\n" + " var etestnumeration num;\n" + "} structA, structB;\n" + "function float funcB( testStruct one, float two ) \n" + "{\n" + " local float c;" + " one.a = 1.3 * c;" + " while (true)" + " {" + " c = c - c - c;" + " }" + " if (false) {" + " switch(one.a) {" + " case one.a:" + " c = one.a;" + " break;" + " case 1.2:" + " case 1.3:" + " c = c + 0.5;" + " break;" + " default:" + " c = 6.6;" + " }" + " }" + " return one.a + 0.33 * (0.66 + 0.1) * 1.5;\n" + "}\n" + "private simulated function float MyFunc( out testStruct one, coerce optional float two ) \n" + "{\n" + " return one.b + funcB(one, two);\n" + "}\n" + "auto state MyState\n" + "{\n" + "ignores MyFunc;\n" + "function StateFunc()\n" + "{\n" + "}\n" + "\n" + "Begin:\n" + " moredragons\n" + "}\n" + "\n" + "final static operator(254) int >>>( coerce float left, coerce float right )\n" + "{\n" + " all the dragons\n" + "}\n" + "\n" + "\n" + "\n"; var parser = new ClassOutlineParser(new TokenStream<String>(new StringLexer(source)), log); var symbols = new SymbolTable(); Class obj = new Class("Object", null, null, null, null, null, null, null, null, null, null); obj.OuterClass = obj; symbols.PushScope(obj.Name); symbols.AddSymbol(obj.Name, obj); VariableType integer = new VariableType("int", null, null); symbols.AddSymbol(integer.Name, integer); VariableType floatingpoint = new VariableType("float", null, null); symbols.AddSymbol(floatingpoint.Name, floatingpoint); InOpDeclaration plus_float = new InOpDeclaration("+", 20, false, null, floatingpoint, new FunctionParameter(floatingpoint, null, null, null, null), new FunctionParameter(floatingpoint, null, null, null, null), null, null, null); symbols.AddOperator(plus_float); InOpDeclaration sub_float = new InOpDeclaration("-", 20, false, null, floatingpoint, new FunctionParameter(floatingpoint, null, null, null, null), new FunctionParameter(floatingpoint, null, null, null, null), null, null, null); symbols.AddOperator(sub_float); InOpDeclaration mult_float = new InOpDeclaration("*", 16, false, null, floatingpoint, new FunctionParameter(floatingpoint, null, null, null, null), new FunctionParameter(floatingpoint, null, null, null, null), null, null, null); symbols.AddOperator(mult_float); Class node = (Class)parser.ParseDocument(); var ClassValidator = new ClassValidationVisitor(log, symbols); node.AcceptVisitor(ClassValidator); symbols.GoDirectlyToStack(node.GetInheritanceString()); foreach (Function f in node.Functions) { symbols.PushScope(f.Name); var p = new CodeBodyParser(new TokenStream<String>(new StringLexer(source)), f.Body, symbols, f, log); var b = p.ParseBody(); symbols.PopScope(); } var CodeBuilder = new CodeBuilderVisitor(); node.AcceptVisitor(CodeBuilder); Console.Write(CodeBuilder.GetCodeString()); Assert.IsTrue(log.AllErrors.Count == 0); return; }
public bool IdenticalSignature(InOpDeclaration other) { return(base.IdenticalSignature(other) && string.Equals(this.LeftOperand.VarType.Name, other.LeftOperand.VarType.Name, StringComparison.OrdinalIgnoreCase) && string.Equals(this.RightOperand.VarType.Name, other.RightOperand.VarType.Name, StringComparison.OrdinalIgnoreCase)); }
public bool IdenticalSignature(InOpDeclaration other) { return base.IdenticalSignature(other) && this.LeftOperand.VarType.Name.ToLower() == other.LeftOperand.VarType.Name.ToLower() && this.RightOperand.VarType.Name.ToLower() == other.RightOperand.VarType.Name.ToLower(); }
public bool IdenticalSignature(InOpDeclaration other) { return(base.IdenticalSignature(other) && this.LeftOperand.VarType.Name.ToLower() == other.LeftOperand.VarType.Name.ToLower() && this.RightOperand.VarType.Name.ToLower() == other.RightOperand.VarType.Name.ToLower()); }