Esempio n. 1
0
/// DeclaratorChunk::getFunction - Return a DeclaratorChunk for a function.
/// "TheDeclarator" is the declarator that this will be added to.
DeclaratorChunk DeclaratorChunk::getFunction(const ParsedAttributes &attrs,
                                             bool hasProto, bool isVariadic,
                                             SourceLocation EllipsisLoc,
                                             ParamInfo *ArgInfo,
                                             unsigned NumArgs,
                                             unsigned TypeQuals,
                                             bool RefQualifierIsLvalueRef,
                                             SourceLocation RefQualifierLoc,
                                             bool hasExceptionSpec,
                                             SourceLocation ThrowLoc,
                                             bool hasAnyExceptionSpec,
                                             ParsedType *Exceptions,
                                             SourceRange *ExceptionRanges,
                                             unsigned NumExceptions,
                                             SourceLocation LPLoc,
                                             SourceLocation RPLoc,
                                             Declarator &TheDeclarator,
                                             ParsedType TrailingReturnType) {
  DeclaratorChunk I;
  I.Kind                 = Function;
  I.Loc                  = LPLoc;
  I.EndLoc               = RPLoc;
  I.Fun.AttrList         = attrs.getList();
  I.Fun.hasPrototype     = hasProto;
  I.Fun.isVariadic       = isVariadic;
  I.Fun.EllipsisLoc      = EllipsisLoc.getRawEncoding();
  I.Fun.DeleteArgInfo    = false;
  I.Fun.TypeQuals        = TypeQuals;
  I.Fun.NumArgs          = NumArgs;
  I.Fun.ArgInfo          = 0;
  I.Fun.RefQualifierIsLValueRef = RefQualifierIsLvalueRef;
  I.Fun.RefQualifierLoc = RefQualifierLoc.getRawEncoding();
  I.Fun.hasExceptionSpec = hasExceptionSpec;
  I.Fun.ThrowLoc         = ThrowLoc.getRawEncoding();
  I.Fun.hasAnyExceptionSpec = hasAnyExceptionSpec;
  I.Fun.NumExceptions    = NumExceptions;
  I.Fun.Exceptions       = 0;
  I.Fun.TrailingReturnType   = TrailingReturnType.getAsOpaquePtr();

  // new[] an argument array if needed.
  if (NumArgs) {
    // If the 'InlineParams' in Declarator is unused and big enough, put our
    // parameter list there (in an effort to avoid new/delete traffic).  If it
    // is already used (consider a function returning a function pointer) or too
    // small (function taking too many arguments), go to the heap.
    if (!TheDeclarator.InlineParamsUsed &&
        NumArgs <= llvm::array_lengthof(TheDeclarator.InlineParams)) {
      I.Fun.ArgInfo = TheDeclarator.InlineParams;
      I.Fun.DeleteArgInfo = false;
      TheDeclarator.InlineParamsUsed = true;
    } else {
      I.Fun.ArgInfo = new DeclaratorChunk::ParamInfo[NumArgs];
      I.Fun.DeleteArgInfo = true;
    }
    memcpy(I.Fun.ArgInfo, ArgInfo, sizeof(ArgInfo[0])*NumArgs);
  }
  // new[] an exception array if needed
  if (NumExceptions) {
    I.Fun.Exceptions = new DeclaratorChunk::TypeAndRange[NumExceptions];
    for (unsigned i = 0; i != NumExceptions; ++i) {
      I.Fun.Exceptions[i].Ty = Exceptions[i];
      I.Fun.Exceptions[i].Range = ExceptionRanges[i];
    }
  }
  return I;
}
Esempio n. 2
0
/// DeclaratorChunk::getFunction - Return a DeclaratorChunk for a function.
/// "TheDeclarator" is the declarator that this will be added to.
DeclaratorChunk DeclaratorChunk::getFunction(bool hasProto, bool isVariadic,
        SourceLocation EllipsisLoc,
        ParamInfo *ArgInfo,
        unsigned NumArgs,
        unsigned TypeQuals,
        bool RefQualifierIsLvalueRef,
        SourceLocation RefQualifierLoc,
        SourceLocation ConstQualifierLoc,
        SourceLocation
        VolatileQualifierLoc,
        SourceLocation MutableLoc,
        ExceptionSpecificationType
        ESpecType,
        SourceLocation ESpecLoc,
        ParsedType *Exceptions,
        SourceRange *ExceptionRanges,
        unsigned NumExceptions,
        Expr *NoexceptExpr,
        SourceLocation LocalRangeBegin,
        SourceLocation LocalRangeEnd,
        Declarator &TheDeclarator,
        ParsedType TrailingReturnType) {
    DeclaratorChunk I;
    I.Kind                        = Function;
    I.Loc                         = LocalRangeBegin;
    I.EndLoc                      = LocalRangeEnd;
    I.Fun.AttrList                = 0;
    I.Fun.hasPrototype            = hasProto;
    I.Fun.isVariadic              = isVariadic;
    I.Fun.EllipsisLoc             = EllipsisLoc.getRawEncoding();
    I.Fun.DeleteArgInfo           = false;
    I.Fun.TypeQuals               = TypeQuals;
    I.Fun.NumArgs                 = NumArgs;
    I.Fun.ArgInfo                 = 0;
    I.Fun.RefQualifierIsLValueRef = RefQualifierIsLvalueRef;
    I.Fun.RefQualifierLoc         = RefQualifierLoc.getRawEncoding();
    I.Fun.ConstQualifierLoc       = ConstQualifierLoc.getRawEncoding();
    I.Fun.VolatileQualifierLoc    = VolatileQualifierLoc.getRawEncoding();
    I.Fun.MutableLoc              = MutableLoc.getRawEncoding();
    I.Fun.ExceptionSpecType       = ESpecType;
    I.Fun.ExceptionSpecLoc        = ESpecLoc.getRawEncoding();
    I.Fun.NumExceptions           = 0;
    I.Fun.Exceptions              = 0;
    I.Fun.NoexceptExpr            = 0;
    I.Fun.TrailingReturnType   = TrailingReturnType.getAsOpaquePtr();

    // new[] an argument array if needed.
    if (NumArgs) {
        // If the 'InlineParams' in Declarator is unused and big enough, put our
        // parameter list there (in an effort to avoid new/delete traffic).  If it
        // is already used (consider a function returning a function pointer) or too
        // small (function taking too many arguments), go to the heap.
        if (!TheDeclarator.InlineParamsUsed &&
                NumArgs <= llvm::array_lengthof(TheDeclarator.InlineParams)) {
            I.Fun.ArgInfo = TheDeclarator.InlineParams;
            I.Fun.DeleteArgInfo = false;
            TheDeclarator.InlineParamsUsed = true;
        } else {
            I.Fun.ArgInfo = new DeclaratorChunk::ParamInfo[NumArgs];
            I.Fun.DeleteArgInfo = true;
        }
        memcpy(I.Fun.ArgInfo, ArgInfo, sizeof(ArgInfo[0])*NumArgs);
    }

    // Check what exception specification information we should actually store.
    switch (ESpecType) {
    default:
        break; // By default, save nothing.
    case EST_Dynamic:
        // new[] an exception array if needed
        if (NumExceptions) {
            I.Fun.NumExceptions = NumExceptions;
            I.Fun.Exceptions = new DeclaratorChunk::TypeAndRange[NumExceptions];
            for (unsigned i = 0; i != NumExceptions; ++i) {
                I.Fun.Exceptions[i].Ty = Exceptions[i];
                I.Fun.Exceptions[i].Range = ExceptionRanges[i];
            }
        }
        break;

    case EST_ComputedNoexcept:
        I.Fun.NoexceptExpr = NoexceptExpr;
        break;
    }
    return I;
}