/*******************************************************************************
* Copyright (c) 2013 Bruno Medeiros and other Contributors.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Bruno Medeiros - initial API and implementation
*******************************************************************************/
package dtool.ast.statements;
import static melnorme.utilbox.core.Assert.AssertNamespace.assertNotNull;
import melnorme.lang.tooling.ast.CommonASTNode;
import melnorme.lang.tooling.ast.IASTVisitor;
import melnorme.lang.tooling.ast.util.ASTCodePrinter;
import melnorme.lang.tooling.ast_actual.ASTNodeTypes;
import melnorme.lang.tooling.engine.PickedElement;
import dtool.ast.definitions.DefSymbol;
import dtool.ast.definitions.DefUnit;
import dtool.ast.definitions.EArcheType;
import dtool.ast.expressions.Expression;
import dtool.ast.expressions.IInitializer;
import dtool.ast.references.Reference;
import dtool.engine.analysis.CommonDefVarSemantics;
import dtool.engine.analysis.IVarDefinitionLike;
public class VariableDefWithInit extends DefUnit implements IVarDefinitionLike {
public final Reference type;
public final Expression defaultValue;
public VariableDefWithInit(Reference type, DefSymbol defId, Expression defaultValue) {
super(defId);
this.type = parentize(assertNotNull(type));
this.defaultValue = parentize(defaultValue);
}
@Override
public ASTNodeTypes getNodeType() {
return ASTNodeTypes.VARIABLE_DEF_WITH_INIT;
}
@Override
public void visitChildren(IASTVisitor visitor) {
acceptVisitor(visitor, type);
acceptVisitor(visitor, defName);
acceptVisitor(visitor, defaultValue);
}
@Override
protected CommonASTNode doCloneTree() {
return new VariableDefWithInit(clone(type), clone(defName), clone(defaultValue));
}
@Override
public void toStringAsCode(ASTCodePrinter cp) {
cp.append(type, " ");
cp.append(defName);
cp.append(" = ", defaultValue);
}
@Override
public EArcheType getArcheType() {
return EArcheType.Variable;
}
@Override
public Reference getDeclaredType() {
return type;
}
@Override
public IInitializer getDeclaredInitializer() {
return defaultValue;
}
/* ----------------- ----------------- */
@Override
protected CommonDefVarSemantics doCreateSemantics(PickedElement<?> pickedElement) {
return new CommonDefVarSemantics(this, pickedElement);
}
}