Package org.aspectj.org.eclipse.jdt.internal.compiler.codegen

Examples of org.aspectj.org.eclipse.jdt.internal.compiler.codegen.CodeStream


    this.referenceBinding = typeBinding;
    if (this.targetJDK >= ClassFileConstants.JDK1_6) {
      this.produceAttributes |= ClassFileConstants.ATTR_STACK_MAP;
      this.codeStream = new StackMapFrameCodeStream(this);
    } else {
      this.codeStream = new CodeStream(this);
    }
    this.initByteArrays();
  }
View Full Code Here


    int constantPoolOffset = constantPool.currentOffset;
    int constantPoolIndex = constantPool.currentIndex;
    classFile.generateMethodInfoHeaderForClinit();
    int codeAttributeOffset = classFile.contentsOffset;
    classFile.generateCodeAttributeHeader();
    CodeStream codeStream = classFile.codeStream;
    this.resolve(classScope);

    codeStream.reset(this, classFile);
    TypeDeclaration declaringType = classScope.referenceContext;

    // initialize local positions - including initializer scope.
    MethodScope staticInitializerScope = declaringType.staticInitializerScope;
    staticInitializerScope.computeLocalVariablePositions(0, codeStream);

    // 1.4 feature
    // This has to be done before any other initialization
    // AspectJ Extension - move logic to helper method
    // was:
    //if (this.assertionSyntheticFieldBinding != null) {
    //  // generate code related to the activation of assertion for this class
    //  codeStream.generateClassLiteralAccessForType(
    //      classScope.outerMostClassScope().enclosingSourceType(),
    //      this.classLiteralSyntheticField);
    //  codeStream.invokeJavaLangClassDesiredAssertionStatus();
    //  BranchLabel falseLabel = new BranchLabel(codeStream);
    //  codeStream.ifne(falseLabel);
    //  codeStream.iconst_1();
    //  BranchLabel jumpLabel = new BranchLabel(codeStream);
    //  codeStream.decrStackSize(1);
    //  codeStream.goto_(jumpLabel);
    //  falseLabel.place();
    //  codeStream.iconst_0();
    //  jumpLabel.place();
    //  codeStream.putstatic(this.assertionSyntheticFieldBinding);
    //}
    generateSyntheticCode(classScope, codeStream);
    // End AspectJ Extension
   
    // generate static fields/initializers/enum constants
    final FieldDeclaration[] fieldDeclarations = declaringType.fields;
    BlockScope lastInitializerScope = null;
    if (TypeDeclaration.kind(declaringType.modifiers) == TypeDeclaration.ENUM_DECL) {
      int enumCount = 0;
      int remainingFieldCount = 0;
      if (fieldDeclarations != null) {
        for (int i = 0, max = fieldDeclarations.length; i < max; i++) {
          FieldDeclaration fieldDecl = fieldDeclarations[i];
          if (fieldDecl.isStatic()) {
            if (fieldDecl.getKind() == AbstractVariableDeclaration.ENUM_CONSTANT) {
              fieldDecl.generateCode(staticInitializerScope, codeStream);
              enumCount++;
            } else {
              remainingFieldCount++;
            }
          }
        }
      }
      // enum need to initialize $VALUES synthetic cache of enum constants
      // $VALUES := new <EnumType>[<enumCount>]
      codeStream.generateInlinedValue(enumCount);
      codeStream.anewarray(declaringType.binding);
      if (enumCount > 0) {
        if (fieldDeclarations != null) {
          for (int i = 0, max = fieldDeclarations.length; i < max; i++) {
            FieldDeclaration fieldDecl = fieldDeclarations[i];
            // $VALUES[i] = <enum-constant-i>
            if (fieldDecl.getKind() == AbstractVariableDeclaration.ENUM_CONSTANT) {
              codeStream.dup();
              codeStream.generateInlinedValue(fieldDecl.binding.id);
              codeStream.getstatic(fieldDecl.binding);
              codeStream.aastore();
            }
          }
        }
      }
      codeStream.putstatic(declaringType.enumValuesSyntheticfield);
      if (remainingFieldCount != 0) {
        // if fields that are not enum constants need to be generated (static initializer/static field)
        for (int i = 0, max = fieldDeclarations.length; i < max; i++) {
          FieldDeclaration fieldDecl = fieldDeclarations[i];
          switch (fieldDecl.getKind()) {
            case AbstractVariableDeclaration.ENUM_CONSTANT :
              break;
            case AbstractVariableDeclaration.INITIALIZER :
              if (!fieldDecl.isStatic())
                break;
              lastInitializerScope = ((Initializer) fieldDecl).block.scope;
              fieldDecl.generateCode(staticInitializerScope, codeStream);
              break;
            case AbstractVariableDeclaration.FIELD :
              if (!fieldDecl.binding.isStatic())
                break;
              lastInitializerScope = null;
              fieldDecl.generateCode(staticInitializerScope, codeStream);
              break;
          }
        }
      }
    } else {
      if (fieldDeclarations != null) {
        for (int i = 0, max = fieldDeclarations.length; i < max; i++) {
          FieldDeclaration fieldDecl = fieldDeclarations[i];
          switch (fieldDecl.getKind()) {
            case AbstractVariableDeclaration.INITIALIZER :
              if (!fieldDecl.isStatic())
                break;
              lastInitializerScope = ((Initializer) fieldDecl).block.scope;
              fieldDecl.generateCode(staticInitializerScope, codeStream);
              break;
            case AbstractVariableDeclaration.FIELD :
              if (!fieldDecl.binding.isStatic())
                break;
              lastInitializerScope = null;
              fieldDecl.generateCode(staticInitializerScope, codeStream);
              break;
          }
        }
      }
    }
   
    // AspectJ Extension
    generatePostSyntheticCode(classScope, codeStream);
    // End AspectJ Extension
   
    if (codeStream.position == 0) {
      // do not need to output a Clinit if no bytecodes
      // so we reset the offset inside the byte array contents.
      classFile.contentsOffset = clinitOffset;
      // like we don't addd a method we need to undo the increment on the method count
      classFile.methodCount--;
      // reset the constant pool to its state before the clinit
      constantPool.resetForClinit(constantPoolIndex, constantPoolOffset);
    } else {
      if ((this.bits & ASTNode.NeedFreeReturn) != 0) {
        int before = codeStream.position;
        codeStream.return_();
        if (lastInitializerScope != null) {
          // expand the last initializer variables to include the trailing return
          codeStream.updateLastRecordedEndPC(lastInitializerScope, before);
        }
      }
      // Record the end of the clinit: point to the declaration of the class
      codeStream.recordPositionsFrom(0, declaringType.sourceStart);
      classFile.completeCodeAttributeForClinit(codeAttributeOffset);
    }
  }
