internal virtual void Compile(FunctionalId functionalId, CompileState state)
        {
            if (PersistenceProvider is Neo4jPersistenceProvider neo4j && neo4j.Major < 4)
            {
                throw new NotSupportedException("Setting functional-id's on (batch) queries is not supported for Neo4j versions before v4.0.0");
            }

            if (!HasBlueprint41FunctionalidFnNext.Value || !HasBlueprint41FunctionalidFnNextNumeric.Value)
            {
                throw new NotSupportedException("Setting functional-id's on (batch) queries is not supported if the Blueprint41 plug-in is not installed or a lower version than 'blueprint41-4.0.2.jar'.");
            }

            if (functionalId.Guid == Guid.Empty)
            {
                state.Text.Append(FnUuidCreate);
            }
            if (functionalId.Format == IdFormat.Hash)
            {
                state.Text.AppendFormat(FnFunctionalIdNextHash, functionalId.Label);
            }
            else
            {
                state.Text.AppendFormat(FnFunctionalIdNextNumeric, functionalId.Label);
            }
        }
Example #2
0
        private void ReportCompileState(CompileState compileState)
        {
            if (compileState.HasErrors)
            {
                statusBar.BackColor    = Color.Red;
                statusBar.ForeColor    = Color.White;
                statusStrip1.BackColor = Color.Red;
                statusBar.Text         = "Error during compiling";

                var sbErr = new StringBuilder("Compiling file: ");
                sbErr.AppendLine();
                sbErr.AppendLine();
                foreach (string error in compileState.Errors)
                {
                    sbErr.AppendLine(error);
                }

                errorWindow.Text         = sbErr.ToString();
                tabControl.SelectedIndex = 1;
            }
            else
            {
                statusStrip1.BackColor = Color.Green;
                statusBar.BackColor    = Color.Green;
                statusBar.ForeColor    = Color.White;
                statusBar.Text         = "Compiled Succesfully";
                errorWindow.Text       = "";
            }
        }
        internal virtual void Compile(AliasResult alias, CompileState state)
        {
            if (alias.AliasName is null)
            {
                alias.AliasName = string.Format("n{0}", state.patternSeq++);
            }

            string?functionText = alias.FunctionText.Invoke(state.Translator);

            if (functionText is null)
            {
                state.Text.Append(alias.AliasName);
            }
            else
            {
                string[] compiledArgs = alias.FunctionArgs.Select(arg => state.Preview(GetCompile(arg), state)).ToArray();
                string   compiledText = string.Format(functionText.Replace("{base}", "{{base}}"), compiledArgs);

                if ((object?)alias.Alias is not null)
                {
                    string[] split = compiledText.Split(new string[] { "{base}" }, StringSplitOptions.None);
                    if (split.Length == 0)
                    {
                        throw new NotSupportedException("Functions have to include compilation of the base they are derived from.");
                    }

                    string baseText = state.Preview(alias.Alias.Compile, state);
                    state.Text.Append(string.Join(baseText, split));
                }
                else
                {
                    state.Text.Append(compiledText);
                }
            }
        }
 internal virtual void Compile(RelationFieldResult field, CompileState state)
 {
     if (!(field.Alias is null))
     {
         field.Alias.Compile(state);
         state.Text.Append(".");
     }
     state.Text.Append(field.FieldName);
 }
Example #5
0
 public LangVisitor(CompileState ts)
 {
     if (ts == null)
     {
         ts = new CompileState();
     }
     state   = ts;
     context = ts.Context;
 }
Example #6
0
 public IValueVisitor(CompileState ts)
 {
     if (ts == null)
     {
         throw new ArgumentNullException("ts");
     }
     state   = ts;
     context = ts.Context;
 }
        internal virtual void Compile(FieldResult field, CompileState state)
        {
            string?functionText = field.FunctionText.Invoke(state.Translator);

            if (functionText is null)
            {
                if ((object?)field.Alias is not null)
                {
                    field.Alias.Compile(state);
                    if (!string.IsNullOrEmpty(field.FieldName))
                    {
                        state.Text.Append(".");
                        state.Text.Append(field.FieldName);
                    }
                }
                else if (!string.IsNullOrEmpty(field.FieldName))
                {
                    state.Text.Append(field.FieldName);
                }
            }
            else
            {
                string[] compiledArgs = field.FunctionArgs.Select(arg => state.Preview(GetCompile(arg), state)).ToArray();
                string   compiledText = string.Format(functionText.Replace("{base}", "{{base}}"), compiledArgs);

                if ((object?)field.Field is not null)
                {
                    string[] split = compiledText.Split(new string[] { "{base}" }, StringSplitOptions.None);
                    if (split.Length == 0)
                    {
                        throw new NotSupportedException("Functions have to include compilation of the base they are derived from.");
                    }

                    string baseText = state.Preview(field.Field.Compile, state);
                    state.Text.Append(string.Join(baseText, split));
                }
                else if ((object?)field.Alias is not null)
                {
                    string[] split = compiledText.Split(new string[] { "{base}" }, StringSplitOptions.None);
                    if (split.Length == 0)
                    {
                        throw new NotSupportedException("Functions have to include compilation of the base they are derived from.");
                    }

                    string baseText = state.Preview(field.Alias.Compile, state);
                    state.Text.Append(string.Join(baseText, split));
                }
                else
                {
                    state.Text.Append(compiledText);
                }
            }
        }
