コード例 #1
0
ファイル: Helpers.cs プロジェクト: keithshort/HOPE
        public static void InitializeNoun(STS ssys, List<SemanticTypeDecl> decls, List<SemanticTypeStruct> structs)
        {
            // Reflective noun necessary for self-referential definition.
            SemanticTypeDecl decl = new SemanticTypeDecl() { OfTypeName = "Noun" };
            decl.AttributeValues.Add(new AttributeValue() { Name = "Name", Value = "Noun" });
            decls.Add(decl);

            SemanticTypeStruct sts = new SemanticTypeStruct() { DeclTypeName = "Noun" };
            sts.NativeTypes.Add(new Clifton.SemanticTypeSystem.NativeType() { Name = "Name", ImplementingType = "string" });
            structs.Add(sts);
        }
コード例 #2
0
ファイル: Helpers.cs プロジェクト: keithshort/HOPE
        /// <summary>
        /// Creates a root semantic type.
        /// </summary>
        public static SemanticTypeStruct CreateSemanticType(string name, bool unique, List<SemanticTypeDecl> decls, List<SemanticTypeStruct> structs)
        {
            SemanticTypeDecl decl = new SemanticTypeDecl() { OfTypeName = "Noun" };
            decl.AttributeValues.Add(new AttributeValue() { Name = "Name", Value = name });
            SemanticTypeStruct sts = new SemanticTypeStruct() { DeclTypeName = name, Unique = unique };

            decls.Add(decl);
            structs.Add(sts);

            return sts;
        }
コード例 #3
0
        protected void CopyDeclStruct(List <SemanticTypeDecl> decls, List <SemanticTypeStruct> structs, SemanticTypeStruct sts)
        {
            // Ignore duplicates.
            if (!decls.Contains(sts.DeclType))
            {
                decls.Add(sts.DeclType);
                structs.Add(sts);

                sts.SemanticElements.ForEach(child => CopyDeclStruct(decls, structs, (SemanticTypeStruct)child.Element.Struct));
            }
        }
コード例 #4
0
        /// <summary>
        /// Creates a custom type of the given name and known child protocols.
        /// </summary>
        public void CreateCustomType(string name, List <string> childProtocols)
        {
            List <SemanticTypeDecl>   decls   = new List <SemanticTypeDecl>();
            List <SemanticTypeStruct> structs = new List <SemanticTypeStruct>();

            SemanticTypeDecl   decl;
            SemanticTypeStruct sts;

            // Noun Decl.
            decl = new SemanticTypeDecl()
            {
                OfTypeName = "Noun"
            };
            decl.AttributeValues.Add(new AttributeValue()
            {
                Name = "Name", Value = "Noun"
            });
            decls.Add(decl);

            // Noun Struct.
            sts = new SemanticTypeStruct()
            {
                DeclTypeName = "Noun"
            };
            sts.NativeTypes.Add(new Clifton.SemanticTypeSystem.NativeType()
            {
                Name = "Name", ImplementingType = "string"
            });
            structs.Add(sts);

            // Custom type decl and struct.
            decl = new SemanticTypeDecl()
            {
                OfTypeName = "Noun"
            };
            decl.AttributeValues.Add(new AttributeValue()
            {
                Name = "Name", Value = name
            });
            sts = new SemanticTypeStruct()
            {
                DeclTypeName = name
            };
            decls.Add(decl);
            structs.Add(sts);

            // Elements of the custom type.
            foreach (string childProtocol in childProtocols)
            {
                sts.SemanticElements.Add(new Clifton.SemanticTypeSystem.SemanticElement()
                {
                    Name = childProtocol
                });
                // Recursively copy decls and structs of the existing types into our decls and structs lists.
                SemanticTypeStruct existingSts = (SemanticTypeStruct)GetSemanticTypeStruct(childProtocol);
                CopyDeclStruct(decls, structs, existingSts);
            }

            // Compile it.
            Parse(decls, structs);
            string code = GenerateCode();

            System.Reflection.Assembly assy = Compiler.Compile(code);
            CompiledAssembly = assy;
        }
