Ejemplo n.º 1
0
 /// <summary>
 /// Execute the variable
 /// </summary>
 /// <param name="w">writer</param>
 /// <param name="indentValue">space size</param>
 /// <param name="currentLine">in-progress line add</param>
 /// <param name="config">configuration</param>
 /// <param name="dir">directory</param>
 public void Execute(TextWriter w, ref int indentValue, ref string currentLine, Dictionary <string, LuigiVariable> vars, Dictionary <string, Accumulate.Accu> types, string dir)
 {
     if (LeftValueType == LuigiVariableType.VAR)
     {
     }
     else if (LeftValueType == LuigiVariableType.REF)
     {
         Accumulate.AccuChild a = Accumulate.Accu.RecursiveFindByName(types, this.name);
         if (RightValueType == LuigiVariableType.VAR)
         {
             if (vars.ContainsKey(this.value))
             {
                 a.Value = vars[this.value].Value;
             }
         }
         else if (RightValueType == LuigiVariableType.CONST)
         {
             a.Value = this.Value;
         }
         else if (RightValueType == LuigiVariableType.NEW)
         {
             Accumulate.Accu n = Accumulate.Accu.FindByName(types, this.Value);
             a.SetReference(n.TypeName);
         }
         else
         {
             // gets the variable element
             // set the accuchild with an another accuchild
             Accumulate.AccuChild b = Accumulate.Accu.RecursiveFindByName(types, this.name);
         }
     }
 }
Ejemplo n.º 2
0
 /// <summary>
 /// Recursive find by name starting by a reference
 /// </summary>
 /// <param name="vars">all variables</param>
 /// <param name="types">all types</param>
 /// <param name="name">name to find</param>
 /// <returns>an accu child</returns>
 public static Accumulate.AccuChild RecursiveFindByName(Dictionary <string, LuigiVariable> vars, Dictionary <string, Accumulate.Accu> types, string name)
 {
     string[] seq = name.Split('.');
     if (seq.Length > 1)
     {
         if (vars.ContainsKey(seq[0].Substring(1)))
         {
             LuigiVariable v = vars[seq[0].Substring(1)];
             if (v.LeftValueType == LuigiVariableType.VAR && v.RightValueType == LuigiVariableType.NEW)
             {
                 // value est une reference sur un accu
                 Accumulate.Accu      a = Accumulate.Accu.FindByName(types, v.Value);
                 Accumulate.AccuChild c = Accumulate.AccuChild.RecursiveFindByName(a, 1, seq);
             }
             else
             {
                 throw new FormatException(String.Format("{0} is not a reference accu", seq[0]));
             }
         }
         else
         {
             throw new KeyNotFoundException(String.Format("Variable name {0} not found", seq[0]));
         }
     }
     else
     {
         throw new ArgumentException("bad name", "name");
     }
 }
Ejemplo n.º 3
0
 /// <summary>
 /// Add a variable
 /// </summary>
 /// <param name="key">key name</param>
 /// <param name="val">string value</param>
 public void AddVariable(string key, string val)
 {
     if (this.variables.ContainsKey(key))
     {
         Accumulate.Accu      a     = this.variables[key];
         Accumulate.AccuChild child = a.Values.Last(x => x.Name == "value") as Accumulate.AccuChild;
         child.Value = val;
     }
     else
     {
         Accumulate.Accu a = new Accumulate.Accu(key, Path.Combine("Luigi", "value.prt"));
         a.TypeName = key;
         Accumulate.AccuChild child = a.Values.Last(x => x.Name == "value") as Accumulate.AccuChild;
         child.Value = val;
         this.variables.Add(key, a);
     }
 }
Ejemplo n.º 4
0
 /// <summary>
 /// Write output as interpretation result
 /// </summary>
 /// <param name="w">writer</param>
 /// <param name="indentValue">space size</param>
 /// <param name="currentLine">in-progress line add</param>
 /// <param name="conf">configuration data</param>
 public void Execute(TextWriter w, ref int indentValue, ref string currentLine, Printer.Configuration conf)
 {
     foreach (KeyValuePair <string, string> kv in this.copy)
     {
         Accumulate.AccuChild a = Accumulate.Accu.RecursiveFindByName(this.types, this.variables, kv.Key);
         if (kv.Value.StartsWith("$const."))
         {
             string val             = kv.Value.Substring(7);
             Accumulate.AccuChild b = Accumulate.Accu.RecursiveFindByName(this.types, this.variables, "$const.value");
             b.Value = val;
             a.Value = b.Execute(conf, this.CurrentDirectory);
         }
         else
         {
             Accumulate.AccuChild b = Accumulate.Accu.RecursiveFindByName(this.types, this.variables, kv.Value);
             a.Value = b.Execute(conf, this.CurrentDirectory);
         }
     }
     foreach (string e in this.datas)
     {
         if (e.StartsWith("[") && e.EndsWith("]"))
         {
             string r = e.Substring(1, e.Length - 2);
             r = conf.Execute(r);
             // TO DO : execute an accu with its values
             if (this.variables.ContainsKey(r))
             {
                 this.variables[r].Execute(w, ref indentValue, ref currentLine, config);
             }
         }
         else
         {
             string res = conf.Execute(e);
             LuigiObject.IndentSource(w, indentValue, ref currentLine, res);
         }
     }
 }