예제 #1
0
        private void OutputSwitch(CodeFormatter cppFile, List<string> sourceValues, List<string> resultValues, string defaultValue, string sourcePrefix, string resultPrefix)
        {
            cppFile.WriteLine("switch (source)");
            cppFile.WriteLine("{");

            List<string> alreadyDone = new List<string>();

            for (int i = 0; i < sourceValues.Count; i++)
            {
                if (alreadyDone.Contains(sourceValues[i]))
                    continue;

                alreadyDone.Add(sourceValues[i]);

                cppFile.FormatLine("case {0}{1}:", sourcePrefix, sourceValues[i]);
                cppFile.IncreaseIndent();
                cppFile.FormatLine("return {0}{1};", resultPrefix, resultValues[i]);
                cppFile.DecreaseIndent();
            }

            cppFile.WriteLine("default:");
            cppFile.IncreaseIndent();
            cppFile.FormatLine("return {0}{1};", resultPrefix, defaultValue);
            cppFile.DecreaseIndent();


            cppFile.WriteLine("}");
        }
예제 #2
0
 private void EmitConditionalInitializer(CodeFormatter cf, string field, string type)
 {
     cf.FormatLine("if (m_dataObject.{0} == null)", field);
     cf.IncreaseIndent();
     cf.FormatLine("m_dataObject.{0} = new {1}();", field, type);
     cf.DecreaseIndent();
 }
예제 #3
0
        private void EmitHandleEponymousNode(CodeFormatter cf)
        {
            cf.WriteLine("private void HandleEponymousNode(System.Xml.XmlReader reader)");
            cf.WriteLine("{");

            if (StartIsMarkerOnly)
            {
                cf.WriteLine("if (reader.IsStartElement())");
                cf.WriteLine("{");
                if (HasType)
                {
                    cf.FormatLine("AddCompletedObject(new {0}(true));", TypeName);
                    cf.FormatLine("m_dataObject = new {0}(false);", TypeName);
                }

                EmitFieldInitializers(cf);
                cf.WriteLine("}");
            }

            if (HandleParentNodeContent)
            {
                cf.WriteLine("m_dataObject.Contents = new TextContent(reader.ReadString());");
            }

            if (listAttrMappings.Count > 0 ||
                MustEmitStartNodeCall)
            {
                cf.WriteLine("if (reader.IsStartElement())");
                cf.WriteLine("{");
                cf.WriteLine("if (!m_bSeenOurStartNode)");
                cf.WriteLine("{");
                cf.WriteLine("HandleStartNode(reader);");
                cf.WriteLine("m_bSeenOurStartNode = true;");
                cf.WriteLine("}");
                cf.WriteLine("else");
                cf.WriteLine("{");
                if (mappings.Count > 0 || listGroupsToHandle.Count > 0 || listContentNodes.Count > 0 || listNodesToHandle.Count > 0 ||// simple nodes may not have any 
                    MustEmitProcess) //used where the handling is currently too complex to auto-generate
                {
                    cf.WriteLine("HandleNamedNode(reader);");
                }
                cf.WriteLine("return;");
                cf.WriteLine("}");
                cf.WriteLine("}");
            }


            if (ForceNotifyContext)
            {
                cf.WriteLine("if (reader.IsStartElement())");
                cf.WriteLine("{");
                AddNotifyContextOfNodeStart(cf);
            }
            else
            {
                cf.WriteLine("if (reader.IsStartElement() && !reader.IsEmptyElement)");
                cf.WriteLine("{");

                if (NotifyContext)
                    AddNotifyContextOfNodeStart(cf);
            }
            cf.WriteLine("}");
            cf.WriteLine("else");
            cf.WriteLine("{");

            if (!string.IsNullOrEmpty(PostProcessCode) || MustEmitPostProcess)
            {
                cf.WriteLine("PostProcess(reader);");
            }

            if (NotifyContext ||  ForceNotifyContext)
                AddNotifyContextOfNodeEnd(cf);
         
            if (ForceAddDataObject)
            {
                if (HasStopParentElementDispatchFlag)
                {
                    cf.WriteLine("if (m_dataObject != null && m_dispatchThis)");
                }
                else
                {
                    cf.WriteLine("if (m_dataObject != null)");
                }
                cf.IncreaseIndent();
                cf.WriteLine("AddCompletedObject(m_dataObject);");
                cf.DecreaseIndent();
            }

            if (!StartIsMarkerOnly && IsHasContentType)
            {
                if (HasType)
                {
                    if (HasStopParentElementDispatchFlag)
                    {
                        cf.WriteLine("if (m_dispatchThis)");
                        if (InitializeFieldOnEnd)
                        {
                            cf.WriteLine("{");
                            cf.IncreaseIndent();
                            cf.FormatLine("{0} endObject = new {0}(false);", TypeName);
                            foreach (KeyValuePair<string, string> pair in fieldValueInitializers)
                            {
                                cf.FormatLine("endObject.{0} = {1};", pair.Key, pair.Value);
                            }

                            cf.WriteLine("AddCompletedObject(endObject);");
                            cf.DecreaseIndent();
                            cf.WriteLine("}");
                        }
                        else
                        {
                            cf.IncreaseIndent();
                            cf.FormatLine("AddCompletedObject(new {0}(false));", TypeName);
                            cf.DecreaseIndent();
                        }
                    }
                    else
                    {
                        if (InitializeFieldOnEnd)
                        {
                            cf.WriteLine("if ( m_dataObject != null)");
                            cf.WriteLine("{");
                            cf.WriteLine("AddCompletedObject(m_dataObject);");
                            cf.WriteLine("}");
                            cf.WriteLine("else");
                            cf.WriteLine("{");
                            cf.FormatLine("{0} endObject = new {0}(false);", TypeName);
                            foreach (KeyValuePair<string, string> pair in fieldValueInitializers)
                            {
                                cf.FormatLine("endObject.{0} = {1};", pair.Key, pair.Value);
                            }

                            cf.WriteLine("AddCompletedObject(endObject);");
                            cf.WriteLine("}");
                        }
                        else
                        {
                            cf.FormatLine("AddCompletedObject(new {0}(false));", TypeName);
                        }
                    }
                }
            }
            else
            {
                if (HasType)
                {
                    if(HasStopParentElementDispatchFlag)
                    {
                        cf.WriteLine("if (m_dispatchThis)");
                        cf.IncreaseIndent();
                        cf.WriteLine("AddCompletedObject(m_dataObject);");
                        cf.DecreaseIndent();
                    }
                    else
                    {
                       cf.WriteLine("AddCompletedObject(m_dataObject);");
                    }
                }
            }

            cf.WriteLine("IsFinished = true;");
            if (HasType)
                cf.WriteLine("m_dataObject = null;");

            cf.WriteLine("}");

            cf.WriteLine("}");

        }
