示例#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
        internal void EmitForeignToFCS(CodeFormatter cppFile, MemberSpec foreignSourceObject, MemberSpec fcsDestObject, string fcsMemberName)
        {
            cppFile.FormatLine("if ({1}{2}{0})", boolMemberName, foreignSourceObject.Name, foreignSourceObject.Type.GetDereferencingOperator() );
            cppFile.WriteLine("{");
            cppFile.FormatLine("{0}{1}{2} = {3}::{4};", fcsDestObject.Name, fcsDestObject.Type.GetDereferencingOperator(), fcsMemberName, FCSType.Name, enumValue);
            cppFile.WriteLine("}");

        }
示例#3
0
        internal void EmitFCSToForeign(CodeFormatter cppFile, MemberSpec foreignDestObject)
        {
            cppFile.BeginCase(FCSType.Name + "::" +  enumValue);
            cppFile.FormatLine("{0}{2}{1} = true;", foreignDestObject.Name, boolMemberName, foreignDestObject.Type.GetDereferencingOperator());

            cppFile.EndCase();
        }
示例#4
0
        protected void InsertReferencedNamespaces(CodeFormatter headerFile, List<string> list)
        {
            foreach (string ns in list)
            {
                headerFile.FormatLine("using namespace {0};", ns);

            }
        }
        public override void EmitFCSToForeign(CodeFormatter cppFile, MemberSpec foreignDestObject, MemberSpec fcsSourceObject)
        {
            foreach (EnumToBoolMapping etbm in mappings)
            {
                etbm.EmitSetToFalse(cppFile, foreignDestObject);
            }
            cppFile.FormatLine("switch ({1}{2}{0})", FCSSpec.Name, fcsSourceObject.Name, fcsSourceObject.Type.GetDereferencingOperator());
            cppFile.WriteLine("{");
            foreach (EnumToBoolMapping etbm in mappings)
            {
                etbm.EmitFCSToForeign(cppFile, foreignDestObject);

            }
            cppFile.WriteLine("}");
        }
        private void EmitHandleNode(CodeFormatter cf)
        {
            cf.WriteLine("public override void HandleNode(System.Xml.XmlReader reader)");
            cf.WriteLine("{");

            cf.FormatLine("if(reader.LocalName == \"{0}\")", NodeName);
            cf.WriteLine("{");
            cf.WriteLine("HandleEponymousNode(reader);");
            cf.WriteLine("return;");
            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("if(string.IsNullOrEmpty(reader.LocalName) || !reader.IsStartElement())");
                cf.WriteLine("{");
                cf.WriteLine("return;");
                cf.WriteLine("}");
                cf.WriteLine("");
                cf.WriteLine("HandleNamedNode(reader);");
            }

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



            if (mappings.Count > 0 || listGroupsToHandle.Count > 0 || listContentNodes.Count > 0 ||listNodesToHandle.Count>0) // simple nodes may not have any 
            {
                EmitHandleNamedNode(cf);
            }

            if(!NodeHasNoAttributes)
                EmitNotHandledWarnings(cf);
        }
        private void EmitFieldInitializers(CodeFormatter cf)
        {
            for (int i = 0; i < fieldsToInitialize.Count; i++)
            {
                EmitConditionalInitializer(cf, fieldsToInitialize[i], typesOfFieldsToInitialize[i]);

            }

            foreach (KeyValuePair<string, string> pair in fieldValueInitializers)
            {
                cf.FormatLine("m_dataObject.{0} = {1};", pair.Key, pair.Value);
            }
        }
 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();
 }
        private void EmitMemberVariables(CodeFormatter cf)
        {
            cf.WriteLine("");
            if (HasType)
            {
                cf.FormatLine("{0} m_dataObject;", TypeName);
            }

            if(HasStopParentElementDispatchFlag)
            {
                cf.WriteLine("bool m_dispatchThis;");

            }

            if (listAttrMappings.Count > 0 ||
                MustEmitStartNodeCall)
            {
                cf.WriteLine("bool m_bSeenOurStartNode;");
            }
        }
示例#10
0
        private void EmitConstructors(CodeFormatter cf)
        {
            cf.FormatLine("public {0}(ParsingContext context) : base(context)", GetClassName());
            cf.WriteLine("{");
            if (!StartIsMarkerOnly)
            {
                if (HasType)
                {
                    cf.FormatLine("m_dataObject = new {0}({1});", TypeName, IsHasContentType ? "true" : "");
                }

                if( this.HasStopParentElementDispatchFlag)
                {
                    cf.WriteLine("m_dispatchThis = true;");
                }
                EmitFieldInitializers(cf);
            }
            cf.WriteLine("}");
            cf.WriteLine();

            if (!StartIsMarkerOnly && HasType)
            {
                cf.FormatLine("public {0}({1} dataObject, ParsingContext context) : base(context)", GetClassName(), TypeName);
                cf.WriteLine("{");

                cf.WriteLine("m_dataObject = dataObject;");
                if( this.HasStopParentElementDispatchFlag)
                {
                    cf.WriteLine("m_dispatchThis = true;");
                }
                EmitFieldInitializers(cf);


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

        }
示例#11
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("}");

        }
