Exemplo n.º 1
0
    void RemoveDefaultArgsOf(Decl* D, Sema* S) {
      m_Sema = S;

      auto cursor = D->getMostRecentDecl();
      m_IsAutloadEntry = IsAutoloadEntry(cursor);
      TraverseDecl(cursor);
      while (cursor != D && (cursor = cursor->getPreviousDecl())) {
        m_IsAutloadEntry = IsAutoloadEntry(cursor);
        TraverseDecl(cursor);
      }
      m_IsAutloadEntry = false;
    }
Exemplo n.º 2
0
// DECLSTMT Allows mix of decl and statements
bool SuperastCPP::TraverseDeclStmt(clang::DeclStmt* declStmt) {
  if (declStmt->isSingleDecl()) {
    TRY_TO(TraverseDecl(declStmt->getSingleDecl()));
  }
  else {
    // Group of  declStmt
    rapidjson::Value arrayValue(rapidjson::kArrayType);
    const clang::DeclGroupRef declGroup = declStmt->getDeclGroup();
    for (auto iterator = declGroup.begin(); iterator != declGroup.end(); ++iterator) {
      TRY_TO(TraverseDecl(*iterator));
      arrayValue.PushBack(sonValue, allocator);
    }
    sonValue = arrayValue;
  }
  return true;
}
Exemplo n.º 3
0
// MEMBER EXPR. Access to a member of a struct or class.
// Translate to binary operator with operator []
bool SuperastCPP::TraverseMemberExpr(clang::MemberExpr* memberExpr) {
  // Accessing a member. Translate into binary operator []
  // Save current status
  const std::string opString = "[]";

  rapidjson::Value leftValue;
  TRY_TO(TraverseStmt(memberExpr->getBase()));
  leftValue = sonValue;

  // Build right value from Declaration
  rapidjson::Value rightValue;
  TRY_TO(TraverseDecl(memberExpr->getMemberDecl()));
  rightValue = sonValue;

  // Instead of data-type, just a type 'string'
  rightValue.AddMember("type", "string", allocator);
  rightValue.EraseMember(rightValue.FindMember("data-type"));
  // The id as 'value', not 'name'
  rightValue.AddMember("value", rightValue["name"], allocator);
  rightValue.EraseMember(rightValue.FindMember("name"));
      
  rapidjson::Value memberExprValue = createBinOpValue(opString, leftValue, rightValue);
  addPos(memberExprValue, memberExpr);

  sonValue = memberExprValue;
  return true;
}
Exemplo n.º 4
0
    // this method is called to analyze the entire AST
    void HandleTranslationUnit(ASTContext &Ctx) {
        // the visitor functions will be invoked by this
        //llvm::errs() << "handling translation unit\n";
        TraverseDecl(Ctx.getTranslationUnitDecl());
        //llvm::errs() << "DONE VISITING\n";

        OutputAnnotation();
        //llvm::errs() << "DONE ANNOTATING\n";
    }
Exemplo n.º 5
0
 void TrackDefaultArgStateOf(Decl* D, AutoloadCallback::FwdDeclsMap& map,
                             Preprocessor& PP) {
   m_IsStoringState = true;
   m_Map = &map;
   m_PP = &PP;
   TraverseDecl(D);
   m_PP = 0;
   m_Map = 0;
   m_IsStoringState = false;
 }
Exemplo n.º 6
0
    bool VisitTemplateDecl(TemplateDecl* D) {
      if (D->getTemplatedDecl() &&
          !D->getTemplatedDecl()->hasAttr<AnnotateAttr>())
        return true;

      VisitDecl(D);

      for(auto P: D->getTemplateParameters()->asArray())
        TraverseDecl(P);
      return true;
    }
