@Override public PType caseAExternalDefinition(AExternalDefinition node) throws AnalysisException { return af.createPDefinitionAssistant().getType(node.getState()); }
@Override public PType caseAInheritedDefinition(AInheritedDefinition node) throws AnalysisException { checkSuperDefinition(node); return af.createPDefinitionAssistant().getType(node.getSuperdef()); }
@Override public Boolean caseALocalDefinition(ALocalDefinition node) throws AnalysisException { return node.getValueDefinition() != null || af.createPTypeAssistant().isType(af.createPDefinitionAssistant().getType(node), AParameterType.class) ? false : !af.createPTypeAssistant().isUnknown(af.createPDefinitionAssistant().getType(node)) && af.createPTypeAssistant().isFunction(af.createPDefinitionAssistant().getType(node)); }
@Override public Boolean caseALocalDefinition(ALocalDefinition node) throws AnalysisException { return node.getNameScope().matches(NameScope.STATE) || af.createPTypeAssistant().isClass(af.createPDefinitionAssistant().getType(node), null); }
@Override public void caseALocalDefinition(ALocalDefinition node, NewQuestion question) throws AnalysisException { if (node.getType() != null) { node.setType(af.createPTypeAssistant().typeResolve(question.question.assistantFactory.createPDefinitionAssistant().getType(node), null, question.rootVisitor, question.question)); } }
@Override public PDefinition defaultSClassDefinition(SClassDefinition classDefinition) throws AnalysisException { PDefinition def = AstFactory.newALocalDefinition(classDefinition.getLocation(), classDefinition.getName().getSelfName(), NameScope.LOCAL, af.createPDefinitionAssistant().getType(classDefinition)); af.createPDefinitionAssistant().markUsed(def); return def; }
@Override public void caseAClassType(AClassType type) throws AnalysisException { if (type.getResolved()) { type.setResolved(false); for (PDefinition d : type.getClassdef().getDefinitions()) { // PTypeAssistantTC.unResolve(af.createPDefinitionAssistant().getType(d)); af.createPTypeAssistant().unResolve(af.createPDefinitionAssistant().getType(d)); } } }
public boolean hasSupertype(SClassDefinition aClassDefDefinition, PType other) { if (af.createPTypeAssistant().equals(af.createPDefinitionAssistant().getType(aClassDefDefinition), other)) { return true; } else { for (PType type : aClassDefDefinition.getSupertypes()) { AClassType sclass = (AClassType) type; if (af.createPTypeAssistant().hasSupertype(sclass, other)) { return true; } } } return false; }
@Override public PType caseASelfObjectDesignator(ASelfObjectDesignator node, TypeCheckInfo question) { PDefinition def = question.env.findName(node.getSelf(), NameScope.NAMES); if (def == null) { TypeCheckerErrors.report(3263, "Cannot reference 'self' from here", node.getSelf().getLocation(), node.getSelf()); return AstFactory.newAUnknownType(node.getSelf().getLocation()); } return question.assistantFactory.createPDefinitionAssistant().getType(def); }
@Override public PType caseAParameterType(AParameterType type, Newquestion question) throws AnalysisException { if (type.getResolved()) { return type; } else { type.setResolved(true); } PDefinition p = question.question.env.findName(type.getName(), NameScope.NAMES); if (p == null || !(question.question.assistantFactory.createPDefinitionAssistant().getType(p) instanceof AParameterType)) { TypeCheckerErrors.report(3433, "Parameter type @" + type.getName() + " not defined", type.getLocation(), type); } return type; }
public PType caseATypeExport(ATypeExport exp, TypeCheckInfo question) throws AnalysisException { ILexNameToken name = exp.getName(); ITypeCheckerAssistantFactory af = question.assistantFactory; ModuleEnvironment menv = (ModuleEnvironment)question.env; PDefinition def = af.createPDefinitionListAssistant().findType(menv.getDefinitions(), name, name.getModule()); if (def == null) { TypeCheckerErrors.report(3187, "Exported type " + name + " not defined in module", name.getLocation(), exp); } else { if (exp.getStruct()) { PType type = af.createPDefinitionAssistant().getType(def); if (!(type instanceof ANamedInvariantType) && !(type instanceof ARecordInvariantType)) { TypeCheckerErrors.report(67, "Exported type " + name + " not structured", name.getLocation(), exp); } } } return null; }
node.setType(af.createPTypeAssistant().typeResolve(af.createPDefinitionAssistant().getType(node), null, question.rootVisitor, new TypeCheckInfo(question.question.assistantFactory, params, question.question.scope, question.question.qualifiers))); } else node.setType(af.createPTypeAssistant().typeResolve(af.createPDefinitionAssistant().getType(node), null, question.rootVisitor, question.question)); AFunctionType fType = (AFunctionType) af.createPDefinitionAssistant().getType(node); node.getName().setTypeQualifier(fType.getParameters());
node.setExpType(node.getExpression().apply(THIS, new TypeCheckInfo(question.assistantFactory, cenv, NameScope.NAMESANDSTATE, question.qualifiers))); ExcludedDefinitions.clearExcluded(); node.setType(question.assistantFactory.createPTypeAssistant().typeResolve(question.assistantFactory.createPDefinitionAssistant().getType(node), null, THIS, question)); if (!question.assistantFactory.getTypeComparator().compatible(question.assistantFactory.createPDefinitionAssistant().getType(node), node.getExpType())) TypeCheckerErrors.detail2("Declared", question.assistantFactory.createPDefinitionAssistant().getType(node), "Expression", node.getExpType());
@Override public SExpIR caseANarrowExp(ANarrowExp node, IRInfo question) throws AnalysisException { PExp exp = node.getTest(); PType type = null; if (node.getBasicType() != null) { type = node.getBasicType(); } else if (node.getTypedef() != null) { type = question.getTcFactory().createPDefinitionAssistant().getType(node.getTypedef()); } SExpIR expCg = exp.apply(question.getExpVisitor(), question); STypeIR typeCg; if (type != null) { typeCg = type.apply(question.getTypeVisitor(), question); } else { log.error("Could not find type of narrow expression"); typeCg = new AUnknownTypeIR(); typeCg.setSourceNode(new SourceNode(node)); } ACastUnaryExpIR cast = new ACastUnaryExpIR(); cast.setExp(expCg); cast.setType(typeCg); return cast; }
node.setType(af.createPTypeAssistant().typeResolve(question.question.assistantFactory.createPDefinitionAssistant().getType(node), null, question.rootVisitor, newQuestion)); } else AFunctionType fType = (AFunctionType) question.question.assistantFactory.createPDefinitionAssistant().getType(node); node.getName().setTypeQualifier(fType.getParameters());
@Override public SExpIR caseAIsExp(AIsExp node, IRInfo question) throws AnalysisException { PType checkedType = node.getBasicType(); if (checkedType == null) { checkedType = question.getTcFactory().createPDefinitionAssistant().getType(node.getTypedef()); } PExp exp = node.getTest(); SExpIR expCg = exp.apply(question.getExpVisitor(), question); if (expCg == null) { return null; } STypeIR checkedTypeCg = checkedType.apply(question.getTypeVisitor(), question); if (checkedTypeCg == null) { return null; } AGeneralIsExpIR generalIsExp = new AGeneralIsExpIR(); generalIsExp.setType(new ABoolBasicTypeIR()); generalIsExp.setExp(expCg); generalIsExp.setCheckedType(checkedTypeCg); return generalIsExp; }
@Override public PType caseAAssignmentDefinition(AAssignmentDefinition node, TypeCheckInfo question) throws AnalysisException { question.qualifiers = null; node.setType(question.assistantFactory.createPTypeAssistant().typeResolve(question.assistantFactory.createPDefinitionAssistant().getType(node), null, THIS, question)); ExcludedDefinitions.setExcluded(node); node.setExpType(node.getExpression().apply(THIS, question)); ExcludedDefinitions.clearExcluded(); question.assistantFactory.getTypeComparator().checkComposeTypes(node.getType(), question.env, false); if (node.getExpType() instanceof AVoidType) { TypeCheckerErrors.report(3048, "Expression does not return a value", node.getExpression().getLocation(), node.getExpression()); } if (!question.assistantFactory.getTypeComparator().compatible(node.getType(), node.getExpType())) { TypeCheckerErrors.report(3000, "Expression does not match declared type", node.getExpression().getLocation(), node); TypeCheckerErrors.detail2("Declared", node.getType(), "Expression", node.getExpType()); } return node.getType(); }
@Override public PType caseANarrowExp(ANarrowExp node, TypeCheckInfo question) throws AnalysisException { node.getTest().setType(node.getTest().apply(THIS, question.newConstraint(null))); PType result = null; if (node.getBasicType() != null) { node.setBasicType(question.assistantFactory.createPTypeAssistant().typeResolve(node.getBasicType(), null, THIS, question)); result = node.getBasicType(); question.assistantFactory.getTypeComparator().checkComposeTypes(result, question.env, false); } else { node.setTypedef(question.env.findType(node.getTypeName(), node.getLocation().getModule())); if (node.getTypedef() == null) { TypeCheckerErrors.report(3113, "Unknown type name '" + node.getTypeName() + "'", node.getLocation(), node); result = AstFactory.newAUnknownType(node.getLocation()); } else { result = question.assistantFactory.createPDefinitionAssistant().getType(node.getTypedef()); } } if (!question.assistantFactory.getTypeComparator().compatible(result, node.getTest().getType())) { TypeCheckerErrors.report(3317, "Expression can never match narrow type", node.getLocation(), node); } return question.assistantFactory.createPTypeAssistant().possibleConstraint(question.constraint, result, node.getLocation()); }
ILexNameToken name = node.getName(); AModuleModules from = node.getFrom(); def.setType((SInvariantType) question.assistantFactory.createPTypeAssistant().typeResolve(question.assistantFactory.createPDefinitionAssistant().getType(def), null, THIS, question));