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); }
/// <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; }
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)); } }
/// <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; }
/// <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 }); }
/// <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 }); }
/// <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)); }
/// <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)); }
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)); } }
/// <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; }