package tlc2.debug;

import java.util.List;
import java.util.Random;

import org.eclipse.lsp4j.debug.Variable;

import tlc2.value.impl.Enumerable;
import tlc2.value.impl.FcnRcdValue;
import tlc2.value.impl.RecordValue;
import tlc2.value.impl.TLCVariable;
import tlc2.value.impl.TupleValue;
import tlc2.value.impl.Value;

public class DebugTLCVariable extends Variable implements tlc2.value.impl.TLCVariable {
	
	private transient Value value;
	
	public DebugTLCVariable(String lhs) {
		this.setName(lhs);
	}
	
	public DebugTLCVariable(Value value) {
		this.setName(value.toString());
	}

	public DebugTLCVariable[] getNested(Random rnd) {
		final List<TLCVariable> tlcVariables = this.value.getTLCVariables(this, rnd);
		return tlcVariables.toArray(new DebugTLCVariable[tlcVariables.size()]);
	}

	public void setInstance(Value v) {
		this.value = v;
	}

	@Override
	public TLCVariable newInstance(final String name, Value v, Random rnd) {
		DebugTLCVariable variable = new DebugTLCVariable(name);
		variable.setInstance(v);
		if (v instanceof Enumerable || v instanceof FcnRcdValue || v instanceof RecordValue || v instanceof TupleValue) {
			variable.setVariablesReference(rnd.nextInt(Integer.MAX_VALUE-1)+ 1);
		}
		return v.toTLCVariable(variable, rnd);
	}

	@Override
	public TLCVariable newInstance(Value value, Random rnd) {
		return newInstance(value.toString(), value, rnd);
	}
}
@@ -1,8 +1,1419 @@
+/*******************************************************************************%0A * Copyright (c) 2020 Microsoft Research. All rights reserved. %0A *%0A * The MIT License (MIT)%0A * %0A * Permission is hereby granted, free of charge, to any person obtaining a copy %0A * of this software and associated documentation files (the %22Software%22), to deal%0A * in the Software without restriction, including without limitation the rights%0A * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies%0A * of the Software, and to permit persons to whom the Software is furnished to do%0A * so, subject to the following conditions:%0A *%0A * The above copyright notice and this permission notice shall be included in all%0A * copies or substantial portions of the Software. %0A * %0A * THE SOFTWARE IS PROVIDED %22AS IS%22, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR%0A * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS%0A * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR%0A * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN%0A * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION%0A * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.%0A *%0A * Contributors:%0A *   Markus Alexander Kuppe - initial API and implementation%0A ******************************************************************************/%0A
 package 

Add license[Debugger]