@Override public int check(final int locals) throws ContextError, HeapTooSmallError { if (locals >= 0) { throw new ContextError("Function declarations are only allowed globally!", ident.getLine()); } Routine routine = IMLCompiler.getRoutineTable().getRoutine(ident.getIdent().toString()); IMLCompiler.setScope(routine.getScope()); Store retStore = returnDecl.check(); retStore.setAddress(-routine.getParamList().size() - 1); retStore.setReference(false); retStore.setRelative(true); globImp.check(routine); int localsCount = param.calculateAddress(routine.getParamList().size(), 0); cpsDecl.check(localsCount); cmd.check(false); if (!routine.getScope().getStoreTable().getStore(returnDecl.getIdent()).isInitialized()) { throw new ContextError( "Return value never initialized! Function: " + ident.getIdent(), ident.getLine()); } IMLCompiler.setScope(null); return -1; }
@Override public void checkDeclaration() throws ContextError { Function function = new Function(ident.getIdent().toString(), returnDecl.getType()); IMLCompiler.setScope(function.getScope()); if (!IMLCompiler.getRoutineTable().addRoutine(function)) { throw new ContextError("Routine already declared: " + ident.getIdent(), ident.getLine()); } param.check(function); IMLCompiler.setScope(null); }
@Override public int getLine() { return ident.getLine(); }