Esempio n. 1
0
        public override AnnotationVisitor VisitTypeAnnotation(int typeRef, TypePath typePath
                                                              , string descriptor, bool visible)
        {
            CheckVisitEndNotCalled();
            var sort = new TypeReference(typeRef).GetSort();

            if (sort != TypeReference.Field)
            {
                throw new ArgumentException("Invalid type reference sort 0x" + sort.ToString("x8"));
            }
            CheckClassAdapter.CheckTypeRef(typeRef);
            CheckMethodAdapter.CheckDescriptor(OpcodesConstants.V1_5, descriptor, false);
            return(new CheckAnnotationAdapter(base.VisitTypeAnnotation(typeRef, typePath, descriptor
                                                                       , visible)));
        }
Esempio n. 2
0
 public override void VisitExport(string packaze, AccessFlags access, params string[] modules
                                  )
 {
     CheckVisitEndNotCalled();
     CheckMethodAdapter.CheckInternalName(OpcodesConstants.V9, packaze, "package name"
                                          );
     exportedPackages.CheckNameNotAlreadyDeclared(packaze);
     CheckClassAdapter.CheckAccess(access, AccessFlags.Synthetic | AccessFlags
                                   .Mandated);
     if (modules != null)
     {
         foreach (var module in modules)
         {
             CheckClassAdapter.CheckFullyQualifiedName(OpcodesConstants.V9, module, "module export to"
                                                       );
         }
     }
     base.VisitExport(packaze, access, modules);
 }
Esempio n. 3
0
 public override void VisitOpen(string packaze, AccessFlags access, params string[] modules
                                )
 {
     CheckVisitEndNotCalled();
     if (isOpen)
     {
         throw new NotSupportedException("An open module can not use open directive");
     }
     CheckMethodAdapter.CheckInternalName(OpcodesConstants.V9, packaze, "package name"
                                          );
     openedPackages.CheckNameNotAlreadyDeclared(packaze);
     CheckClassAdapter.CheckAccess(access, AccessFlags.Synthetic | AccessFlags
                                   .Mandated);
     if (modules != null)
     {
         foreach (var module in modules)
         {
             CheckClassAdapter.CheckFullyQualifiedName(OpcodesConstants.V9, module, "module open to"
                                                       );
         }
     }
     base.VisitOpen(packaze, access, modules);
 }
Esempio n. 4
0
 public override void VisitRequire(string module, AccessFlags access, string version)
 {
     CheckVisitEndNotCalled();
     CheckClassAdapter.CheckFullyQualifiedName(OpcodesConstants.V9, module, "required module"
                                               );
     requiredModules.CheckNameNotAlreadyDeclared(module);
     CheckClassAdapter.CheckAccess(access, AccessFlags.StaticPhase | AccessFlags
                                   .Transitive | AccessFlags.Synthetic |
                                   AccessFlags.Mandated
                                   );
     if (classVersion >= OpcodesConstants.V10 && module.Equals("java.base") && (access
                                                                                & (AccessFlags
                                                                                   .StaticPhase |
                                                                                   AccessFlags
                                                                                   .Transitive)) != 0)
     {
         throw new ArgumentException(
                   "Invalid access flags: " + access +
                   " java.base can not be declared ACC_TRANSITIVE or ACC_STATIC_PHASE"
                   );
     }
     base.VisitRequire(module, access, version);
 }