Example #8
0
        private Type[] GetKnownTypes()
        {
            if (CompiledAssembly == null)
            {
                throw new Exception("Assembly is not compiled yet");
            }
            var assemblies = _cSharpProject.MetadataReferences.Select(i =>
            {
                if (i is PortableExecutableReference g)
                {
                    return(Sandbox.LoadByFullFilename(g.FilePath).WrappedAssembly);
                }
                throw new NotSupportedException(i.GetType().FullName);
            }).ToList();

            assemblies.Add(CompiledAssembly);
            return(CompileState.GetAllTypes(assemblies));
        }
Example #9
0
        public TranslationInfo ParseCsSource()
        {
            // must be public
            var knownTypes = GetKnownTypes();

            CheckRequiredTranslator();

            var translationInfo = new TranslationInfo(Sandbox);

            translationInfo.TranslationAssemblies.AddRange(_translationAssemblies);
            translationInfo.Prepare();
            // Console.WriteLine("======================");

            foreach (var tree in ProjectCompilation.SyntaxTrees)
            {
                var now = DateTime.Now;
                Console.WriteLine("parse file {0}", tree.FilePath);
                var root  = (CompilationUnitSyntax)tree.GetRoot();
                var state = new CompileState
                {
                    Context =
                    {
                        RoslynCompilation = ProjectCompilation,
                        RoslynModel       = ProjectCompilation.GetSemanticModel(tree)
                    }
                };
                translationInfo.State = state;

                var langVisitor = new LangVisitor(state)
                {
                    throwNotImplementedException = true
                };
                state.Context.KnownTypes = knownTypes;
                var compilationUnit = langVisitor.Visit(root) as CompilationUnit;
                translationInfo.Compiled.Add(compilationUnit);
                Console.WriteLine("    {0:0.0} sek", DateTime.Now.Subtract(now).TotalSeconds);
            }

            Console.WriteLine("Parsowanie c# skończone, mamy drzewo definicji");
            translationInfo.FillClassTranslations(knownTypes);
            return(translationInfo);
        }
        internal override void Compile(Parameter parameter, CompileState state)
        {
            if (!state.Parameters.Contains(parameter))
            {
                state.Parameters.Add(parameter);
            }

            if (parameter.IsConstant && !state.Values.Contains(parameter))
            {
                state.Values.Add(parameter);
            }

            if (parameter.Name == Parameter.CONSTANT_NAME)
            {
                parameter.Name = $"param{state.paramSeq}";
                state.paramSeq++;
            }
            state.Text.Append("$");
            state.Text.Append(parameter.Name);
        }
 internal virtual void Compile(AsResult result, CompileState state)
 {
     result.Result.Compile(state);
     state.Text.Append(" AS ");
     state.Text.Append(result.AliasName);
 }
        internal virtual void Compile(Node node, CompileState state, bool suppressAliases)
        {
            //find the root
            Node root = node;

            while (root.FromRelationship is not null)
            {
                root = root.FromRelationship.FromNode;
            }

            Node?current = root;

            do
            {
                GetDirection(current, state.Text);
                if (!(current.NodeAlias is null))
                {
                    if (current.NodeAlias.AliasName is null)
                    {
                        current.NodeAlias.AliasName = string.Format("n{0}", state.patternSeq++);
                    }

                    if (current.IsReference || current.Neo4jLabel is null)
                    {
                        state.Text.Append("(");
                        state.Text.Append(current.NodeAlias.AliasName);
                        state.Text.Append(")");
                    }
                    else
                    {
                        state.Text.Append("(");
                        if (!suppressAliases)
                        {
                            state.Text.Append(current.NodeAlias.AliasName);
                        }
                        state.Text.Append(":");
                        state.Text.Append(current.Neo4jLabel);
                        InlineConditions(current, state);
                        state.Text.Append(")");
                    }
                }
                else
                {
                    if (current.Neo4jLabel is null)
                    {
                        state.Text.Append("()");
                    }
                    else
                    {
                        state.Text.Append("(");
                        state.Text.Append(":");
                        state.Text.Append(current.Neo4jLabel);
                        InlineConditions(current, state);
                        state.Text.Append(")");
                    }
                }

                if (current.ToRelationship is not null)
                {
                    current.ToRelationship.Compile(state);
                    current = current.ToRelationship.ToNode;
                    if (current is null)
                    {
                        break;
                    }
                }
                else
                {
                    break;
                }
            } while (true);
        internal virtual void Compile(QueryCondition condition, CompileState state)
        {
            condition.Left  = Substitute(state, condition.Left);
            condition.Right = Substitute(state, condition.Right);

            if (condition.Operator == Operator.Boolean)
            {
                state.Text.Append("(");
                switch (condition.Left)
                {
                case BooleanResult boolean:
                    boolean.Compile(state);
                    break;

                case Literal literal:
                    literal.Compile(state);
                    break;
                }
                state.Text.Append(")");
                return;
            }

            Type?leftType  = GetOperandType(condition.Left);
            Type?rightType = GetOperandType(condition.Right);

            if (leftType is not null && rightType is not null)
            {
                if (leftType != rightType)
                {
                    if (condition.Operator == Operator.In)
                    {
                        if (rightType.GetInterface(nameof(IEnumerable)) is null)
                        {
                            state.Errors.Add($"The types of the fields {state.Preview(s => CompileOperand(s, condition.Right))} should be a collection.");
                        }

                        rightType = GetEnumeratedType(rightType);
                    }
                    if (GetConversionGroup(leftType, state.TypeMappings) != GetConversionGroup(rightType, state.TypeMappings))
                    {
                        state.Errors.Add($"The types of the fields {state.Preview(s => CompileOperand(s, condition.Left))} and {state.Preview(s => CompileOperand(s, condition.Right))} are not compatible.");
                    }
                }
            }

            state.Text.Append("(");
            if (condition.Operator == Operator.Not || condition.Operator == Operator.NotPattern)
            {
                state.Text.Append("NOT(");
            }
            else if (condition.Operator != Operator.Pattern)
            {
                CompileOperand(state, condition.Left);
            }

            if (condition.Right is Parameter)
            {
                Parameter rightParameter = (Parameter)condition.Right;
                if (rightParameter.IsConstant && rightParameter.Value is null)
                {
                    condition.Operator.Compile(state, true);
                    CompileOperand(state, null);
                }
                else
                {
                    condition.Operator.Compile(state, false);
                    CompileOperand(state, condition.Right);
                }
            }
            else
            {
                condition.Operator.Compile(state, condition.Right is null);
                CompileOperand(state, condition.Right);
            }

            if (condition.Operator == Operator.Not || condition.Operator == Operator.NotPattern)
            {
                state.Text.Append(")");
            }

            state.Text.Append(")");
        }
 internal virtual void Compile(PathResult path, CompileState state)
 {
     Compile(path.Alias, state);
 }
Example #15
0
 public void Execute(byte c, ref CompileState state)
 {
     state = _executor[(int)state].Execute((char)c);
 }
 internal virtual void Compile(Literal litheral, CompileState state)
 {
     state.Text.Append(litheral.Text);
 }
Example #17
0
        internal virtual void Compile(q.Query query, CompileState state)
        {
            switch (query.Type)
            {
            case PartType.Search:

                string        search = $"replace(trim(replace(replace(replace({state.Preview(query.SearchWords!.Compile, state)}, 'AND', '\"AND\"'), 'OR', '\"OR\"'), '  ', ' ')), ' ', ' {query.SearchOperator!.ToString().ToUpperInvariant()} ')";
                Node          node   = query.Patterns.First();
                AliasResult   alias  = node.NodeAlias !;
                AliasResult?  weight = query.Aliases?.FirstOrDefault();
                FieldResult[] fields = query.Fields !;

                List <string> queries = new List <string>();
                foreach (var property in fields)
                {
                    queries.Add(string.Format("({0}.{1}:' + {2} + ')", node.Neo4jLabel, property.FieldName, search));
                }

                state.Text.Append("CALL apoc.index.search('fts', '");
                state.Text.Append(string.Join(" OR ", queries));
                state.Text.Append("') YIELD node AS ");
                Compile(alias, state);
                if ((object?)weight != null)
                {
                    state.Text.Append(", weight AS ");
                    Compile(weight, state);
                }
                state.Text.Append(" WHERE (");
                Compile(alias, state);
                state.Text.Append(":");
                state.Text.Append(node.Neo4jLabel);
                state.Text.Append(")");
                break;

            case PartType.Match:
                state.Text.Append("MATCH ");
                query.ForEach(query.Patterns, state.Text, ", ", item => item?.Compile(state));
                break;

            case PartType.OptionalMatch:
                state.Text.Append("OPTIONAL MATCH ");
                query.ForEach(query.Patterns, state.Text, ", ", item => item?.Compile(state));
                break;

            case PartType.UsingScan:
                state.Text.Append("USING SCAN ");
                query.ForEach(query.Aliases, state.Text, "\r\nUSING SCAN ", item =>
                {
                    if (item.Node is null)
                    {
                        return;
                    }

                    item.Compile(state);
                    state.Text.Append(":" + item.Node.Neo4jLabel);
                });
                break;

            case PartType.UsingIndex:
                state.Text.Append("USING INDEX ");
                query.ForEach(query.Fields, state.Text, "\r\nUSING INDEX ", item =>
                {
                    if (item.Alias is null || item.Alias.Node is null)
                    {
                        return;
                    }

                    state.Text.Append(string.Format("{0}:{1}({2})", item.Alias.AliasName, item.Alias.Node.Neo4jLabel, item.FieldName));
                });