Пример #1
0
        /// <summary>
        /// Check the bytecode from one round of bytecode generation.
        /// </summary>
        /// <param name="classpathLoader">
        ///         the ClassLoader to use for loading classes from the classpath. </param>
        /// <param name="byteCodes">
        ///         the bytecodes generated in this round. </param>
        /// <exception cref="CompilationFailureException">
        ///         if any issue is discovered in the verification. </exception>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public void check(ClassLoader classpathLoader, java.util.Collection<org.neo4j.codegen.ByteCodes> byteCodes) throws org.neo4j.codegen.CompilationFailureException
        public override void Check(ClassLoader classpathLoader, ICollection <ByteCodes> byteCodes)
        {
            IList <ClassNode> classes  = new List <ClassNode>(byteCodes.Count);
            IList <Failure>   failures = new List <Failure>();

            // load (and verify) the structure of the generated classes
            foreach (ByteCodes byteCode in byteCodes)
            {
                try
                {
                    classes.Add(ClassNode(byteCode.Bytes()));
                }
                catch (Exception e)
                {
                    failures.Add(new Failure(e, e.ToString()));
                }
            }
            // if there are problems with the structure of the generated classes,
            // we are not going to be able to verify their methods
            if (failures.Count > 0)
            {
                throw CompilationFailure(failures);
            }
            // continue with verifying the methods of the classes
            AssignmentChecker check = new AssignmentChecker(classpathLoader, classes);

            foreach (ClassNode clazz in classes)
            {
                Verify(check, clazz, failures);
            }
            if (failures.Count > 0)
            {
                throw CompilationFailure(failures);
            }
        }
Пример #2
0
        /// <summary>
        /// Verify the methods of a single class.
        /// </summary>
        /// <param name="check">
        ///         a helper for verifying assignments. </param>
        /// <param name="clazz">
        ///         the class to check the methods of. </param>
        /// <param name="failures">
        ///         where any detected errors are added. </param>
        private static void Verify(AssignmentChecker check, ClassNode clazz, IList <Failure> failures)
        {
            Verifier verifier = new Verifier(clazz, check);

            foreach (MethodNode method in clazz.methods)
            {
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: org.objectweb.asm.tree.analysis.Analyzer<?> analyzer = new org.objectweb.asm.tree.analysis.Analyzer<>(verifier);
                Analyzer <object> analyzer = new Analyzer <object>(verifier);
                try
                {
                    analyzer.analyze(clazz.name, method);
                }
                catch (Exception cause)
                {
                    failures.Add(new Failure(cause, DetailedMessage(cause.Message, method, analyzer.Frames, cause is AnalyzerException ? (( AnalyzerException )cause).node : null)));
                }
            }
        }
Пример #3
0
 /// <summary>
 /// Add an assignment checker for this decorator.
 /// </summary>
 /// <param name="checker"> Checker to test whether items should be decorated. </param>
 /// <returns> Builder. </returns>
 public virtual Builder addAssignmentChecker(AssignmentChecker checker)
 {
     assignments.Add(checker);
     return(this);
 }
Пример #4
0
        public CompilerResults compileFromCompilationUnits(CompilerParameters parameters, CompilationUnitNode[] compilationUnits) {
            var results = new CompilerResults();
            this.context = new CompilerContext(parameters, results);
            this.statementValidator = new StatementValidator(this.context);
            this.expressionValidator = new ExpressionValidator(this.context);
            this.statementValidator.ExpressionValidator = this.expressionValidator;
            this.expressionValidator.StatementValidator = this.statementValidator;
            this.reachabilityChecker = new ReachabilityChecker(context);
            this.assignmentChecker = new AssignmentChecker(context);
            this.bytecodeGenerator = new BytecodeGenerator(context);
            
			foreach (var cu in compilationUnits) {
				context.CompilationUnits.add(cu);
			}
			doCompile();
            
            this.context = null;
            this.statementValidator = null;
            this.expressionValidator = null;
            this.reachabilityChecker = null;
            this.assignmentChecker = null;
            this.queryTranslator = null;
            this.documentationBuilder = null;
			
			if (parameters.ProgressTracker != null) {
				parameters.ProgressTracker.compilationFinished();
			}
            return results;
        }
Пример #5
0
        public CompilerResults compileFromFiles(CompilerParameters parameters, File[] files) {
            var results = new CompilerResults();
            this.context = new CompilerContext(parameters, results);
            this.statementValidator = new StatementValidator(this.context);
            this.expressionValidator = new ExpressionValidator(this.context);
            this.statementValidator.ExpressionValidator = this.expressionValidator;
            this.expressionValidator.StatementValidator = this.statementValidator;
            this.reachabilityChecker = new ReachabilityChecker(context);
            this.assignmentChecker = new AssignmentChecker(context);
            this.bytecodeGenerator = new BytecodeGenerator(context);
            bool tragicError = false;
			
            var buffer = new char[4096];
            var sb = new StringBuilder();
            var parser = new Parser();
            
            foreach (var file in files) {
                sb.setLength(0);
                InputStreamReader reader = null;
                try {
                    reader = new InputStreamReader(new FileInputStream(file), Charset.forName("UTF-8"));
                    int read;
                    while ((read = reader.read(buffer)) != -1) {
                        sb.append(buffer, 0, read);
                    }
                    
                    var text = new char[sb.length()];
                    sb.getChars(0, sizeof(text), text, 0);
                    if (sizeof(text) > 0) {
                        if (text[sizeof(text) - 1] == '\u001a') {
                            text[sizeof(text) - 1] = ' ';
                        }
                    }
                    var preprocessor = new Preprocessor(results.codeErrorManager, text);
                    preprocessor.Filename = file.getAbsolutePath();
					preprocessor.Symbols.addAll(parameters.Symbols);
                    
                    var scanner = new PreprocessedTextScanner(results.codeErrorManager, preprocessor.preprocess());
                    scanner.Filename = file.getAbsolutePath();
                    var compilationUnit = parser.parseCompilationUnit(scanner);
                    
                    if (compilationUnit != null) {
                        compilationUnit.Symbols = preprocessor.Symbols;
                        context.CompilationUnits.add(compilationUnit);
                    }
                } catch (CodeErrorException) {
				} catch (Exception e) {
					e.printStackTrace();
					tragicError = true;
					break;
                } finally {
                    if (reader != null) {
                        try {
                            reader.close();
                        } catch (IOException) {
                        }
                    }
                }
            }
            if (!tragicError) {
				if (!context.HasErrors) {
					if (parameters.ProgressTracker != null) {
						parameters.ProgressTracker.compilationStageFinished(CompilationStage.Parsing);
					}
					doCompile();
				}
			}
            this.context = null;
            this.statementValidator = null;
            this.expressionValidator = null;
            this.reachabilityChecker = null;
            this.assignmentChecker = null;
            this.queryTranslator = null;
            this.documentationBuilder = null;
			
			if (parameters.ProgressTracker != null) {
				parameters.ProgressTracker.compilationFinished();
			}
            return results;
        }
Пример #6
0
 internal Verifier(ClassNode clazz, AssignmentChecker check) : base(ASM6, Type.getObjectType(clazz.name), SuperClass(clazz), Interfaces(clazz), IsInterfaceNode(clazz))
 {
     this.Check = check;
 }