View Full Code Here

  this.creatingProblemType = creatingProblemType;
  if (this.targetJDK >= ClassFileConstants.JDK1_6) {
    this.codeStream = new StackMapFrameCodeStream(this);
    this.produceAttributes |= ClassFileConstants.ATTR_STACK_MAP;
  } else {
    this.codeStream = new CodeStream(this);
  }
  // retrieve the enclosing one guaranteed to be the one matching the propagated flow info
  // 1FF9ZBU: LFCOM:ALL - Local variable attributes busted (Sanity check)
  if (this.enclosingClassFile == null) {
    this.codeStream.maxFieldCount = aType.scope.referenceType().maxFieldCount;
View Full Code Here

    classFile.generateMethodInfoHeader(binding);
    int methodAttributeOffset = classFile.contentsOffset;
    int attributeNumber = classFile.generateMethodInfoAttribute(binding, false, AstUtil.getAjSyntheticAttribute());
    int codeAttributeOffset = classFile.contentsOffset;
    classFile.generateCodeAttributeHeader();
    CodeStream codeStream = classFile.codeStream;
    codeStream.reset(this, classFile);

    // push the closure
    int nargs = binding.parameters.length;
    int closureIndex = 0;
    for (int i = 0; i < nargs - 1; i++) {
      closureIndex += AstUtil.slotsNeeded(binding.parameters[i]);
    }

    codeStream.aload(closureIndex);

    // build the Object[]

    codeStream.generateInlinedValue(nargs - 1);
    codeStream.newArray(new ArrayBinding(classScope.getType(TypeConstants.JAVA_LANG_OBJECT,
        TypeConstants.JAVA_LANG_OBJECT.length), 1, classScope.environment()));

    int index = 0;
    for (int i = 0; i < nargs - 1; i++) {
      TypeBinding type = binding.parameters[i];
      codeStream.dup();
      codeStream.generateInlinedValue(i);
      codeStream.load(type, index);
      index += AstUtil.slotsNeeded(type);
      if (type.isBaseType()) {
        codeStream.invokestatic(AjTypeConstants.getConversionMethodToObject(classScope, type));
      }

      codeStream.aastore();
    }

    // call run
    ReferenceBinding closureType = (ReferenceBinding) binding.parameters[nargs - 1];
    MethodBinding runMethod = closureType.getMethods("run".toCharArray())[0];
    codeStream.invokevirtual(runMethod);

    TypeBinding returnType = binding.returnType;
    if (returnType.isBaseType()) {
      codeStream.invokestatic(AjTypeConstants.getConversionMethodFromObject(classScope, returnType));
    } else {
      codeStream.checkcast(returnType);
    }
    AstUtil.generateReturn(returnType, codeStream);
    codeStream.recordPositionsFrom(0, 1);
    classFile.completeCodeAttribute(codeAttributeOffset);
    attributeNumber++;
    classFile.completeMethodInfo(methodAttributeOffset, attributeNumber);
  }