示例#12
0
 private void AddNotifyContextOfNodeEnd(CodeFormatter cf)
 {
     cf.WriteLine("if(Context != null)");
     cf.WriteLine("{");
     cf.FormatLine("Context.NotifyEndOfNodeNamed(\"{0}\");", NodeName);
     cf.WriteLine("}");
 }
示例#13
0
        private void EmitStartNodeHandler(CodeFormatter cf)
        {
            List<string> handledAttrs = new List<string>();
            if (listAttrMappings.Count > 0)
            {

                cf.WriteLine("protected override void HandleStartNode(System.Xml.XmlReader reader)");
                cf.WriteLine("{");

                foreach (AttrToFieldMapping mapping in listAttrMappings)
                {
                    mapping.EmitHandler(cf);
                    handledAttrs.Add(mapping.AttrName);
                }

                cf.WriteLine("}");
            }

            if (!NodeHasNoAttributes)
            {
                string[] attrs = GenerationContext.ResolveAttributes(this.NodeNameSpace + ":" + this.NodeName);

                foreach (string expectedAttr in attrs)
                {
                    if (!handledAttrs.Contains(expectedAttr))
                        cf.FormatLine("// {0} : unhandled attribute", expectedAttr);


                }
            }
        }
示例#14
0
        private void HandleSingleNode(CodeFormatter cf, string item, bool bSuppressParentEmit)
        {
            if (!GenerationContext.CanHandle(item))
            {
                cf.FormatLine("// case \"{0}\": Unhandled", item);
            }
            else
            {
                cf.BeginCase("\"" + item + "\"");
                cf.FormatLine("SubConsumer = new {0}_Handler(Context);", item);
                if (!bSuppressParentEmit && !StartIsMarkerOnly)
                {
                    if (HasType)
                    {
                        cf.WriteLine("AddCompletedObject(m_dataObject);");
                        cf.WriteLine("m_dataObject = null;");
                    }
                }
                cf.EndCase();

                AddHandledSubNode(item);
            }
        }
示例#15
0
 private void ConstructResult(CodeFormatter cppFile, TypeSpec resultType)
 {
     switch (resultType.Modifier)
     {
         case TypeSpec.Modifiers.value:
             cppFile.FormatLine("{0} result(pContext);", resultType.ToString());
             break;
         case TypeSpec.Modifiers.managedReference:
             if (FCSTypeIsHasContentType)
             {
                 cppFile.FormatLine("{0} result = gcnew {1}(true);", resultType.ToString(), resultType.Name);
             }
             else
             {
                 cppFile.FormatLine("{0} result = gcnew {1}();", resultType.ToString(), resultType.Name);
             }
             break;
         case TypeSpec.Modifiers.pointer:
             cppFile.FormatLine("{0} result = new {1}(pContext);", resultType.ToString(), resultType.Name);
             break;
         case TypeSpec.Modifiers.reference:
             throw new NotImplementedException();
     }
 }
示例#16
0
        private void EmitNotHandledWarnings(CodeFormatter cf)
        {
            string[] subNodes = GenerationContext.ResolveSubNodes(this.NodeNameSpace + ":" + this.NodeName);
            if (subNodes != null)
            {
                foreach (string s in subNodes)
                {
                    if (!HandledItems.Contains(s))
                        cf.FormatLine("// {0} : Subnode unhandled", s);


                }


            }
        }
示例#17
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("}");
        }
示例#18
0
 private void InsertConversionMethods(CodeFormatter headerFile)
 {
     headerFile.FormatLine("static {0} Convert({1} source);", FCSType.ToString(), ForeignType.ToString());
     headerFile.FormatLine("static {0} Convert({1} source);", ForeignType.ToString(), FCSType.ToString());
 }
示例#19
0
 internal void EmitSetToFalse(CodeFormatter cppFile, MemberSpec foreignDestObject)
 {
     cppFile.FormatLine("{0}{2}{1} = false;", foreignDestObject.Name, boolMemberName, foreignDestObject.Type.GetDereferencingOperator());
 }
示例#20
0
        private void InsertConversionMethods(CodeFormatter headerFile)
        {
            if (!UseManagedCtor)
                headerFile.FormatLine("static void Populate({0} destination, {1} source);", FCSType.ToString(), AdjustTypeForConstSourcePointers(ForeignType));
            headerFile.FormatLine("static void Populate({0} destination, {1} source);", ForeignType.ToString(), FCSType.ToString());
            headerFile.FormatLine("static {0} Construct({1} source);", FCSType.EnsurePointerishType().ToString(), AdjustTypeForConstSourcePointers(ForeignType));
            headerFile.FormatLine("static {0} Construct({1} source, RTFFileContext* pContxt);", ForeignType.ToString(), FCSType.ToString());

        }
示例#21
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("}");
        }