private Symbol ProcessAliasedQuerySource(VerificationContext context, HeD.Engine.Model.Node source) { var sourceAlias = source.GetAttribute<String>("alias"); var sourceExpression = source.Children[0] as ASTNode; if (sourceExpression == null) { throw new InvalidOperationException(String.Format("Could not determine source expression for alias '{0}'.", sourceAlias)); } Verifier.Verify(context, sourceExpression); return new Symbol(sourceAlias, sourceExpression.ResultType); }
public void Verify(VerificationContext context, HeD.Engine.Model.ASTNode node) { Symbol sourceSymbol = null; // foreach source // add to the output context var sources = ((Node)node).Children.Where(c => c.Name == "source").ToList(); foreach (var source in sources) { if (sourceSymbol == null) { sourceSymbol = ProcessAliasedQuerySource(context, source); } else { throw new NotImplementedException("Multi-source query verification is not implemented."); } } if (sourceSymbol == null) { throw new InvalidOperationException("Could not determine query source type."); } var sourceSymbolListType = sourceSymbol.DataType as ListType; var sourceSymbolElementType = sourceSymbolListType != null ? sourceSymbolListType.ElementType : null; var sourceElementSymbol = sourceSymbolElementType != null ? new Symbol(sourceSymbol.Name, sourceSymbolElementType) : null; context.PushSymbol(sourceElementSymbol ?? sourceSymbol); try { // foreach define // add to the current scope var defines = ((Node)node).Children.Where(c => c.Name == "define").ToList(); foreach (var define in defines) { throw new NotImplementedException("Query defines are not implemented."); } // verify each with/without clause var relationships = ((Node)node).Children.Where(c => c.Name == "relationship").ToList(); foreach (var relationship in relationships) { var relatedSourceSymbol = ProcessAliasedQuerySource(context, relationship); var relatedSourceSymbolListType = relatedSourceSymbol.DataType as ListType; var relatedSourceSymbolElementType = relatedSourceSymbolListType != null ? relatedSourceSymbolListType.ElementType : null; var relatedSourceElementSymbol = relatedSourceSymbolElementType != null ? new Symbol(relatedSourceSymbol.Name, relatedSourceSymbolElementType) : null; context.PushSymbol(relatedSourceElementSymbol ?? relatedSourceSymbol); try { var suchThat = relationship.Children[1] as ASTNode; if (suchThat == null) { throw new InvalidOperationException(String.Format("Could not determine such that for relationship '{0}'.", relatedSourceSymbol.Name)); } Verifier.Verify(context, suchThat); context.VerifyType(suchThat.ResultType, DataTypes.Boolean); } finally { context.PopSymbol(); } } // verify the where clause var whereClause = ((Node)node).Children.Where(c => c.Name == "where").FirstOrDefault() as ASTNode; if (whereClause != null) { Verifier.Verify(context, whereClause); context.VerifyType(whereClause.ResultType, DataTypes.Boolean); } // verify the return clause var returnClause = ((Node)node).Children.Where(c => c.Name == "return").FirstOrDefault(); if (returnClause != null) { throw new NotImplementedException("Return clause is not implemented."); } // verify the sort clause var sortClause = ((Node)node).Children.Where(c => c.Name == "sort").FirstOrDefault(); if (sortClause != null) { throw new NotImplementedException("Sort clause is not implemented."); } node.ResultType = sourceSymbol.DataType; } finally { context.PopSymbol(); } }
public void Verify(VerificationContext context, HeD.Engine.Model.ASTNode node) { throw new NotImplementedException(); }
public void Verify(VerificationContext context, HeD.Engine.Model.ASTNode node) { // TODO: Implement generic identifier resolution. In theory, this isn't necessary because the CQL-to-ELM translator should never spit out this type of node. throw new InvalidOperationException(String.Format("Could not resolve identifier {0}{1}.", node.GetAttribute<String>("libraryName") ?? "", node.GetAttribute<String>("name"))); }
public HeD.Engine.Model.Library Read(HeD.Engine.Model.LibraryRef libraryRef) { DoMessage("Loading library document..."); var libraryDocument = XDocument.Load(libraryRef.Path, LoadOptions.SetLineInfo); DoMessage("Verifying artifact schema..."); var schemaSet = new XmlSchemaSet(); foreach (var schemaLocation in ELMLibrarySettings.Default.SchemaLocation.Split(';', ',', ' ')) { schemaSet.Add(null, schemaLocation); } libraryDocument.Validate(schemaSet, onValidationEvent, true); if (libraryDocument.Root.GetSchemaInfo().Validity != XmlSchemaValidity.Valid) { throw new InvalidOperationException("Library does not conform to the schema."); } var result = new HeD.Engine.Model.Library(); // TODO: Read library nodes... result.Name = libraryRef.Name; //result.Version; var ns = libraryDocument.Root.GetDefaultNamespace(); // Pull models var dataModelsElement = libraryDocument.Root.Element(ns + "usings"); if (dataModelsElement != null) { result.Models = ReadModels(ns, dataModelsElement.Elements(ns + "def")).ToList(); } else { result.Models = new List<HeD.Engine.Model.ModelRef>(); } // Pull libraries var librariesElement = libraryDocument.Root.Element(ns + "includes"); if (librariesElement != null) { result.Libraries = ReadLibraries(ns, librariesElement.Elements(ns + "def")).ToList(); } else { result.Libraries = new List<HeD.Engine.Model.LibraryRef>(); } // Pull Codesystems var codesystemsElement = libraryDocument.Root.Element(ns + "codeSystems"); if (codesystemsElement != null) { result.CodeSystems = ReadCodeSystems(ns, codesystemsElement.Elements(ns + "def")).ToList(); } else { result.CodeSystems = new List<HeD.Engine.Model.CodeSystemDef>(); } // Pull Valuesets var valuesetsElement = libraryDocument.Root.Element(ns + "valueSets"); if (valuesetsElement != null) { result.ValueSets = ReadValueSets(ns, valuesetsElement.Elements(ns + "def")).ToList(); } else { result.ValueSets = new List<HeD.Engine.Model.ValueSetDef>(); } // Pull parameters var parametersElement = libraryDocument.Root.Element(ns + "parameters"); if (parametersElement != null) { result.Parameters = ReadParameters(ns, parametersElement.Elements(ns + "def")).ToList(); } else { result.Parameters = new List<HeD.Engine.Model.ParameterDef>(); } // Pull expression defs var statementsElement = libraryDocument.Root.Element(ns + "statements"); if (statementsElement != null) { // TODO: FunctionDefs result.Expressions = ReadExpressionDefs(ns, statementsElement.Elements(ns + "def")).ToList(); } else { result.Expressions = new List<HeD.Engine.Model.ExpressionDef>(); } return result; }