Beispiel #1
0
 public override void setValue(Variable other)
 {
     if (!assigned)
     {
         assign();
     }
     _list = other.getValue();
     trace("setValue", new dynamic[] { other.getRawValue() });
 }
Beispiel #2
0
 public void addValue(Variable x)
 {
     if (!assigned)
     {
         assign();
     }
     _list.Add(x);
     trace("addValue", new dynamic[] { x.getRawValue() });
 }
Beispiel #3
0
        /// <summary>
        /// Create a new <see cref="VarTracer"/>
        /// </summary>
        /// <param name="traced"> the traced <see cref="Variable"/></param>
        public VarTracer(Variable traced) : base(traced)
        {
            _traced_var = traced;
            printTrace(("trace type: " + traced.trace_mode));
            var creation_event =
                new Event(new Alteration("creation", _traced_var, _traced_var.getRawValue(), new dynamic[] { }, traced.trace_mode));

            events.Push(creation_event); // tracer creation event
            last_stack_count = 1;
            callUpdateHandler(creation_event.alter);
        }
Beispiel #4
0
 public void insertValue(Variable x, Integer index)
 {
     assertAssignment();
     _list.Insert(index.getValue(), x);
     trace("insertValue", new dynamic[] { index.getRawValue(), x.getRawValue() });
 }
Beispiel #5
0
        public override void execute()
        {
            setContext();

            // get variable value
            Variable variable_value = _var_expr.evaluate();

            // is the value assigned ? (only relevant if other variable)
            variable_value.assertAssignment();
            Variable variable = Variable.fromRawValue(variable_value.getRawValue());

            // keep track of source vars -> should do something generic for lots of attributes ...
            if (variable is NumericalValue)
            {
                ((NumericalValue)variable).source_vars = new Dictionary <string, NumericalValue>(((NumericalValue)variable_value).source_vars);
            }
            variable.setName(_var_name);
            // explicit typing
            if (_var_type != StringConstants.Types.AUTO_TYPE)
            {
                Debugging.print("checking variable explicit type");
                Expression default_value = Global.default_values_by_var_type[_var_type];
                Debugging.assert(variable_value.hasSameParent(default_value.evaluate()));   // TypeException
            }
            // constant
            if (_constant)
            {
                if (variable_value.isConst())
                {
                    variable.setConst();
                }
                else
                {
                    throw new AquilaExceptions.InvalidVariableClassifierException(
                              "The \"const\" cannot be used when assigning to a non-const value");
                }
            }
            // actually declare it to its value
            if (_global)
            {
                Global.addGlobalVariable(_var_name, variable);
            }
            else
            {
                Global.getCurrentDict()[_var_name] = variable; // overwriting is mandatory
                Debugging.print("variable exists ", Global.variableExistsInCurrentScope(_var_name));
                if (_assignment)
                {
                    variable.assign();              // should not need this, but doing anyway
                }
                else
                {
                    variable.assigned = false;
                }
            }
            Debugging.print("finished declaration with value assignment: ", variable.assigned);

            // automatic tracing ?
            if (_assignment && Global.getSetting("auto trace"))
            {
                Debugging.print("Tracing variable: \"auto trace\" setting set to true");
                // Does NOT work by simply doing "variable.startTracing()", and idk why
                Tracing tracing_instr = new RawInstruction($"trace ${_var_name}", line_index).toInstr() as Tracing;
                //Tracing tracing_instr = new Tracing(line_index, new List<Expression>{_var_expr}); // <- does not work either :(
                tracing_instr.execute();
            }

            // update things 'n stuff
            Global.onElementaryInstruction();

            // reset Context
            Context.reset();
        }