コード例 #1
0
 protected CodeConstruct(GeneratorScope scope, CodeConstruct from, object[] parameters)
 {
     Scope      = scope;
     From       = from;
     Parameters = parameters;
     scope.Codes.Add(this);
 }
コード例 #2
0
        public async Task <IGeneratorScope> StoredProcedure(Func <IGeneratorScope, Task> procedureBuilder)
        {
            var scope = new GeneratorScope(this, false, null);

            await procedureBuilder(scope);

            _ = scope.Store();
            Scopes.Push(scope);
            return(scope);
        }
コード例 #3
0
        /// <summary>
        /// Generate C# code for matching the DFA.
        /// </summary>
        /// <param name="indent"></param>
        /// <returns></returns>
        public string Generate(string indent, ReCodeGenerator generator)
        {
            var scope = new GeneratorScope(generator, indent);

            scope.WriteLine("/*");
            _root.Print(generator.StringBuilder, scope.Indentation + " * ", scope.Indentation + " * ");
            scope.WriteLine(" */");
            foreach (var state in _dfaStates)
            {
                GenerateCode(scope, state.EvaluationNode);
            }
            return(generator.StringBuilder.ToString());
        }
コード例 #4
0
 private void SubGenerate(GeneratorScope scope, IReadOnlyList <KeyValuePair <uint, RegExEvaluationNode> > nodes, int a, int b, RegExEvaluationNode target, ushort?currentState)
 {
     if (a > b)
     {
         scope.Goto(target == null ? scope.AcceptLabel(currentState) : scope.StateLabel(target.Id));
     }
     else
     {
         var m    = (a + b) / 2;
         var pair = nodes[m];
         scope.IfBegin(pair.Key, m - a);
         SubGenerate(scope.Indent(), nodes, a, m - 1, pair.Value, currentState);
         scope.IfEnd(m - a);
         SubGenerate(scope, nodes, m + 1, b, target, currentState);
     }
 }
コード例 #5
0
        public IGeneratorScope BeginScope(bool save = false)
        {
            var scope = new GeneratorScope(this, save, null);

            return(scope);
        }
コード例 #6
0
 public PropertyGetter(GeneratorScope scope, CodeConstruct from, MethodInfo method, object[] parameters) : base(scope, from, parameters)
 {
     Method = method;
 }
コード例 #7
0
 public Method(GeneratorScope generatorScope, CodeConstruct parent, MethodInfo method, object[] paramaters) : base(generatorScope, parent, paramaters)
 {
     InterfaceMethod = method;
 }
コード例 #8
0
 public PropertySetter(GeneratorScope scope, CodeConstruct from, MethodInfo method, object[] parameters) : base(scope, from, parameters)
 {
     Method = method;
     //parameterName = Method.Name.Replace("set_", "");
 }
コード例 #9
0
 public Nop(GeneratorScope scope) : base(scope, null, null)
 {
 }
コード例 #10
0
 public InstancePropertyInitializer(GeneratorScope generatorScope, Type type, string instanceName) :
     base(generatorScope, null, null)
 {
     Type         = type;
     variableName = instanceName;
 }
コード例 #11
0
 public ClassDefinition(GeneratorScope generatorScope, Type type, string classCreator, object[] paramaters) : base(generatorScope, null, paramaters)
 {
     Type         = type;
     ClassCreator = classCreator;
 }
コード例 #12
0
 public LiteralCode(GeneratorScope scope, string code) : base(scope, null, null)
 {
     Code = code;
 }
コード例 #13
0
 public Return(GeneratorScope scope, ICodeResult result) : base(scope, null, null)
 {
     Construct = result;
 }
コード例 #14
0
 public InstanceInitializer(GeneratorScope generatorScope, Type type, string instanceName, string instanceCreation, object[] paramaters) :
     base(generatorScope, $"var {instanceName} = {(paramaters.Length > 0 ? string.Format(instanceCreation, paramaters) : instanceCreation)}")
 {
     Type         = type;
     variableName = instanceName;
 }
コード例 #15
0
        private void GenerateCode(GeneratorScope scope, RegExEvaluationNode node)
        {
            var dfa          = _dfaStates[node.Id];
            var currentState = dfa.SmallestAcceptState;

#if DIAGNOSTICS
            Console.WriteLine($"Code generation for of state {dfa.DfaId}:");
            foreach (var range in node)
            {
                Console.WriteLine($" range {range.Key.Min}-{range.Key.Max} {range.Value?.Id} {range.Value?.AcceptAction}");
            }
#endif
            var points = new SortedDictionary <uint, RegExEvaluationNode>();

            RegExEvaluationNode lastValue = null;
            uint lastSuccessor            = 0;
            foreach (var pair in node)
            {
                if ((pair.Value == lastValue) && (lastSuccessor == pair.Key.Min))
                {
                    points.Remove(lastSuccessor);
                }
                else if (lastSuccessor < pair.Key.Min)
                {
                    points.Add(pair.Key.Min, null);
                }
                lastSuccessor = pair.Key.Max + 1;
                points.Add(lastSuccessor, pair.Value);
                lastValue = pair.Value;
            }
            if (lastSuccessor == char.MaxValue + 1)
            {
                points.Remove(lastSuccessor);
            }
            else
            {
                lastValue = null;
            }

#if DIAGNOSTICS
            Console.WriteLine("Points:");
            foreach (var pair in points)
            {
                Console.WriteLine(" point {0} -> {1}", pair.Key, pair.Value != null ? $"{pair.Value.Id} ({pair.Value.AcceptAction})" : string.Empty);
            }
#endif

            var accept = node.AcceptAction.HasValue ? $" (accepts to {node.AcceptAction.Value})" : string.Empty;
            scope.WriteLine("/*");
            scope.WriteLine(" * DFA STATE {0}{1}", node.Id, accept);
            foreach (var map in node)
            {
                scope.WriteLine(" * {0} -> {1}", map.Key, map.Value.Id);
            }
            scope.WriteLine(" */");
            if ((node.Id > 0) || NodeIsReferenced(node))
            {
                scope.SetLabel(scope.StateLabel(node.Id));
            }
            if (node.AcceptAction.HasValue && !(node.AcceptAction > currentState))
            {
                scope.MarkPos();
                if (node.Count > 0)
                {
                    scope.IncrementPos(scope.AcceptLabel(node.AcceptAction), node.Id == 0);
                }
            }
            else
            {
                if (node.Count > 0)
                {
                    scope.IncrementPos(scope.AcceptLabel(currentState), node.Id == 0);
                }
            }
            var pointList = points.ToList();
            if ((pointList.Count == 0) && (node.Count == 0))
            {
                scope.Goto(scope.AcceptLabel(currentState));
            }
            else
            {
                SubGenerate(scope, pointList, 0, points.Count - 1, lastValue, currentState);
            }
        }
コード例 #16
0
 public DateTimeNow(GeneratorScope scope)
 {
     this._Scope = scope;
 }
コード例 #17
0
 public NewGuid(GeneratorScope scope)
 {
     this._Scope = scope;
 }