Ejemplo n.º 1
0
        public override void EmitCpp(CppEmitContext cec)
        {
            base.EmitCpp(cec);

            if ((this.ModFlags & Modifiers.STATIC) != 0)
            {
                cec.Buf.Write("\tstatic ", Location);
            }
            else
            {
                cec.Buf.Write("\t", Location);
            }

            if (cec.Pass == CppPasses.CLASSDEF)
            {
                cec.Buf.Write(cec.MakeCppFullTypeName(this.ReturnType), " ", this.MethodName.Name, "(");
                parameters.EmitCpp(cec);
                cec.Buf.Write(");\n");
            }
            else
            {
                cec.Buf.Write(cec.MakeCppFullTypeName(this.ReturnType), " ", cec.MakeCppTypeName(Parent.CurrentType, false), "::", this.MethodName.Name, "(");
                parameters.EmitCpp(cec);
                cec.Buf.Write(") ");

                if (MethodData != null)
                {
                    MethodData.EmitCpp(Parent, cec);
                }

                Block = null;

                cec.Buf.Write("\n");
            }
        }
Ejemplo n.º 2
0
        protected override void DoEmitCpp(CppEmitContext cec)
        {
            // FIXME: Switch has changed..
            base.DoEmitCpp(cec);
//			cec.Buf.Write ("\tswitch (", loc);
//			Expr.EmitCpp (cec);
//			cec.Buf.Write (") {\n");
//			cec.Buf.Indent ();
//
//			foreach (var section in Sections) {
//				foreach (var label in section.Labels) {
//					if (label.IsDefault) {
//						cec.Buf.Write ("\tdefault:\n", label.Location);
//					} else {
//						cec.Buf.Write ("\tcase ", label.Location);
//						label.Label.EmitCpp (cec);
//						cec.Buf.Write (":\n");
//					}
//				}
//				cec.Buf.Indent ();
//				section.Block.EmitBlockCpp (cec, true, true);
//				cec.Buf.Unindent ();
//			}
//
//			cec.Buf.Unindent ();
//			cec.Buf.Write ("\t}\n");
        }
Ejemplo n.º 3
0
        public override void EmitCpp(CppEmitContext cec)
        {
            var leftParens  = cec.NeedParens(this, Left);
            var rightParens = cec.NeedParens(this, Right);

            if (leftParens)
            {
                cec.Buf.Write("(", Location);
            }
            Left.EmitCpp(cec);
            if (leftParens)
            {
                cec.Buf.Write(")");
            }
            cec.Buf.Write(" " + this.OperName(oper) + " ");
            if (rightParens)
            {
                cec.Buf.Write("(", Location);
            }
            Right.EmitCpp(cec);
            if (rightParens)
            {
                cec.Buf.Write(")");
            }
        }
Ejemplo n.º 4
0
        protected override void DoEmitCpp(CppEmitContext cec)
        {
            // NOTE: WE don't optimize for emty loop right now..

            cec.Buf.Write("\tfor (", loc);
            cec.PushForceExpr(true);
            if (Initializer != null)
            {
                Initializer.EmitCpp(cec);
            }
            cec.Buf.Write("; ");
            if (Condition != null)
            {
                Condition.EmitCpp(cec);
            }
            cec.Buf.Write("; ");
            if (Iterator != null)
            {
                Iterator.EmitCpp(cec);
            }
            cec.Buf.Write(") ");
            cec.PopForceExpr();

            cec.Buf.WriteBlockStatement(Statement);

            cec.Buf.Write("\n");
        }
Ejemplo n.º 5
0
        protected override void DoEmitCpp(CppEmitContext cec)
        {
            if (Initializer != null)
            {
                cec.Buf.Write("\t", loc);
                Initializer.EmitCpp(cec);
            }
            else
            {
                cec.Buf.Write("\t", cec.MakeCppFullTypeName(this.type), " ", Variable.Name, loc);
            }

            if (declarators != null)
            {
                foreach (var d in declarators)
                {
                    cec.Buf.Write(", ");
                    if (d.Initializer != null)
                    {
                        d.Initializer.EmitCpp(cec);
                    }
                    else
                    {
                        cec.Buf.Write(d.Variable.Name);
                    }
                }
            }

            cec.Buf.Write(";\n");
        }
Ejemplo n.º 6
0
        protected override void DoEmitCpp(CppEmitContext cec)
        {
            if (empty)
            {
                return;
            }

            //
            // Inform whether we are infinite or not
            //
            if (expr is Constant)
            {
                // expr is 'true', since the 'empty' case above handles the 'false' case
                cec.Buf.Write("\twhile (true) ", loc);
            }
            else
            {
                cec.Buf.Write("\twhile (", loc);
                expr.EmitCpp(cec);
                cec.Buf.Write(") ");
            }

            cec.Buf.WriteBlockStatement(Statement);

            cec.Buf.Write("\n");
        }
