示例#1
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();
        }
示例#2
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("}");
        }
        public override void EmitForeignToFCS(CodeFormatter cppFile, MemberSpec fcsDestObject, MemberSpec foreignSourceObject)
        {
            foreach (EnumToBoolMapping etbm in mappings)
            {
                etbm.EmitForeignToFCS(cppFile, foreignSourceObject, fcsDestObject, FCSSpec.Name);

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

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

        }
示例#6
0
 private void AddForeignToFCSConvert(CodeFormatter cppFile)
 {
     MemberSpec dest = new MemberSpec(FCSType, "destination");
     MemberSpec source = new MemberSpec(ForeignType, "source");
     BeginMethod(cppFile, dest.Type, "Convert", source);
     OutputSwitch(cppFile, ForeignValues, FCSValues, FCSDefault, ForeignTypePrefix(), FCSType.Name+"::");
     cppFile.WriteLine("}");
 }
        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("}");
        }
示例#8
0
 protected void BeginMethod(CodeFormatter cppFile, TypeSpec returnType, string methodName, params object[] parameters)
 {
     cppFile.WriteLine("");
     StringBuilder bld = new StringBuilder();
     bld.AppendFormat("{0} {1}::{2}(", returnType.ToString(), GetClassName(), methodName);
     for (int i = 0; i < parameters.Length; i++)
     {
         MemberSpec ms = parameters[i] as MemberSpec;
         TypeSpec type = ms.Type;
         string name = ms.Name;
         if (name == null || type == null)
         {
             throw new ArgumentException("Wrong arguments to BeginMethod");
         }
         if (i != 0)
             bld.Append(", ");
         if (name == "source" && type.Modifier == TypeSpec.Modifiers.pointer)
             bld.Append("const ");
         bld.AppendFormat("{0} {1}", type.ToString(), name);
     }
     bld.Append(")");
     cppFile.WriteLine(bld.ToString());
     cppFile.WriteLine("{");
 }
        private void EmitContentNodeHandlers(CodeFormatter cf)
        {
            foreach (string nodeName in listContentNodes)
            {
                if (string.IsNullOrEmpty(nodeName))
                    continue;

                if (GenerationContext.CanHandle(nodeName))
                {
                    throw new Exception("Unexpected : we have a handler for a content type node (" + nodeName + ")");
                }
                else
                {
                    cf.BeginCase("\"" + nodeName + "\"");
                    if (HasType)
                        cf.WriteLine("AddCompletedObject(m_dataObject);");
                    cf.WriteLine("AddCompletedObject(new TextContent(reader.ReadString()));");
                    cf.EndCase();
                    AddHandledSubNode(nodeName);
                }

            }
        }
示例#10
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);


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

        }
示例#14
0
        private void EmitOnSubConsumerComplete(CodeFormatter cf)
        {
            cf.WriteLine("public override void OnSubConsumerComplete(object subConsumerOutput)");
            cf.WriteLine("{");

            foreach (IFieldMapping fm in mappings)
            {
                fm.EmitCompleteHandler(cf);

            }

            cf.WriteLine("}");
        }
示例#15
0
        private void EmitPostProcess(CodeFormatter cf)
        {
            if (string.IsNullOrEmpty(PostProcessCode))
                return;

            cf.WriteLine("private void PostProcess(System.Xml.XmlReader reader)");
            cf.WriteLine("{");
            cf.WriteLine("if (reader == null) return;");  // more to stop compiler complaining

            foreach (string s in PostProcessCode.Split('\r'))
            {
                cf.WriteLine(s);
            }
            cf.WriteLine("}");
        }
示例#16
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());

        }
示例#17
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());
 }
示例#18
0
 public virtual void EmitFCSToForeign(CodeFormatter cppFile, MemberSpec foreignDestObject, MemberSpec fcsSourceObject)
 {
     BaseClassMapping converter = GetConverter();
     m_currentFile = cppFile;
     EmitConversion(converter, foreignDestObject, ForeignSpec, fcsSourceObject, FCSSpec);
 }
示例#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 EmitHandleGroupsCases(CodeFormatter cf)
        {
            foreach (KeyValuePair<string, NodeGroupData> groupInfo in listGroupsToHandle)
            {
                string[] items;
                if (string.IsNullOrEmpty(groupInfo.Value.nodenamespace))
                {
                    items = GenerationContext.ResolveGroupMembers(SchemaSupport.DefaultDocxNamespace + ":" + groupInfo.Key);
                }
                else
                {
                    items = GenerationContext.ResolveGroupMembers(groupInfo.Value.nodenamespace + ":" + groupInfo.Key);
                }

                foreach (string item in items)
                {
                    bool excepted = false;
                    if (groupInfo.Value.listGroupExceptions != null)
                    {
                        foreach (string except in groupInfo.Value.listGroupExceptions)
                        {
                            if (except == item)
                            {
                                excepted = true;
                                break;
                            }
                        }
                    }
                    if (string.IsNullOrEmpty(item) || excepted)
                        continue;

                    bool bSuppressParentEmit = groupInfo.Value.flag;

                    HandleSingleNode(cf, item, bSuppressParentEmit);

                }

            }
        }
示例#21
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);
            }
        }
示例#22
0
        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);
        }
示例#23
0
 private void AddNotifyContextOfNodeEnd(CodeFormatter cf)
 {
     cf.WriteLine("if(Context != null)");
     cf.WriteLine("{");
     cf.FormatLine("Context.NotifyEndOfNodeNamed(\"{0}\");", NodeName);
     cf.WriteLine("}");
 }
示例#24
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);


                }


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

        }
示例#26
0
 private void EmitHandleNotes(CodeFormatter cf)
 {
     foreach (string s in listNodesToHandle)
     {
         HandleSingleNode(cf, s, false);
     }
 }
示例#27
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();
 }
示例#28
0
        private void EmitCaseHandlers(CodeFormatter cf)
        {
            List<int> AlreadyMapped = new List<int>();
            for (int iMappings = 0; iMappings < mappings.Count; ++iMappings)
            {
                if (AlreadyMapped.Contains(iMappings))
                    continue;

                mappings[iMappings].EmitCaseHandlerStart(cf);
                mappings[iMappings].EmitCaseHandlerBody(cf);

                string mappedNodeName = mappings[iMappings].TheNodeName;
                if (!string.IsNullOrEmpty(mappedNodeName))
                {
                    for (int iRepeats = iMappings + 1; iRepeats < mappings.Count; ++iRepeats)
                    {
                        if (AlreadyMapped.Contains(iRepeats))
                            continue;

                        if (mappings[iRepeats].TheNodeName == mappedNodeName)
                        {
                            mappings[iRepeats].EmitCaseHandlerBody(cf);
                            AlreadyMapped.Add(iRepeats);
                        }
                    }
                }
                mappings[iMappings].EmitCaseHandlerEnd(cf);
                AddHandledSubNode(mappings[iMappings].TheNodeName);
            }
        }
示例#29
0
        //getting to point where compiler doesn't like the size of the case statement
        //so wrap it in a separate handler - seems to satisfy the compiler so far
        private void EmitHandleNamedNode(CodeFormatter cf)
        {
            cf.WriteLine("private void HandleNamedNode(System.Xml.XmlReader reader)");

            cf.WriteLine("{");
            cf.WriteLine("switch (reader.LocalName)");
            cf.WriteLine("{");

            EmitCaseHandlers(cf);
            EmitHandleGroupsCases(cf);
            EmitContentNodeHandlers(cf);
            EmitHandleNotes(cf);

            cf.WriteLine("}");
            cf.WriteLine("}");
        }
示例#30
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("}");
        }