package scotch.compiler.syntax.value;
import static lombok.AccessLevel.PACKAGE;
import static scotch.compiler.syntax.definition.Definitions.scopeDef;
import static scotch.compiler.syntax.reference.DefinitionReference.scopeRef;
import lombok.AllArgsConstructor;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import scotch.compiler.analyzer.DependencyAccumulator;
import scotch.compiler.analyzer.NameAccumulator;
import scotch.compiler.analyzer.OperatorAccumulator;
import scotch.compiler.analyzer.PrecedenceParser;
import scotch.compiler.analyzer.NameQualifier;
import scotch.compiler.analyzer.TypeChecker;
import scotch.compiler.intermediate.IntermediateGenerator;
import scotch.compiler.intermediate.IntermediateValue;
import scotch.compiler.syntax.Scoped;
import scotch.compiler.syntax.definition.Definition;
import scotch.compiler.syntax.pattern.PatternReducer;
import scotch.compiler.syntax.reference.DefinitionReference;
import scotch.compiler.text.SourceLocation;
import scotch.symbol.Symbol;
import scotch.compiler.syntax.type.Type;
@AllArgsConstructor(access = PACKAGE)
@EqualsAndHashCode(callSuper = false)
@ToString(exclude = "sourceLocation")
public class ValueScope extends Value implements Scoped {
private final SourceLocation sourceLocation;
private final Symbol symbol;
private final Value value;
@Override
public Value accumulateDependencies(DependencyAccumulator state) {
return state.keep(withValue(value.accumulateDependencies(state)));
}
@Override
public Definition getDefinition() {
return scopeDef(sourceLocation, symbol);
}
@Override
public DefinitionReference getReference() {
return scopeRef(symbol);
}
private ValueScope withValue(Value value) {
return new ValueScope(sourceLocation, symbol, value);
}
@Override
public Value accumulateNames(NameAccumulator state) {
throw new UnsupportedOperationException(); // TODO
}
@Override
public Value bindMethods(TypeChecker typeChecker) {
return typeChecker.scoped(this, () -> new ValueScope(sourceLocation, symbol, value.bindMethods(typeChecker)));
}
@Override
public Value bindTypes(TypeChecker typeChecker) {
return new ValueScope(sourceLocation, symbol, value.bindTypes(typeChecker));
}
@Override
public Value checkTypes(TypeChecker typeChecker) {
return typeChecker.scoped(this, () -> new ValueScope(sourceLocation, symbol, value.checkTypes(typeChecker)));
}
@Override
public Value defineOperators(OperatorAccumulator state) {
throw new UnsupportedOperationException(); // TODO
}
@Override
public IntermediateValue generateIntermediateCode(IntermediateGenerator state) {
return value.generateIntermediateCode(state);
}
@Override
public SourceLocation getSourceLocation() {
return sourceLocation;
}
@Override
public Type getType() {
return value.getType();
}
@Override
public Value parsePrecedence(PrecedenceParser state) {
throw new UnsupportedOperationException(); // TODO
}
@Override
public Value qualifyNames(NameQualifier state) {
throw new UnsupportedOperationException(); // TODO
}
@Override
public Value reducePatterns(PatternReducer reducer) {
throw new UnsupportedOperationException(); // TODO
}
@Override
public Value withType(Type type) {
throw new UnsupportedOperationException(); // TODO
}
}