Ejemplo n.º 7
0
        public override void EmitContainerCpp(CppEmitContext cec)
        {
            VerifyClsCompliance();

            var  ns           = cec.MakeCppNamespaceName(this.NS.Name);
            var  ns_names     = this.NS.Name.Split(new char[] { '.' });
            bool is_global_ns = String.IsNullOrEmpty(ns);

            if (!is_global_ns && ns != cec.PrevNamespace)
            {
                if (cec.PrevNamespaceNames != null)
                {
                    foreach (var n in cec.PrevNamespaceNames)
                    {
                        cec.Buf.Unindent();
                        cec.Buf.Write("\t}\n");
                    }
                }
                foreach (var n in ns_names)
                {
                    cec.Buf.Write("\tnamespace ", n, " {\n");
                    cec.Buf.Indent();
                }
                cec.MarkNamespaceDefined(NS.Name);
                cec.PrevNamespace      = ns;
                cec.PrevNamespaceNames = ns_names;
            }

            base.EmitContainerCpp(cec);
        }
Ejemplo n.º 8
0
 protected void EmitScopeInitializersCpp(CppEmitContext cec)
 {
     foreach (Statement s in scope_initializers)
     {
         s.EmitCpp(cec);
     }
 }
Ejemplo n.º 9
0
        public override void EmitStatementCpp(CppEmitContext cec)
        {
            cec.Buf.Write("\t", Location);

            EmitCpp(cec);

            cec.Buf.Write(";\n");
        }
Ejemplo n.º 10
0
 public void EmitCallCpp(CppEmitContext cec, Arguments arguments)
 {
     cec.Buf.Write("(", Location);
     if (arguments != null)
     {
         arguments.EmitCpp(cec);
     }
     cec.Buf.Write(")");
 }
Ejemplo n.º 11
0
        /// <summary>
        /// Base C++ emit method.  This is also entry point for CLS-Compliant verification.
        /// </summary>
        public virtual void EmitCpp(CppEmitContext cec)
        {
            if (!Compiler.Settings.VerifyClsCompliance)
            {
                return;
            }

            VerifyClsCompliance();
        }
Ejemplo n.º 12
0
 public override void EmitCpp(CppEmitContext cec)
 {
     cec.Buf.Write("new ", cec.MakeCppFullTypeName(Type, false), "(", Location);
     if (arguments != null)
     {
         arguments.EmitCpp(cec);
     }
     cec.Buf.Write(")");
 }
Ejemplo n.º 13
0
        public override void EmitContainerCpp(CppEmitContext cec)
        {
            if ((caching_flags & Flags.CloseTypeCreated) != 0)
            {
                return;
            }

            EmitCpp(cec);
        }
Ejemplo n.º 14
0
 protected override void DoEmitCpp(CppEmitContext cec)
 {
     if (expr != null)
     {
         cec.Buf.Write("\treturn ", loc);
         expr.EmitCpp(cec);
         cec.Buf.Write(";\n");
     }
 }
Ejemplo n.º 15
0
 public virtual void EmitContainerCpp(CppEmitContext cec)
 {
     if (containers != null)
     {
         for (int i = 0; i < containers.Count; ++i)
         {
             containers[i].EmitContainerCpp(cec);
         }
     }
 }
Ejemplo n.º 16
0
        protected override void DoEmitCpp(CppEmitContext cec)
        {
            cec.Buf.Write("\tdo ", loc);

            cec.Buf.WriteBlockStatement(EmbeddedStatement);

            cec.Buf.Write(" while (", expr.Location);
            expr.EmitCpp(cec);
            cec.Buf.Write(");\n");
        }
Ejemplo n.º 17
0
 public override void EmitCpp(CppEmitContext cec)
 {
     try {
         base.EmitCpp(cec);
     } catch {
         Console.WriteLine("Internal compiler error at {0}: exception caught while emitting {1}",
                           Location, MethodBuilder);
         throw;
     }
 }
Ejemplo n.º 18
0
 public override void EmitCpp(CppEmitContext cec)
 {
     if (Value != null)
     {
         cec.Buf.Write("\"", cec.Buf.EscapeString(Value), "\"", Location);
     }
     else
     {
         cec.Buf.Write("\"\"", Location);
     }
 }
Ejemplo n.º 19
0
 public override void EmitCpp(CppEmitContext cec)
 {
     if (IsStatic)
     {
         cec.Buf.Write(cec.MakeCppFullTypeName(best_candidate.DeclaringType, false), loc);
     }
     else
     {
         InstanceExpression.EmitCpp(cec);
     }
     cec.Buf.Write("->", "get_", best_candidate.Name, "()", loc);
 }
Ejemplo n.º 20
0
        public override void EmitCpp(CppEmitContext cec)
        {
            if (this.Get != null)
            {
                this.Get.EmitCpp(cec);
            }

            if (this.Set != null)
            {
                this.Set.EmitCpp(cec);
            }
        }
