// createGUIQuestion creates a GUIQuestion, the last argument indicates if the question should be disabled (no entry allowed) func createGUIQuestion(question interfaces.Question, callback func(interfaces.Expr, error), disabled bool) *GUIQuestion { questionLabel := createLabel(question.LabelAsString()) guiElementVisitor := newQuestionTypeToGUIElementVisitor(question, callback, disabled) questionElement := question.VarDeclValueType().Accept(guiElementVisitor, nil).(ui.Control) errorLabel := createLabel("") return &GUIQuestion{questionLabel, questionElement, errorLabel, question} }
// checkQuestionForRedeclarationWithDifferentTypes checks if the passed question has been declared before with a different type, and if so, adds an error to the typechecker func checkQuestionForRedeclarationWithDifferentTypes(question interfaces.Question, typeCheckArgs interfaces.TypeCheckArgs) { varDecl := question.VarDecl() varID := varDecl.VariableIdentifier() if typeCheckArgs.Symbols().IsTypeSetForVarID(varID) && typeCheckArgs.Symbols().TypeForVarID(varID) != varDecl.ValueType() { typeCheckArgs.TypeChecker().AddEncounteredError(errors.NewQuestionRedeclaredWithDifferentTypesError(varDecl.ValueType(), typeCheckArgs.Symbols().TypeForVarID(varID))) } }
// checkQuestionForDuplicateLabels checks if there are multiple questions with the same label, and if so, adds an warning to the typechecker func checkQuestionForDuplicateLabels(question interfaces.Question, typeChecker interfaces.TypeChecker) { labelKnown := typeChecker.IsLabelUsed(question.Label()) if labelKnown { typeChecker.AddEncounteredWarning(errors.NewDuplicateLabelWarning(question, typeChecker.VarIDForLabel(question.Label()))) return } typeChecker.MarkLabelAsUsed(question.Label(), question.VarDecl()) }
// checkForCyclicDependencies checks if the this question depends on itself, and if so, adds an error to the typechecker func checkForCyclicDependencies(question interfaces.Question, typeChecker interfaces.TypeChecker) { // if we find our own VarID as a dependency at least once, the dependencyChain is cyclic if typeChecker.DependencyListForVarDeclContainsReferenceToSelf(question.VarDecl()) { typeChecker.AddEncounteredError(errors.NewCyclicDependencyError(question.VarDecl())) } }