View Full Code Here

    int methodAttributeOffset = classFile.contentsOffset;
    int attributeNumber = classFile.generateMethodInfoAttribute(binding, false, makeEffectiveSignatureAttribute(sig,
        isGetter ? Shadow.FieldGet : Shadow.FieldSet, false));
    int codeAttributeOffset = classFile.contentsOffset;
    classFile.generateCodeAttributeHeader();
    CodeStream codeStream = classFile.codeStream;
    codeStream.reset(this, classFile);

    NewFieldTypeMunger fieldMunger = (NewFieldTypeMunger) munger;

        // Force use of version 1 if there is a field with that name on the type already
    if (world.getItdVersion() == 1) {
      fieldMunger.version = NewFieldTypeMunger.VersionOne;
    } else {
      if (!onTypeBinding.isInterface()) {
        FieldBinding[] existingFields = onTypeBinding.fields();
        for (int f = 0; f < existingFields.length; f++) {
          FieldBinding fieldBinding = existingFields[f];
          if (CharOperation.equals(fieldBinding.name, sig.getName().toCharArray())) {
            fieldMunger.version = NewFieldTypeMunger.VersionOne;
          }
        }
      }
    }

    FieldBinding classField = world.makeFieldBinding(AjcMemberMaker.interFieldClassField(sig, aspectType,
        fieldMunger.version == NewFieldTypeMunger.VersionTwo), munger.getTypeVariableAliases());

    codeStream.initializeMaxLocals(binding);
    if (isGetter) {
      if (onTypeBinding.isInterface()) {
        UnresolvedType declaringTX = sig.getDeclaringType();
        ResolvedType declaringRTX = world.getWorld().resolve(declaringTX, munger.getSourceLocation());
        MethodBinding readMethod = world.makeMethodBinding(AjcMemberMaker.interFieldInterfaceGetter(sig, declaringRTX,
View Full Code Here

      attributeNumber = classFile.generateMethodInfoAttribute(methodBinding, false, AstUtil.getAjSyntheticAttribute());
    }

    int codeAttributeOffset = classFile.contentsOffset;
    classFile.generateCodeAttributeHeader();
    CodeStream codeStream = classFile.codeStream;

    // Use reset() rather than init()
    // XXX We need a scope to keep reset happy, initializerScope is *not* the right one, but it works !
    // codeStream.init(classFile);
    // codeStream.initializeMaxLocals(methodBinding);
    MethodDeclaration md = AstUtil.makeMethodDeclaration(methodBinding);
    md.scope = initializerScope;
    codeStream.reset(md, classFile);
    // body starts here
    gen.generate(codeStream);
    // body ends here
    if (codeStream.pcToSourceMapSize == 0) {
      codeStream.recordPositionsFrom(0, 1);
    }
    boolean b = ((codeStream.generateAttributes & ClassFileConstants.ATTR_VARS) != 0 ? true : false); // pr148693
    if (codeStream.maxLocals == 0) {
      codeStream.generateAttributes &= ~ClassFileConstants.ATTR_VARS;
    }
View Full Code Here

    // damage the attributes generated for the dispatch binding.
    int attributeNumber = classFile.generateMethodInfoAttribute(binding, false, makeEffectiveSignatureAttribute(signature,
        Shadow.MethodCall, false));
    int codeAttributeOffset = classFile.contentsOffset;
    classFile.generateCodeAttributeHeader();
    CodeStream codeStream = classFile.codeStream;
    codeStream.reset(this, classFile);
    codeStream.initializeMaxLocals(dispatchBinding);

    Argument[] itdArgs = this.arguments;
    if (itdArgs != null) {
      for (int a = 0; a < itdArgs.length; a++) {
        LocalVariableBinding lvb = itdArgs[a].binding;
        LocalVariableBinding lvbCopy = new LocalVariableBinding(lvb.name, lvb.type, lvb.modifiers, true);
        codeStream.record(lvbCopy);
        lvbCopy.recordInitializationStartPC(0);
        lvbCopy.resolvedPosition = lvb.resolvedPosition;
      }
    }

    MethodBinding methodBinding = introducedMethod;
    TypeBinding[] parameters = methodBinding.parameters;
    int length = parameters.length;
    int resolvedPosition;
    if (methodBinding.isStatic())
      resolvedPosition = 0;
    else {
      codeStream.aload_0();
      resolvedPosition = 1;
    }
    for (int i = 0; i < length; i++) {
      codeStream.load(parameters[i], resolvedPosition);
      if ((parameters[i] == TypeBinding.DOUBLE) || (parameters[i] == TypeBinding.LONG))
        resolvedPosition += 2;
      else
        resolvedPosition++;
    }
    // TypeBinding type;
    if (methodBinding.isStatic())
      codeStream.invokestatic(methodBinding);
    else {
      if (methodBinding.declaringClass.isInterface()) {
        codeStream.invokeinterface(methodBinding);
      } else {
        codeStream.invokevirtual(methodBinding);
      }
    }
    AstUtil.generateReturn(dispatchBinding.returnType, codeStream);

    // tag the local variables as used throughout the method
View Full Code Here

    int attributeNumber = classFile.generateMethodInfoAttribute(binding,
        false,
        makeEffectiveSignatureAttribute(signature, Shadow.MethodCall, false));
    int codeAttributeOffset = classFile.contentsOffset;
    classFile.generateCodeAttributeHeader();
    CodeStream codeStream = classFile.codeStream;
    codeStream.reset(this, classFile);
   
    codeStream.initializeMaxLocals(dispatchBinding);
   
    MethodBinding methodBinding = introducedMethod;
    TypeBinding[] parameters = methodBinding.parameters;
    int length = parameters.length;
    int resolvedPosition;
    if (methodBinding.isStatic())
      resolvedPosition = 0;
    else {
      codeStream.aload_0();
      resolvedPosition = 1;
    }
    for (int i = 0; i < length; i++) {
      codeStream.load(parameters[i], resolvedPosition);
      if ((parameters[i] == DoubleBinding) || (parameters[i] == LongBinding))
        resolvedPosition += 2;
      else
        resolvedPosition++;
    }
//    TypeBinding type;
    if (methodBinding.isStatic())
      codeStream.invokestatic(methodBinding);
    else {
      if (methodBinding.declaringClass.isInterface()){
        codeStream.invokeinterface(methodBinding);
      } else {
        codeStream.invokevirtual(methodBinding);
      }
    }
    AstUtil.generateReturn(dispatchBinding.returnType, codeStream);

    classFile.completeCodeAttribute(codeAttributeOffset);
View Full Code Here

    int methodAttributeOffset = classFile.contentsOffset;
    int attributeNumber = classFile.generateMethodInfoAttribute(binding, false,
        makeEffectiveSignatureAttribute(sig, isGetter ? Shadow.FieldGet : Shadow.FieldSet, false));
    int codeAttributeOffset = classFile.contentsOffset;
    classFile.generateCodeAttributeHeader();
    CodeStream codeStream = classFile.codeStream;
    codeStream.reset(this, classFile);
   
    FieldBinding classField = world.makeFieldBinding(
      AjcMemberMaker.interFieldClassField(sig, aspectType),munger.getTypeVariableAliases());
   
    codeStream.initializeMaxLocals(binding);
    if (isGetter) {
      if (onTypeBinding.isInterface()) {
                UnresolvedType declaringTX = sig.getDeclaringType();
                ResolvedType declaringRTX = world.getWorld().resolve(declaringTX,munger.getSourceLocation());
        MethodBinding readMethod = world.makeMethodBinding(
View Full Code Here

      attributeNumber = classFile.generateMethodInfoAttribute(methodBinding, false, AstUtil.getAjSyntheticAttribute());
    }

    int codeAttributeOffset = classFile.contentsOffset;
    classFile.generateCodeAttributeHeader();
    CodeStream codeStream = classFile.codeStream;
   
    // Use reset() rather than init()
    // XXX We need a scope to keep reset happy, initializerScope is *not* the right one, but it works !
//     codeStream.init(classFile);
//     codeStream.initializeMaxLocals(methodBinding);
    MethodDeclaration md = AstUtil.makeMethodDeclaration(methodBinding);
    md.scope = initializerScope;
    codeStream.reset(md,classFile);
   
    // body starts here
    gen.generate(codeStream);
    // body ends here
    classFile.completeCodeAttribute(codeAttributeOffset);
View Full Code Here

TOP

Related Classes of org.aspectj.org.eclipse.jdt.internal.compiler.codegen.CodeStream

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.