Ejemplo n.º 1
0
 void Transaction::appendUnique(DeclGroupRef DGR) {
   for (const_iterator I = decls_begin(), E = decls_end(); I != E; ++I) {
     if (DGR.isNull() || (*I).getAsOpaquePtr() == DGR.getAsOpaquePtr())
       return;
   }
   m_DeclQueue.push_back(DGR);
 }
Ejemplo n.º 2
0
void MoveGlobalVar::handleOtherDecl(DeclGroupRef DGR)
{
  if (!TheFirstFunctionDecl)
    return;

  ValidInstanceNum++;
  if (TransformationCounter == ValidInstanceNum)
    TheDGRPointer = DGR.getAsOpaquePtr();
}
Ejemplo n.º 3
0
bool CombineGlobalVarDecl::HandleTopLevelDecl(DeclGroupRef DGR) 
{
  DeclGroupRef::iterator DI = DGR.begin();
  VarDecl *VD = dyn_cast<VarDecl>(*DI);
  if (!VD || isInIncludedFile(VD))
    return true;
  SourceRange Range = VD->getSourceRange();
  if (Range.getBegin().isInvalid() || Range.getEnd().isInvalid())
    return true;

  const Type *T = VD->getType().getTypePtr();
  const Type *CanonicalT = Context->getCanonicalType(T);
  
  DeclGroupVector *DV;
  TypeToDeclMap::iterator TI = AllDeclGroups.find(CanonicalT);
  if (TI == AllDeclGroups.end()) {
    DV = new DeclGroupVector();
    AllDeclGroups[CanonicalT] = DV;
  }
  else {
    ValidInstanceNum++;
    DV = (*TI).second;

    if (ValidInstanceNum == TransformationCounter) {
      if (DV->size() >= 1) {
        void* DP1 = *(DV->begin());
        TheDeclGroupRefs.push_back(DP1);
        TheDeclGroupRefs.push_back(DGR.getAsOpaquePtr());
      }
    }
  }

  // Note that it's unnecessary to keep all encountered
  // DeclGroupRefs. We could choose a light way similar
  // to what we implemented in CombineLocalVarDecl.
  // I kept the code here because I feel we probably 
  // need more combinations, i.e., not only combine the
  // first DeclGroup with others, but we could combine
  // the second one and the third one. 
  DV->push_back(DGR.getAsOpaquePtr());
  return true;
}
Ejemplo n.º 4
0
void SimplifyStructUnionDecl::addOneRecordDecl(const RecordDecl *RD,
                                               DeclGroupRef DGR)
{
  const Decl *CanonicalD = RD->getCanonicalDecl();

  const RecordDecl *RDDef = RD->getDefinition();
  if (!RDDef || (RD != RDDef))
    return;

  if (!RecordDeclToDeclGroup[CanonicalD])
    RecordDeclToDeclGroup[CanonicalD] = (DGR.getAsOpaquePtr());
}
Ejemplo n.º 5
0
bool SimplifyStructUnionDecl::HandleTopLevelDecl(DeclGroupRef DGR) 
{
  DeclGroupRef::iterator DI = DGR.begin();
  if (isInIncludedFile(*DI))
    return true;

  const RecordDecl *RD = dyn_cast<RecordDecl>(*DI);
  if (RD) {
    addOneRecordDecl(RD, DGR);
    return true;
  }

  VarDecl *VD = dyn_cast<VarDecl>(*DI);
  if (!VD)
    return true;

  const Type *T = VD->getType().getTypePtr();

  RD = getBaseRecordDecl(T);
  if (!RD)
    return true;

  const Decl *CanonicalD = RD->getCanonicalDecl();
  void *DGRPointer = RecordDeclToDeclGroup[CanonicalD];
  if (!DGRPointer)
    return true;

  ValidInstanceNum++;
  if (ValidInstanceNum != TransformationCounter)
    return true;

  TheRecordDecl = dyn_cast<RecordDecl>(CanonicalD);
  TheDeclGroupRefs.push_back(DGRPointer);
  TheDeclGroupRefs.push_back(DGR.getAsOpaquePtr());

  for (DeclGroupRef::iterator I = DGR.begin(), E = DGR.end(); I != E; ++I) {
    VarDecl *VD = dyn_cast<VarDecl>(*I);
    TransAssert(VD && "Bad VarDecl!");
    CombinedVars.insert(VD);
  }

  DeclGroupRef DefDGR = DeclGroupRef::getFromOpaquePtr(DGRPointer);
  for (DeclGroupRef::iterator I = DefDGR.begin(), 
       E = DefDGR.end(); I != E; ++I) {
    VarDecl *VD = dyn_cast<VarDecl>(*I);
    if (VD)
      CombinedVars.insert(VD);
  }
  return true;
}