예제 #4
0
        private void AddFCSToForeignConstruct(CodeFormatter cppFile)
        {
            MemberSpec source = new MemberSpec(FCSType, "source");
            MemberSpec context = new MemberSpec(new TypeSpec("RTFFileContext", TypeSpec.TypeSpecCategories.ForeignType) { Modifier = TypeSpec.Modifiers.pointer }, "pContext");
            BeginMethod(cppFile, ForeignType, "Construct", source, context);
            if (ForeignType.Modifier == TypeSpec.Modifiers.pointer && FCSType.Modifier == TypeSpec.Modifiers.managedReference)
            {
                cppFile.WriteLine("if (source == nullptr)");
                cppFile.IncreaseIndent();
                cppFile.WriteLine("return NULL;");
                cppFile.DecreaseIndent();
            }

            ConstructResult(cppFile, ForeignType);
            cppFile.FormatLine("Populate(result, source);");
            cppFile.WriteLine("return result;");
            cppFile.WriteLine("}");
        }
예제 #5
0
        private void AddForeignToFCSPopulate(CodeFormatter cppFile)
        {
            MemberSpec dest = new MemberSpec(FCSType, "destination");
            MemberSpec source = new MemberSpec(ForeignType, "source");
            BeginMethod(cppFile, TypeSpec.Void, "Populate", dest, source);

            if (ForeignType.Modifier == TypeSpec.Modifiers.pointer)
            {
                cppFile.WriteLine("if (source == NULL)");
                cppFile.IncreaseIndent();
                cppFile.WriteLine("return;");
                cppFile.DecreaseIndent();
            }

            foreach (MemberMapping mm in MemberMappings)
            {
                mm.EmitForeignToFCS(cppFile, dest, source);

            }
            cppFile.WriteLine("}");
        }
예제 #6
0
        private void AddForeignToFCSConstruct(CodeFormatter cppFile)
        {
            MemberSpec source = new MemberSpec(ForeignType, "source");
            BeginMethod(cppFile, FCSType, "Construct", source);
            if (ForeignType.Modifier == TypeSpec.Modifiers.pointer && FCSType.Modifier == TypeSpec.Modifiers.managedReference)
            {
                cppFile.WriteLine("if (source == NULL)");
                cppFile.IncreaseIndent();
                cppFile.WriteLine("return nullptr;");
                cppFile.DecreaseIndent();
            }
            if (UseManagedCtor)
            {
                ConstructResultWithParams(cppFile, FCSType);

            }
            else
            {
                ConstructResult(cppFile, FCSType);
                cppFile.FormatLine("Populate(result, source);");
            }
            cppFile.WriteLine("return result;");
            cppFile.WriteLine("}");
        }