Exemplo n.º 1
0
        // 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;
        }
Exemplo n.º 2
0
 public bool VisitNode(InOpReference node)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 3
0
        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;
        }
Exemplo n.º 4
0
        public bool VisitNode(InOpReference node)
        {
            // [(] expression operatorkeyword expression [)]
            bool scopeNeeded = node.Operator.Precedence > ExpressionPrescedence.Peek();
            ExpressionPrescedence.Push(node.Operator.Precedence);

            if (scopeNeeded)
                Append("(");
            node.LeftOperand.AcceptVisitor(this);
            Append(" {0} ", node.Operator.OperatorKeyword);
            node.RightOperand.AcceptVisitor(this);
            if (scopeNeeded)
                Append(")");

            ExpressionPrescedence.Pop();
            return true;
        }