Exemple #1
0
        public void TyfoInt()
        {
            DataType dt = PrimitiveType.Int32;

            tyreffo.WriteDeclaration(dt, "test");
            Assert.AreEqual("int32 test", sw.ToString());
        }
Exemple #2
0
        public void Emit(string fnName, EmitFlags f, Formatter fmt, CodeFormatter w, TypeReferenceFormatter t)
        {
            bool emitStorage = (f & EmitFlags.ArgumentKind) == EmitFlags.ArgumentKind;

            if (ParametersValid)
            {
                if (emitStorage)
                {
                    if (HasVoidReturn)
                    {
                        fmt.Write("void ");
                    }
                    else
                    {
                        w.WriteFormalArgumentType(ReturnValue, emitStorage);
                        fmt.Write(" ");
                    }
                    fmt.Write("{0}(", fnName);
                }
                else
                {
                    if (HasVoidReturn)
                    {
                        fmt.Write("void {0}", fnName);
                    }
                    else
                    {
                        t.WriteDeclaration(ReturnValue.DataType, fnName);           //$TODO: won't work with fn's that return pointers to functions or arrays.
                    }
                    fmt.Write("(");
                }
                var sep = "";
                if (Parameters != null)
                {
                    IEnumerable <Identifier> parms = this.IsInstanceMetod
                        ? Parameters.Skip(1)
                        : Parameters;
                    foreach (var p in parms)
                    {
                        fmt.Write(sep);
                        sep = ", ";
                        w.WriteFormalArgument(p, emitStorage, t);
                    }
                }
                fmt.Write(")");
            }
            else
            {
                fmt.WriteKeyword("define");
                fmt.Write(" ");
                fmt.Write(fnName);
            }

            if ((f & EmitFlags.LowLevelInfo) == EmitFlags.LowLevelInfo)
            {
                fmt.WriteLine();
                fmt.Write("// stackDelta: {0}; fpuStackDelta: {1}; fpuMaxParam: {2}", StackDelta, FpuStackDelta, FpuStackArgumentMax);
                fmt.WriteLine();
            }
        }
        public void Tyreffmt_ptr_TypeReference()
        {
            var sw  = new StringWriter();
            var trf = new TypeReferenceFormatter(new TextFormatter(sw));

            trf.WriteDeclaration(
                new Pointer(
                    new TypeReference("LONG", PrimitiveType.Int32), 32),
                "l0");
            Assert.AreEqual("LONG * l0", sw.ToString());
        }
        public void Tyreffmt_ptr_function()
        {
            var sw  = new StringWriter();
            var trf = new TypeReferenceFormatter(new TextFormatter(sw));

            trf.WriteDeclaration(
                new Pointer(
                    FunctionType.Action(new [] { Arg("arg0", 0) }),
                    32),
                "pfn");
            Assert.AreEqual("void (* pfn)(word32 arg0)", sw.ToString());
        }
        public void Tyreffmt_ptr_function_with_eq_class()
        {
            var sw  = new StringWriter();
            var trf = new TypeReferenceFormatter(new TextFormatter(sw));

            trf.WriteDeclaration(
                new Pointer(
                    new EquivalenceClass(
                        new TypeVariable(3),
                        FunctionType.Action(new[] { Arg("arg0", 0) })),
                    4),
                "pfn");
            Assert.AreEqual("void (* pfn)(word32 arg0)", sw.ToString());
        }
Exemple #6
0
        public void Write(TextWriter writer)
        {
            TextFormatter f = new TextFormatter(writer);

            foreach (var de in Signatures.OrderBy(d => d.Key, StringComparer.InvariantCulture))
            {
                string name = de.Key;
                de.Value.Emit(de.Key, FunctionType.EmitFlags.ArgumentKind, f);
                writer.WriteLine();
            }

            var tf = new TypeReferenceFormatter(f);

            foreach (var de in Globals.OrderBy(d => d.Key, StringComparer.InvariantCulture))
            {
                tf.WriteDeclaration(de.Value, de.Key);
            }
        }