Esempio n. 5
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: private Class<IExecutable> compile(CompilerContext context) throws ClassFormatError
        private Type <IExecutable> compile(CompilerContext context)
        {
            Type <IExecutable> compiledClass = null;

            context.CodeBlock = this;
            string className = InternalClassName;

            //if (log.DebugEnabled)
            {
                string functionName = Utilities.getFunctionNameByAddress(StartAddress);

                if (!string.ReferenceEquals(functionName, null))
                {
                    Console.WriteLine(string.Format("Compiling {0} ({1})", className, functionName));
                }
                else
                {
                    Console.WriteLine(string.Format("Compiling {0}", className));
                }
            }

            prepare(context, context.MethodMaxInstructions);

            currentSequence = null;
            int computeFlag = ClassWriter.COMPUTE_FRAMES;

            if (context.AutomaticMaxLocals || context.AutomaticMaxStack)
            {
                computeFlag |= ClassWriter.COMPUTE_MAXS;
            }
            ClassWriter  cw = new ClassWriter(computeFlag);
            ClassVisitor cv = cw;
            //if (log.DebugEnabled)
            {
                cv = new CheckClassAdapter(cv);
            }
            StringWriter debugOutput = null;

            if (log.TraceEnabled)
            {
                debugOutput = new StringWriter();
                PrintWriter debugPrintWriter = new PrintWriter(debugOutput);
                cv = new TraceClassVisitor(cv, debugPrintWriter);
            }
            cv.visit(Opcodes.V1_6, Opcodes.ACC_PUBLIC | Opcodes.ACC_SUPER, className, null, objectInternalName, interfacesForExecutable);
            context.startClass(cv);

            addConstructor(cv);
            addNonStaticMethods(context, cv);

            MethodVisitor mv = cv.visitMethod(Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC, context.StaticExecMethodName, context.StaticExecMethodDesc, null, exceptions);

            mv.visitCode();
            context.MethodVisitor = mv;
            context.startMethod();

            // Jump to the block start if other instructions have been inserted in front
            if (codeInstructions.Count > 0 && codeInstructions.First.Value.Address != StartAddress)
            {
                mv.visitJumpInsn(Opcodes.GOTO, getCodeInstruction(StartAddress).Label);
            }

            compile(context, mv, codeInstructions);
            mv.visitMaxs(context.MaxStack, context.MaxLocals);
            mv.visitEnd();

            foreach (SequenceCodeInstruction sequenceCodeInstruction in sequenceCodeInstructions)
            {
                //if (log.DebugEnabled)
                {
                    Console.WriteLine("Compiling Sequence " + sequenceCodeInstruction.getMethodName(context));
                }
                currentSequence = sequenceCodeInstruction;
                mv = cv.visitMethod(Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC, sequenceCodeInstruction.getMethodName(context), "()V", null, exceptions);
                mv.visitCode();
                context.MethodVisitor = mv;
                context.startSequenceMethod();

                compile(context, mv, sequenceCodeInstruction.CodeSequence.Instructions);

                context.endSequenceMethod();
                mv.visitMaxs(context.MaxStack, context.MaxLocals);
                mv.visitEnd();
            }
            currentSequence = null;

            cv.visitEnd();

            if (debugOutput != null)
            {
                log.trace(debugOutput.ToString());
            }

            try
            {
                compiledClass = loadExecutable(context, className, cw.toByteArray());
            }
            catch (System.NullReferenceException e)
            {
                Console.WriteLine("Error while compiling " + className + ": " + e);
            }

            return(compiledClass);
        }
Esempio n. 6
0
        private Type <IExecutable> interpret(CompilerContext context)
        {
            Type <IExecutable> compiledClass = null;

            context.CodeBlock = this;
            string className = InternalClassName;

            if (log.InfoEnabled)
            {
                Console.WriteLine("Compiling for Interpreter " + className);
            }

            int computeFlag = ClassWriter.COMPUTE_FRAMES;

            if (context.AutomaticMaxLocals || context.AutomaticMaxStack)
            {
                computeFlag |= ClassWriter.COMPUTE_MAXS;
            }
            ClassWriter  cw = new ClassWriter(computeFlag);
            ClassVisitor cv = cw;
            //if (log.DebugEnabled)
            {
                cv = new CheckClassAdapter(cv);
            }

            StringWriter debugOutput = null;

            //if (log.DebugEnabled)
            {
                debugOutput = new StringWriter();
                PrintWriter debugPrintWriter = new PrintWriter(debugOutput);
                cv = new TraceClassVisitor(cv, debugPrintWriter);
            }
            cv.visit(Opcodes.V1_6, Opcodes.ACC_PUBLIC | Opcodes.ACC_SUPER, className, null, objectInternalName, interfacesForExecutable);
            context.startClass(cv);

            addConstructor(cv);
            addNonStaticMethods(context, cv);

            MethodVisitor mv = cv.visitMethod(Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC, context.StaticExecMethodName, context.StaticExecMethodDesc, null, exceptions);

            mv.visitCode();
            context.MethodVisitor = mv;
            context.startMethod();

            context.compileExecuteInterpreter(StartAddress);

            mv.visitMaxs(context.MaxStack, context.MaxLocals);
            mv.visitEnd();

            cv.visitEnd();

            if (debugOutput != null)
            {
                Console.WriteLine(debugOutput.ToString());
            }

            compiledClass = loadExecutable(context, className, cw.toByteArray());

            return(compiledClass);
        }