Ejemplo n.º 21
0
        public override void EmitContainerCpp(CppEmitContext cec)
        {
            if (OptAttributes != null)
            {
                OptAttributes.EmitCpp(cec);
            }

            if (cec.Pass == CppPasses.PREDEF)
            {
                foreach (var tc in containers)
                {
                    tc.PrepareEmit();
                }
            }

            cec.PrevNamespace      = null;
            cec.PrevNamespaceNames = null;

            base.EmitContainerCpp(cec);

            // Close last unclosed namespace..
            if (cec.PrevNamespaceNames != null)
            {
                foreach (var n in cec.PrevNamespaceNames)
                {
                    cec.Buf.Unindent();
                    cec.Buf.Write("\t}\n");
                }
            }

            cec.PrevNamespace      = null;
            cec.PrevNamespaceNames = null;

            if (cec.Pass == CppPasses.METHODS)
            {
                if (Compiler.Report.Errors == 0 && !Compiler.Settings.WriteMetadataOnly)
                {
                    VerifyMembers();
                }
            }

            if (anonymous_types != null)
            {
                foreach (var atypes in anonymous_types)
                {
                    foreach (var at in atypes.Value)
                    {
                        at.EmitContainerCpp(cec);
                    }
                }
            }
        }
Ejemplo n.º 22
0
        public override void EmitCpp(CppEmitContext cec)
        {
            double d = Value;

            if (d == System.Math.Floor(d))
            {
                cec.Buf.Write(GetValue().ToString(), ".0", Location);
            }
            else
            {
                cec.Buf.Write(GetValue().ToString(), Location);
            }
        }
Ejemplo n.º 23
0
 public override void EmitCpp(CppEmitContext cec)
 {
     if (InstanceExpression != null)
     {
         InstanceExpression.EmitCpp(cec);
         cec.Buf.Write("->");
     }
     else
     {
         cec.Buf.Write(DeclaringType.Name, "->", Location);
     }
     cec.Buf.Write(Name);
 }
Ejemplo n.º 24
0
 public override void EmitCpp(CppEmitContext cec)
 {
     if (Target is PropertyExpr)
     {
         ((PropertyExpr)Target).EmitAssignCpp(cec, Source, false, false);
     }
     else
     {
         Target.EmitCpp(cec);
         cec.Buf.Write(" = ");
         Source.EmitCpp(cec);
     }
 }
Ejemplo n.º 25
0
 public override void EmitAssignCpp(CppEmitContext cec, Expression source, bool leave_copy, bool isCompound)
 {
     if (IsStatic)
     {
         cec.Buf.Write(cec.MakeCppFullTypeName(best_candidate.DeclaringType, false), loc);
     }
     else
     {
         InstanceExpression.EmitCpp(cec);
     }
     cec.Buf.Write("->", "set_", best_candidate.Name, "(");
     source.EmitCpp(cec);
     cec.Buf.Write(")", loc);
 }
Ejemplo n.º 26
0
        public virtual void EmitCpp(CppEmitContext cec)
        {
            bool first = true;

            foreach (Argument a in args)
            {
                if (!first)
                {
                    cec.Buf.Write(", ");
                }
                a.Expr.EmitCpp(cec);
                first = false;
            }
        }
Ejemplo n.º 27
0
        public void EmitCpp()
        {
            cec = new CppEmitContext(module);

            cec.Buf.Write("// Module: ", this.Name, ".cpp\n");

            cec.Pass = CppPasses.PREDEF;
            module.EmitContainerCpp(cec);

            cec.Pass = CppPasses.CLASSDEF;
            module.EmitContainerCpp(cec);

            cec.Pass = CppPasses.METHODS;
            module.EmitContainerCpp(cec);
        }
Ejemplo n.º 28
0
        public override void EmitCpp(CppEmitContext cec)
        {
            bool needsParen = cec.NeedParens(this, Expr);

            cec.Buf.Write(OperName(Oper), Location);
            if (needsParen)
            {
                cec.Buf.Write("(");
            }
            Expr.EmitCpp(cec);
            if (needsParen)
            {
                cec.Buf.Write(")");
            }
        }
Ejemplo n.º 29
0
            public override void EmitCpp(CppEmitContext cec)
            {
                if (cec.Pass == CppPasses.CLASSDEF)
                {
                    cec.Buf.Write("\t", cec.MakeCppFullTypeName(this.Property.MemberType), " get_", Property.MemberName.Name, "();\n");
                }
                else
                {
                    cec.Buf.Write("\t", cec.MakeCppFullTypeName(this.Property.MemberType), cec.MakeCppTypeName(Parent.CurrentType, false), "::", " get_", Property.MemberName.Name, "() ", Location);
                    method_data.EmitCpp(Parent as TypeDefinition, cec);
                    cec.Buf.Write("\n");

                    block = null;
                }
            }
Ejemplo n.º 30
0
 public override void EmitCpp(CppEmitContext cec)
 {
     cec.Buf.Write("\t", cec.MakeCppFullTypeName(MemberType), " ", Name, Location);
     if (initializer != null)
     {
         ResolveContext rc   = new ResolveContext(this);
         var            expr = initializer.Resolve(rc);
         if (expr != null)
         {
             cec.Buf.Write(" = ");
             expr.EmitCpp(cec);
         }
     }
     cec.Buf.Write(";\n");
 }