Skip to content

Commit

Permalink
Merge pull request #1608 from atsushieno/import-system-xml-4
Browse files Browse the repository at this point in the history
Import large chunk of System.Xml sources from referencesource.
  • Loading branch information
atsushieno committed Mar 3, 2015
2 parents 1a679a6 + e7da0c1 commit e9ef998
Show file tree
Hide file tree
Showing 86 changed files with 4,640 additions and 818 deletions.
1 change: 1 addition & 0 deletions mcs/build/common/Consts.cs.in
Expand Up @@ -78,6 +78,7 @@ static class Consts
//

public const string AssemblyI18N = "I18N, Version=" + FxVersion + ", Culture=neutral, PublicKeyToken=0738eb9f132ed756";
public const string AssemblyMicrosoft_JScript = "Microsoft.JScript, Version=" + FxVersion + ", Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a";
public const string AssemblyMicrosoft_VisualStudio = "Microsoft.VisualStudio, Version=" + FxVersion + ", Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a";
public const string AssemblyMicrosoft_VisualStudio_Web = "Microsoft.VisualStudio.Web, Version=" + VsVersion + ", Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a";
public const string AssemblyMicrosoft_VSDesigner = "Microsoft.VSDesigner, Version=" + VsVersion + ", Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a";
Expand Down
2 changes: 2 additions & 0 deletions mcs/build/common/SR.cs
Expand Up @@ -9,7 +9,9 @@ static class AssemblyRef
public const string EcmaPublicKey = "b77a5c561934e089";
public const string MicrosoftPublicKey = "b03f5f7f11d50a3a";

public const string MicrosoftJScript = Consts.AssemblyMicrosoft_JScript;
public const string MicrosoftVSDesigner = Consts.AssemblyMicrosoft_VSDesigner;
public const string SystemData = Consts.AssemblySystem_Data;
public const string SystemDesign = Consts.AssemblySystem_Design;
public const string SystemDrawing = Consts.AssemblySystem_Drawing;
public const string SystemWeb = Consts.AssemblySystem_Web;
Expand Down
Expand Up @@ -115,8 +115,7 @@
<IISUrl>http://localhost:18572/</IISUrl>
<NTLMAuthentication>False</NTLMAuthentication>
<UseCustomServer>False</UseCustomServer>
<CustomServerUrl>
</CustomServerUrl>
<CustomServerUrl></CustomServerUrl>
<SaveServerSettingsInUserFile>False</SaveServerSettingsInUserFile>
</WebProjectProperties>
</FlavorProperties>
Expand Down
2 changes: 1 addition & 1 deletion mcs/class/System.Data/System.Data/DataSet.cs
Expand Up @@ -781,7 +781,7 @@ public void WriteXmlSchema (XmlWriter writer)

public void ReadXmlSchema (Stream stream)
{
XmlReader reader = new XmlTextReader (stream, null);
XmlReader reader = new XmlTextReader (stream, new NameTable ());
ReadXmlSchema (reader);
}

Expand Down
2 changes: 1 addition & 1 deletion mcs/class/System.Data/System.Data/DataTable.cs
Expand Up @@ -1742,7 +1742,7 @@ public static XmlSchemaComplexType GetDataTableSchema (XmlSchemaSet schemaSet)

public XmlReadMode ReadXml (Stream stream)
{
return ReadXml (new XmlTextReader(stream, null));
return ReadXml (new XmlTextReader(stream, new NameTable ()));
}

public XmlReadMode ReadXml (string fileName)
Expand Down
5 changes: 4 additions & 1 deletion mcs/class/System.Data/System.Xml/XmlDataDocument.cs
Expand Up @@ -423,6 +423,9 @@ private void OnNodeInserted (object sender, XmlNodeChangedEventArgs args)
}

