@Override public void caseILexIdentifierToken(ILexIdentifierToken node) throws AnalysisException { validateName(node.getName(), node.getLocation(), /* no module */ null); }
public LexNameToken(String module, ILexIdentifierToken id) { super(id.getLocation(), VDMToken.NAME); this.module = module; this.name = id.getName(); this.old = id.isOld(); this.explicit = false; }
/** * @return The current default module's file name. */ @Override public File getDefaultFile() { return defaultModule.getName().getLocation().getFile(); }
private LexIdentifierToken consLexIdToken(ILexIdentifierToken defName, String newName) { return new LexIdentifierToken(newName, defName.getOld(), defName.getLocation()); }
public PStm findStatement(AModuleModules m, File file, int lineno) { if (m.getName().getLocation().getFile().equals(file)) { return af.createPDefinitionAssistant().findStatement(m.getDefs(), lineno); } return null; }
public PExp findExpression(AModuleModules m, File file, int lineno) { if (m.getName().getLocation().getFile().equals(file)) { return af.createPDefinitionListAssistant().findExpression(m.getDefs(), lineno); } return null; }
public LexNameToken getMemberName(AClassType cls, ILexIdentifierToken id) { // Note: not explicit return new LexNameToken(cls.getName().getName(), id.getName(), id.getLocation(), false, false); }
private void handleLexIdToken(INode parent, ILexIdentifierToken node) { Renaming r = findRenaming(node.getLocation()); if (r != null) { parent.replaceChild(node, consLexIdToken(node, r.getNewName())); } }
private AFromModuleImports importAll(ILexIdentifierToken from) { List<List<PImport>> types = new Vector<List<PImport>>(); ILexNameToken all = new LexNameToken(from.getName(), "all", from.getLocation()); List<PImport> impAll = new Vector<PImport>(); AAllImport iport = AstFactory.newAAllImport(all); iport.setLocation(all.getLocation()); iport.setName(all); iport.setRenamed(all); iport.setFrom(null); impAll.add(iport); types.add(impAll); return AstFactory.newAFromModuleImports(from, types); } }
public static ANewExp newANewExp(ILexLocation start, ILexIdentifierToken classname, List<PExp> args) { ANewExp result = new ANewExp(); initExpression(result, start); result.setClassName(classname); result.setArgs(args); classname.getLocation().executable(true); return result; }
public List<PDefinition> getDefinitions(AModuleImports imports, List<AModuleModules> allModules) { List<PDefinition> defs = new Vector<PDefinition>(); for (AFromModuleImports ifm : imports.getImports()) { if (ifm.getName().getName().equals(imports.getName())) { TypeCheckerErrors.report(3195, "Cannot import from self", ifm.getName().getLocation(), ifm); continue; } AModuleModules from = af.createAModuleModulesAssistant().findModule(allModules, ifm.getName()); if (from == null) { TypeCheckerErrors.report(3196, "No such module as " + ifm.getName(), ifm.getName().getLocation(), ifm); } else { defs.addAll(getDefinitions(ifm, from)); } } return defs; }
@Override public Context getInitialTraceContext(ANamedTraceDefinition tracedef, boolean debug) throws ValueException { Context mainContext = new StateContext(assistantFactory, defaultModule.getName().getLocation(), "module scope", initialContext, assistantFactory.createAModuleModulesAssistant().getStateContext(defaultModule)); mainContext.putAll(initialContext); mainContext.setThreadState(mainContext.threadState.dbgp, CPUValue.vCPU); return mainContext; }
public static PExp newAFieldExp(PExp object, ILexIdentifierToken field) { AFieldExp result = new AFieldExp(); result.setLocation(object.getLocation()); result.setObject(object); result.setField(field); result.getField().getLocation().executable(true); return result; }
public RootContext createInitialContext(ModuleList modules) { StateContext initialContext = null; if (modules.isEmpty()) { initialContext = new StateContext(af, new LexLocation(), "global environment"); } else { initialContext = new StateContext(af, modules.get(0).getName().getLocation(), "global environment"); } return initialContext; }
@Override public Value caseAFieldExp(AFieldExp node, Context ctxt) throws AnalysisException { BreakpointManager.getBreakpoint(node).check(node.getLocation(), ctxt); node.getField().getLocation().hit(); try { return ctxt.assistantFactory.createAFieldExpAssistant().evaluate(node, ctxt); } catch (ValueException e) { return VdmRuntimeError.abort(node.getLocation(), e); } }
public static AFieldExp newAFieldExp(PExp object, ILexNameToken field) { AFieldExp result = new AFieldExp(); result.setLocation(object.getLocation()); result.setObject(object); result.setField(new LexIdentifierToken(field.getName(), field.getOld(), field.getLocation())); result.setMemberName(field); result.getField().getLocation().executable(true); return result; }
/** * Parse the line passed, type check it and evaluate it as an expression in the initial module context (with default * module's state). * * @param line * A VDM expression. * @return The value of the expression. * @throws Exception * Parser, type checking or runtime errors. */ @Override public Value execute(String line, DBGPReader dbgp) throws Exception { PExp expr = parseExpression(line, getDefaultName()); Environment env = getGlobalEnvironment(); typeCheck(expr, env); Context mainContext = new StateContext(assistantFactory, defaultModule.getName().getLocation(), "module scope", null, assistantFactory.createAModuleModulesAssistant().getStateContext(defaultModule)); mainContext.putAll(initialContext); mainContext.setThreadState(dbgp, null); clearBreakpointHits(); // scheduler.reset(); InitThread iniThread = new InitThread(Thread.currentThread()); BasicSchedulableThread.setInitialThread(iniThread); MainThread main = new MainThread(expr, mainContext); main.start(); scheduler.start(main); return main.getResult(); // Can throw ContextException }
@Override public Value caseANewExp(ANewExp node, Context ctxt) throws AnalysisException { BreakpointManager.getBreakpoint(node).check(node.getLocation(), ctxt); node.getClassName().getLocation().hit(); try { ValueList argvals = new ValueList(); for (PExp arg : node.getArgs()) { argvals.add(arg.apply(VdmRuntime.getExpressionEvaluator(), ctxt)); } ObjectValue objval = ctxt.assistantFactory.createSClassDefinitionAssistant().newInstance(node.getClassdef(), node.getCtorDefinition(), argvals, ctxt); if (objval.invlistener != null) { // Check the initial values of the object's fields objval.invlistener.doInvariantChecks = true; objval.invlistener.changedValue(node.getLocation(), objval, ctxt); } return objval; } catch (ValueException e) { return VdmRuntimeError.abort(node.getLocation(), e); } }
result.add(AstFactory.newAUnknownType(field.getLocation())); } else + field + "'", field.getLocation(), field); result.add(AstFactory.newAUnknownType(node.getLocation())); + field.getName() + " of class " + cname, field.getLocation(), field); result.add(AstFactory.newAUnknownType(node.getLocation())); node.setType(AstFactory.newAUnknownType(field.getLocation())); return node.getType();
VdmRuntimeError.abort(node.getField().getLocation(), 4037, "No such field: " + node.getField(), ctxt);