Exemplo n.º 7
0
bool SuperastCPP::TraverseFunctionDecl(clang::FunctionDecl* functionDecl) {

  const std::string functionName = functionDecl->getNameInfo().getAsString();

  rapidjson::Value functionValue(rapidjson::kObjectType);
  addId(functionValue);
  addPos(functionValue, functionDecl);
  
  functionValue.AddMember("type", "function-declaration", allocator);
  // Add the name
  functionValue.AddMember(
      "name", 
      rapidjson::Value().SetString(functionName.c_str(), 
                                   functionName.size(),
                                   allocator), 
      allocator);

  // Add the return type
  clang::QualType qualType = functionDecl->getCallResultType().getNonLValueExprType(*context);
  functionValue.AddMember("return-type", createTypeValue((qualType.getTypePtr())), allocator);

  // Array of parameters
  rapidjson::Value parametersValue(rapidjson::kArrayType);

  // Traverse parameters
  for (unsigned int i = 0; i < functionDecl->param_size(); ++i) {
    TRY_TO(TraverseDecl(functionDecl->getParamDecl(i)));

    // Add the parameter to array
    parametersValue.PushBack(sonValue, allocator);
  }

  // Add parameters to functionValue
  functionValue.AddMember("parameters", parametersValue, allocator);
  
  // If this is a function definition, traverse definition.
  if (functionDecl->isThisDeclarationADefinition()) {
    TRY_TO(TraverseStmt(functionDecl->getBody()));
    ensureSonIsArray();
    rapidjson::Value blockValue = createBlockValue(sonValue);
    functionValue.AddMember("block", blockValue, allocator);
  }
  else {
    // If not definition, add empty block
    rapidjson::Value emptyArray(rapidjson::kArrayType);
    functionValue.AddMember("block", createBlockValue(emptyArray), allocator);
  }

  // END BODY TRAVERSE
  sonValue = functionValue;
  return true;
}
Exemplo n.º 8
0
    bool VisitTemplateDecl(TemplateDecl* D) {
      if (D->getTemplatedDecl() &&
          !D->getTemplatedDecl()->hasAttr<AnnotateAttr>())
        return true;

      // If we have a definition we might be about to re-#include the
      // same header containing definition that was #included previously,
      // i.e. we might have multiple fwd decls for the same template.
      // DO NOT remove the defaults here; the definition needs to keep it.
      // (ROOT-7037)
      if (ClassTemplateDecl* CTD = dyn_cast<ClassTemplateDecl>(D))
        if (CXXRecordDecl* TemplatedD = CTD->getTemplatedDecl())
          if (TemplatedD->getDefinition())
            return true;

      for(auto P: D->getTemplateParameters()->asArray())
        TraverseDecl(P);
      return true;
    }
Exemplo n.º 9
0
void RewriterASTConsumer::HandleTranslationUnit(ASTContext& Context)
{
    TranslationUnitDecl* D = Context.getTranslationUnitDecl();
    TraverseDecl(D);

    const RewriteBuffer& RewriteBufG =
            TheGpuRewriter.getEditBuffer(TheGpuRewriter.getSourceMgr().getMainFileID());
    RewritenGpuSource = std::string(RewriteBufG.begin(), RewriteBufG.end());

    const RewriteBuffer& RewriteBufC =
            TheCpuRewriter.getEditBuffer(TheCpuRewriter.getSourceMgr().getMainFileID());
    RewritenCpuSource = std::string(RewriteBufC.begin(), RewriteBufC.end());

#ifdef Out
    llvm::errs() << "______________________________ CPU _____________________ \n";
    llvm::errs() << std::string(RewriteBufC.begin(), RewriteBufC.end());
    llvm::errs() << "\n\n______________________________ GPU _____________________ \n";
    llvm::errs() << std::string(RewriteBufG.begin(), RewriteBufG.end());
#endif
}
Exemplo n.º 10
0
// The AST entry point. Here begins everything.
bool SuperastCPP::TraverseTranslationUnitDecl(
    clang::TranslationUnitDecl* unitDecl) {
  // Create the block object at root of DOM
  document.SetObject();

  // Set the pointer. Statements from root will be added here
  addId(document);
  document.AddMember("statements", rapidjson::kArrayType, allocator);

  for (auto declaration : unitDecl->decls()) {
    TRY_TO(TraverseDecl(declaration));
    if (!sonValue.IsNull()) {
      if (sonValue.IsArray()) {
        addElemsToArray(document["statements"], sonValue);
      }
      else {
        document["statements"].PushBack(sonValue, allocator);
      }
    }
  }
  return true;
}
Exemplo n.º 11
0
 void RemoveDefaultArgsOf(Decl* D) {
   //D = D->getMostRecentDecl();
   TraverseDecl(D);
   //while ((D = D->getPreviousDecl()))
   //  TraverseDecl(D);
 }
Exemplo n.º 12
0
void Consumer::HandleTranslationUnit( ASTContext& context )
    {
    if( context.getDiagnostics().hasErrorOccurred())
        return;
    TraverseDecl( compiler.getASTContext().getTranslationUnitDecl());
    }
 /// \brief Whether or not the parameter variable is referred only once in
 /// the
 /// given constructor.
 bool hasExactlyOneUsageIn(const CXXConstructorDecl *Ctor) {
   Count = 0;
   TraverseDecl(const_cast<CXXConstructorDecl *>(Ctor));
   return Count == 1;
 }