DataRow row = GetRowFromElement (args.NewParent as XmlElement);
if (row == null && args.Node is XmlCharacterData)
// check if grandparent is a new row and this node is one of its column values.
row = GetRowFromElement (args.NewParent.ParentNode as XmlElement);
if (row == null) {
// That happens only when adding table to existing DocumentElement (aka DataSet element)
if (args.NewParent == DocumentElement)
Expand Down Expand Up @@ -453,7 +456,7 @@ private void OnNodeInserted (object sender, XmlNodeChangedEventArgs args)
if (args.Node.NodeType != XmlNodeType.Comment) {
for (int i = 0; i < row.Table.Columns.Count; i++) {
DataColumn col = row.Table.Columns [i];
if (col.ColumnMapping == MappingType.SimpleContent)
if (col.ColumnMapping == MappingType.SimpleContent || col.ColumnName == XmlHelper.Decode (args.NewParent.LocalName))
row [col] = StringToObject (col.DataType, args.Node.Value);
}
}
Expand Down
Expand Up @@ -35,6 +35,8 @@ namespace MonoTests.System.Data
[TestFixture]
public class DataTableReadWriteXmlTest
{
public static readonly string EOL = Environment.NewLine;

void StandardizeXmlFormat(ref string xml)
{
XmlDocument doc = new XmlDocument();
Expand Down Expand Up @@ -124,11 +126,11 @@ public void TestWriteXml()
// Get XML for DataSet writes.
sw.GetStringBuilder().Length = 0;
ds.WriteXml(sw);
string xmlDSNone = sw.ToString().Replace ("\n", "\r\n");
string xmlDSNone = sw.ToString().Replace ("\n", EOL);

sw.GetStringBuilder().Length = 0;
ds.WriteXml(sw, XmlWriteMode.DiffGram);
string xmlDSDiffGram = sw.ToString().Replace ("\n", "\r\n");
string xmlDSDiffGram = sw.ToString().Replace ("\n", EOL);

sw.GetStringBuilder().Length = 0;
ds.WriteXml(sw, XmlWriteMode.WriteSchema);
Expand Down Expand Up @@ -186,11 +188,11 @@ public void TestWriteXml()

sw.GetStringBuilder().Length = 0;
ds.WriteXml(sw);
xmlDSNone = sw.ToString().Replace ("\n", "\r\n");
xmlDSNone = sw.ToString().Replace ("\n", EOL);

sw.GetStringBuilder().Length = 0;
ds.WriteXml(sw, XmlWriteMode.DiffGram);
xmlDSDiffGram = sw.ToString().Replace ("\n", "\r\n");;
xmlDSDiffGram = sw.ToString().Replace ("\n", EOL);

sw.GetStringBuilder().Length = 0;
ds.WriteXml(sw, XmlWriteMode.WriteSchema);
Expand Down
2 changes: 1 addition & 1 deletion mcs/class/System.Data/Test/System.Data/DataTableTest.cs
Expand Up @@ -54,7 +54,7 @@ namespace MonoTests.System.Data
[TestFixture]
public class DataTableTest : DataSetAssertion
{
string EOL = "\r\n";
string EOL = Environment.NewLine;

[Test]
public void Ctor()
Expand Down
Expand Up @@ -286,7 +286,7 @@ public void Navigator ()
Nav.MoveToNext ();
Assert.AreEqual ("Region", Nav.Name.ToString (), "test#06");

Assert.AreEqual ("2Western", Nav.Value.Substring(0, Nav.Value.IndexOf ("\n") - 1), "test#07");
Assert.AreEqual ("2Western", Nav.Value.Substring(0, Nav.Value.IndexOf (EOL)), "test#07");
Nav.MoveToFirstChild ();
Assert.AreEqual ("2", Nav.Value, "test#08");
Nav.MoveToRoot ();
Expand Down
8 changes: 2 additions & 6 deletions mcs/class/System.Data/Test/System.Xml/XmlDataDocumentTest2.cs
Expand Up @@ -287,12 +287,8 @@ public void DataSet_ColumnNameWithSpaces ()
// No exception shud be thrown
XmlDataDocument doc = new XmlDataDocument (ds);

// Should fail to save as there are no rows
try {
doc.Save (new StringWriter ());
Fail ("#1");
} catch (InvalidOperationException) {
}
// Should not fail to save because of "no rows"
doc.Save (new StringWriter ());

table1.Rows.Add (new object[] {0});
table1.Rows.Add (new object[] {1});
Expand Down
62 changes: 31 additions & 31 deletions mcs/class/System.Data/Test/System.Xml/region.xml
@@ -1,31 +1,31 @@
<?xml version="1.0" standalone="yes"?>
<Root>
<Region>
<RegionID>1</RegionID>
<RegionDescription>Eastern
</RegionDescription>
</Region>
<Region>
<RegionID>2</RegionID>
<RegionDescription>Western
</RegionDescription>
</Region>
<Region>
<RegionID>3</RegionID>
<RegionDescription>Northern
</RegionDescription>
</Region>
<Region>
<RegionID>4</RegionID>
<RegionDescription>Southern
</RegionDescription>
</Region>
<MoreData>
<Column1>12</Column1>
<Column2>Hi There</Column2>
</MoreData>
<MoreData>
<Column1>12</Column1>
<Column2>Hi There</Column2>
</MoreData>
</Root>
<?xml version="1.0" standalone="yes"?>
<Root>
<Region>
<RegionID>1</RegionID>
<RegionDescription>Eastern
</RegionDescription>
</Region>
<Region>
<RegionID>2</RegionID>
<RegionDescription>Western
</RegionDescription>
</Region>
<Region>
<RegionID>3</RegionID>
<RegionDescription>Northern
</RegionDescription>
</Region>
<Region>
<RegionID>4</RegionID>
<RegionDescription>Southern
</RegionDescription>
</Region>
<MoreData>
<Column1>12</Column1>
<Column2>Hi There</Column2>
</MoreData>
<MoreData>
<Column1>12</Column1>
<Column2>Hi There</Column2>
</MoreData>
</Root>
Expand Up @@ -143,8 +143,7 @@ public bool CanImport (XmlSchemaSet schemas)
if (schemas == null)
throw new ArgumentNullException ("schemas");

if (!schemas.IsCompiled)
schemas.Compile ();
PrepareSchemas (schemas);

foreach (XmlSchemaElement xe in schemas.GlobalElements.Values)
if (!CanImport (schemas, xe))
Expand All @@ -159,8 +158,7 @@ public bool CanImport (XmlSchemaSet schemas, ICollection<XmlQualifiedName> typeN
if (typeNames == null)
throw new ArgumentNullException ("typeNames");

if (!schemas.IsCompiled)
schemas.Compile ();
PrepareSchemas (schemas);

foreach (var name in typeNames)
if (!CanImport (schemas, name))
Expand All @@ -175,8 +173,7 @@ public bool CanImport (XmlSchemaSet schemas, XmlQualifiedName typeName)
if (typeName == null)
throw new ArgumentNullException ("typeName");

if (!schemas.IsCompiled)
schemas.Compile ();
PrepareSchemas (schemas);

if (IsPredefinedType (typeName))
return true; // while it just ignores...
Expand All @@ -194,8 +191,7 @@ public bool CanImport (XmlSchemaSet schemas, XmlSchemaElement element)
if (element == null)
throw new ArgumentNullException ("element");

if (!schemas.IsCompiled)
schemas.Compile ();
PrepareSchemas (schemas);

if (element.ElementSchemaType != null)
return CanImport (schemas, element.ElementSchemaType as XmlSchemaType);
Expand Down Expand Up @@ -390,13 +386,21 @@ bool CanImport (XmlSchemaSet schemas, XmlSchemaComplexType type)

// Import

void PrepareSchemas (XmlSchemaSet schemas)
{
if (!schemas.Contains (KnownTypeCollection.MSSimpleNamespace))
schemas.Add (XmlSchema.Read (GetType ().Assembly.GetManifestResourceStream ("mstypes.schema"), null));

if (!schemas.IsCompiled)
schemas.Compile ();
}

public void Import (XmlSchemaSet schemas)
{
if (schemas == null)
throw new ArgumentNullException ("schemas");

if (!schemas.IsCompiled)
schemas.Compile ();
PrepareSchemas (schemas);

foreach (XmlSchemaElement xe in schemas.GlobalElements.Values)
Import (schemas, xe);
Expand All @@ -420,8 +424,7 @@ public void Import (XmlSchemaSet schemas, XmlQualifiedName typeName)
if (typeName == null)
throw new ArgumentNullException ("typeName");

if (!schemas.IsCompiled)
schemas.Compile ();
PrepareSchemas (schemas);

if (IsPredefinedType (typeName))
return;
Expand Down
Expand Up @@ -31,7 +31,6 @@
using System.Runtime.Serialization;
using System.Xml;
using System.Xml.Schema;
using Mono.Xml.XPath;

namespace System.ServiceModel.Channels
{
Expand Down
49 changes: 49 additions & 0 deletions mcs/class/System.XML/Dummy.cs
@@ -0,0 +1,49 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Xml.Schema;

namespace System.Xml
{
static partial class Res
{
public static string GetString (string s, params object [] args)
{
return args == null ? s : string.Format (s, args);
}
}
}

namespace System.Xml.Utils
{
static partial class Res
{
public static string GetString (string s, params object [] args)
{
return args == null || args.Length == 0 ? s : string.Format (s, args);
}
}
}

// workaround for missing members in corlib.
namespace System.Security.Policy
{
static class EvidenceExtensions
{
public static void AddHostEvidence (this Evidence evidence, Url url)
{
throw new NotImplementedException ();
}
public static void AddHostEvidence (this Evidence evidence, Zone zone)
{
throw new NotImplementedException ();
}
public static void AddHostEvidence (this Evidence evidence, Site site)
{
throw new NotImplementedException ();
}
public static void AddHostEvidence (this Evidence evidence, EvidenceBase e)
{
throw new NotImplementedException ();
}
}
}
34 changes: 7 additions & 27 deletions mcs/class/System.XML/Makefile
Expand Up @@ -13,12 +13,17 @@ ifdef USE_BOOT_COMPILE
LIBRARY_COMPILE = $(BOOT_COMPILE)
endif

# FIXME: use below, once mcs got fixed.
#RESOURCE_STRINGS = ../../../external/referencesource/System.Xml/System.Xml.txt
# ../../../external/referencesource/System.Data.SqlXml/System.Xml.Utils.txt

PROFILE_ANY_MOBILE := $(filter monotouch monotouch_runtime monodroid xammac mobile mobile_static, $(PROFILE))

LIB_REFS = System
LIB_MCS_FLAGS = -r:$(corlib) -nowarn:0618,0612,0642
LIB_MCS_FLAGS = -r:$(corlib) -nowarn:0618,0612,0642 -unsafe -d:ASYNC -d:DISABLE_CAS_USE -d:MONO_HYBRID_SYSTEM_XML

ifeq (2.1, $(FRAMEWORK_VERSION))
LIB_MCS_FLAGS += -unsafe -d:AGCLR -d:NET_2_1_HACK
LIB_MCS_FLAGS += -unsafe -d:AGCLR -d:NET_2_1_HACK -d:DISABLE_XSLT_COMPILER -d:DISABLE_XSLT_SCRIPT
endif
TEST_MCS_FLAGS = $(LIB_MCS_FLAGS) -nowarn:0618 -nowarn:219 -nowarn:169 -r:System.Data.dll -r:System.Core.dll

Expand Down Expand Up @@ -66,31 +71,6 @@ EXTRA_DISTFILES = \
$(xmlfiles_files:%=Test/XmlFiles/%) \
$(nist_dom_files:%=Test/System.Xml/nist_dom/%)

System.Xml.XPath/$(PROFILE)_Parser.cs: System.Xml.XPath/Parser.jay $(topdir)/jay/skeleton.cs
(cd System.Xml.XPath; $(topdir)/../jay/jay -ct < $(topdir)/../jay/skeleton.cs Parser.jay > $(PROFILE)_Parser.cs)

Mono.Xml.Xsl/$(PROFILE)_PatternParser.jay: System.Xml.XPath/Parser.jay $(topdir)/jay/skeleton.cs
sed "s/\%start Expr/\%start Pattern/" $< >$@

Mono.Xml.Xsl/$(PROFILE)_PatternParser.cs: Mono.Xml.Xsl/$(PROFILE)_PatternParser.jay $(topdir)/jay/skeleton.cs
echo "#define XSLT_PATTERN" > $@
(cd Mono.Xml.Xsl; $(topdir)/../jay/jay -ct $(PROFILE)_PatternParser.jay < $(topdir)/../jay/skeleton.cs >> $(PROFILE)_PatternParser.cs)

Mono.Xml.Xsl/$(PROFILE)_PatternTokenizer.cs: System.Xml.XPath/Tokenizer.cs
echo "#define XSLT_PATTERN" > $@
cat $< >>$@

ifneq (moonlight_raw, $(PROFILE))
BUILT_SOURCES = System.Xml.XPath/$(PROFILE)_Parser.cs \
Mono.Xml.Xsl/$(PROFILE)_PatternParser.cs \
Mono.Xml.Xsl/$(PROFILE)_PatternTokenizer.cs

CLEAN_FILES = Test/XmlFiles/xsl/result.xml \
System.Xml.XPath/$(PROFILE)_Parser.cs \
Mono.Xml.Xsl/$(PROFILE)_PatternParser.cs \
Mono.Xml.Xsl/$(PROFILE)_PatternTokenizer.cs
endif

include ../../build/library.make

ifeq (bare/,$(intermediate))
Expand Down
9 changes: 9 additions & 0 deletions mcs/class/System.XML/ReferenceSources/SpecifiedAccessor.cs
@@ -0,0 +1,9 @@
namespace System.Xml.Serialization
{
// from Models.cs
internal enum SpecifiedAccessor {
None,
ReadOnly,
ReadWrite,
}
}
5 changes: 5 additions & 0 deletions mcs/class/System.XML/ReferenceSources/ThisAssembly.cs
@@ -0,0 +1,5 @@
static class ThisAssembly
{
public const string Version = Consts.FxVersion;
}

0 comments on commit e9ef998

Please sign in to comment.