コード例 #5
0
ファイル: Helpers.cs プロジェクト: keithshort/HOPE
 /// <summary>
 /// Associates an ST as a sub-element of the specified parent ST (sts).
 /// </summary>
 public static void CreateSemanticElement(SemanticTypeStruct sts, string subtypeName, bool unique)
 {
     sts.SemanticElements.Add(new Clifton.SemanticTypeSystem.SemanticElement() { Name = subtypeName, UniqueField = unique });
 }
コード例 #6
0
ファイル: Helpers.cs プロジェクト: keithshort/HOPE
 /// <summary>
 /// Creates a native type for the specified ST (sts).
 /// </summary>
 public static void CreateNativeType(SemanticTypeStruct sts, string name, string type, bool unique)
 {
     sts.NativeTypes.Add(new Clifton.SemanticTypeSystem.NativeType() { Name = name, ImplementingType = type, UniqueField = unique });
 }
コード例 #7
0
        /// <summary>
        /// Each native type in the struct
        /// </summary>
        public static void Match(SemanticTypeStruct ststruct, List <IAttributeValue> attrValues)
        {
            List <INativeType> nativeTypes = ststruct.NativeTypes;

            nativeTypes.ForEach(nt => Assert.That(attrValues.Any(attr => attr.Name == nt.Name), "Attribute mismatch between decl and struct for struct DeclType" + ststruct.DeclTypeName));
        }
コード例 #8
0
ファイル: Parser.cs プロジェクト: keithshort/HOPE
		/// <summary>
		/// Each native type in the struct 
		/// </summary>
		public static void Match(SemanticTypeStruct ststruct, List<IAttributeValue> attrValues)
		{
			List<INativeType> nativeTypes = ststruct.NativeTypes;
			nativeTypes.ForEach(nt => Assert.That(attrValues.Any(attr => attr.Name == nt.Name), "Attribute mismatch between decl and struct for struct DeclType" + ststruct.DeclTypeName));
		}
コード例 #9
0
ファイル: STS.cs プロジェクト: keithshort/HOPE
		protected void CopyDeclStruct(List<SemanticTypeDecl> decls, List<SemanticTypeStruct> structs, SemanticTypeStruct sts)
		{
			// Ignore duplicates.
			if (!decls.Contains(sts.DeclType))
			{
				decls.Add(sts.DeclType);
				structs.Add(sts);

				sts.SemanticElements.ForEach(child => CopyDeclStruct(decls, structs, (SemanticTypeStruct)child.Element.Struct));
			}
		}
コード例 #10
0
ファイル: STS.cs プロジェクト: keithshort/HOPE
		/// <summary>
		/// Creates a custom type of the given name and known child protocols.
		/// </summary>
		public void CreateCustomType(string name, List<string> childProtocols)
		{
			List<SemanticTypeDecl> decls = new List<SemanticTypeDecl>();
			List<SemanticTypeStruct> structs = new List<SemanticTypeStruct>();

			SemanticTypeDecl decl;
			SemanticTypeStruct sts;

			// Noun Decl.
			decl = new SemanticTypeDecl() { OfTypeName = "Noun" };
			decl.AttributeValues.Add(new AttributeValue() { Name = "Name", Value = "Noun" });
			decls.Add(decl);

			// Noun Struct.
			sts = new SemanticTypeStruct() { DeclTypeName = "Noun" };
			sts.NativeTypes.Add(new Clifton.SemanticTypeSystem.NativeType() { Name = "Name", ImplementingType = "string" });
			structs.Add(sts);

			// Custom type decl and struct.
			decl = new SemanticTypeDecl() { OfTypeName = "Noun" };
			decl.AttributeValues.Add(new AttributeValue() { Name = "Name", Value = name });
			sts = new SemanticTypeStruct() { DeclTypeName = name };
			decls.Add(decl);
			structs.Add(sts);

			// Elements of the custom type.
			foreach (string childProtocol in childProtocols)
			{
				sts.SemanticElements.Add(new Clifton.SemanticTypeSystem.SemanticElement() { Name = childProtocol});
				// Recursively copy decls and structs of the existing types into our decls and structs lists.
				SemanticTypeStruct existingSts = (SemanticTypeStruct)GetSemanticTypeStruct(childProtocol);
				CopyDeclStruct(decls, structs, existingSts);
			}

			// Compile it.
			Parse(decls, structs);
			string code = GenerateCode();
			System.Reflection.Assembly assy = Compiler.Compile(code);
			CompiledAssembly = assy;
		}