⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 usecompiler.java

📁 UML设计测试工具
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
            err.println(parser.getFilename() +":" +                         e.getLine() + ":" +                        e.getColumn() + ": " +                         e.getMessage());        } catch (SemanticException ex) {            err.println(ex.getMessage());        } catch (antlr.TokenStreamRecognitionException e) {            err.println(parser.getFilename() +":" +                         e.recog.getLine() + ":" + e.recog.getColumn() + ": " +                         e.recog.getMessage());        } catch (antlr.TokenStreamException ex) {            err.println(ex.getMessage());        }        err.flush();        return cmdList;    }    /**     * Compiles and adds invariants     *     * @param  model the model the invaraints are added to     * @param  in the source to be compiled     * @param  inName name of the source stream     * @param  err output stream for error messages     * @return Collection the added invariants (MClassInvariant)     */    public static Collection compileAndAddInvariants(MModel model,                                                     Reader in,                                                     String inName,                                                     PrintWriter err) {        ParseErrorHandler errHandler = new ParseErrorHandler(inName, err);        Collection addedInvs = null;        try {            GGeneratorLexer lexer = new GGeneratorLexer(in);            GGeneratorParser parser = new GGeneratorParser(lexer);            lexer.init(errHandler);            parser.init(errHandler);            // Parse the specification            //Log.verbose("Parsing...");            List consDefList = parser.invariantListOnly();            if (errHandler.errorCount() == 0 ) {                Context ctx = new Context(inName,                                          err,                                          null,                                          new ModelFactory());                Collection existingInvs = model.classInvariants();                ctx.setModel(model);                Iterator it = consDefList.iterator();                while (it.hasNext())                    // adds the class invariants to the given model                    ((ASTConstraintDefinition) it.next()).gen(ctx);                addedInvs = new ArrayList(model.classInvariants());                addedInvs.removeAll(existingInvs);            }        } catch (antlr.RecognitionException e) {            errHandler.reportError(e.getLine() + ":" + e.getColumn() + ": " +e.getMessage());        } catch (antlr.TokenStreamRecognitionException e) {            errHandler.reportError(e.recog.getLine() + ":" + e.recog.getColumn()                     + ": " + e.recog.getMessage());        } catch (antlr.TokenStreamException ex) {            errHandler.reportError(ex.getMessage());        }        err.flush();        return addedInvs;    }    /**     * Compiles generator procedures     *     * @param  model the model, which is the context of the procedure     * @param  in the source to be compiled     * @param  inName name of the source stream     * @param  err output stream for error messages     * @return List the comiled procedures (GProcedure)     */    public static List compileProcedures(MModel model,                                         Reader in,                                         String inName,                                         PrintWriter err) {        List astgProcList = new ArrayList();        List procedures = new ArrayList();  // GProcedure        ParseErrorHandler errHandler = new ParseErrorHandler(inName, err);        GGeneratorLexer lexer = new GGeneratorLexer(in);        GGeneratorParser parser = new GGeneratorParser(lexer);        lexer.init(errHandler);        parser.init(errHandler);        boolean error = false;        try {            astgProcList = parser.procedureListOnly();            if (errHandler.errorCount() != 0 )                error = true;            else {                Iterator astgproc = astgProcList.iterator();                while (astgproc.hasNext() && !error ) {                    Context ctx = new Context(inName, err, null, null);                    ctx.setModel(model);                    ASTGProcedure astgProc = (ASTGProcedure) astgproc.next();                    try {                        GProcedure proc = astgProc.gen(ctx);                        if (ctx.errorCount() != 0 )                            error = true;                        else {                            boolean ignore = false;                            Iterator it = procedures.iterator();                            while (it.hasNext())                                if (((GProcedure) it.next()).signature().equals(proc.signature() ) ) {                                    err.println("Warning: Ignoring redefinition of " + proc);                                    ignore = true;                                }                            if (!ignore)                                procedures.add( proc );                        }                    } catch (SemanticException ex) {                        ctx.reportError(ex);                        error = true;                    }                }            }        } catch (antlr.RecognitionException e) {            error = true;            err.println(parser.getFilename() +":" +                         e.getLine() + ":" + e.getColumn() + ": " +                         e.getMessage());        } catch (antlr.TokenStreamRecognitionException e) {            error = true;            err.println(parser.getFilename() +":" +                         e.recog.getLine() + ":" + e.recog.getColumn() + ": " +                         e.recog.getMessage());        } catch (antlr.TokenStreamException ex) {            error = true;            err.println(parser.getFilename() +":" + ex.getMessage());        }        err.flush();        if (error)            return null;        else            return procedures;    }    /**     * Compiles a procedure call     *     * @param  model the model of the call     * @param  systemState the context of the call     * @param  in the input source stream     * @param  inName the name of the input source stream     * @param  err output stream for error messages     * @return GProcedureCall the compiled call or null     */    public static GProcedureCall compileProcedureCall(MModel model,                                                      MSystemState systemState,                                                      Reader in,                                                       String inName,                                                      PrintWriter err) {        GProcedureCall procCall = null;        ParseErrorHandler errHandler = new ParseErrorHandler(inName, err);        try {            GGeneratorLexer lexer = new GGeneratorLexer(in);            GGeneratorParser parser = new GGeneratorParser(lexer);            parser.init(errHandler);            lexer.init(errHandler);            // Parse the command            ASTGProcedureCall astgProcCall = parser.procedureCallOnly();            if (errHandler.errorCount() == 0 ) {                Context ctx=new Context(inName,                                        err,                                        systemState.system().topLevelBindings(),                                        null);                ctx.setModel(model);                ctx.setSystemState(systemState);                procCall = astgProcCall.gen(ctx);                // check for semantic errors                if (ctx.errorCount() > 0 )                    procCall = null;            }        } catch (antlr.RecognitionException e) {            errHandler.reportError(e.getLine() + ":" + e.getColumn() + ": " +e.getMessage());        } catch (antlr.TokenStreamRecognitionException e) {            errHandler.reportError(e.recog.getLine() + ":" + e.recog.getColumn()                     + ": " + e.recog.getMessage());        } catch (antlr.TokenStreamException ex) {            errHandler.reportError(ex.getMessage());        } catch (SemanticException e) {            errHandler.reportError(e.getMessage());      }        err.flush();        return procCall;    }   }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -