[cfe-commits] r58073 - in /cfe/trunk: include/clang/Analysis/PathSensitive/SVals.h lib/Analysis/SVals.cpp

Ted Kremenek kremenek at apple.com
Thu Oct 23 23:07:00 PDT 2008


Great Zhongxing!  We should probably just remove the ostream versions.

On Oct 23, 2008, at 11:00 PM, Zhongxing Xu wrote:

> Author: zhongxingxu
> Date: Fri Oct 24 01:00:12 2008
> New Revision: 58073
>
> URL: http://llvm.org/viewvc/llvm-project?rev=58073&view=rev
> Log:
> Add printing with llvm::raw_ostream methods to SVals.
>
> Modified:
>    cfe/trunk/include/clang/Analysis/PathSensitive/SVals.h
>    cfe/trunk/lib/Analysis/SVals.cpp
>
> Modified: cfe/trunk/include/clang/Analysis/PathSensitive/SVals.h
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Analysis/PathSensitive/SVals.h?rev=58073&r1=58072&r2=58073&view=diff
>
> =
> =
> =
> =
> =
> =
> =
> =
> ======================================================================
> --- cfe/trunk/include/clang/Analysis/PathSensitive/SVals.h (original)
> +++ cfe/trunk/include/clang/Analysis/PathSensitive/SVals.h Fri Oct  
> 24 01:00:12 2008
> @@ -89,6 +89,7 @@
>   bool isZeroConstant() const;
>
>   void print(std::ostream& OS) const;
> +  void print(llvm::raw_ostream& OS) const;
>   void printStdErr() const;
>
>   typedef const SymbolID* symbol_iterator;
> @@ -126,6 +127,7 @@
>
> public:
>   void print(std::ostream& Out) const;
> +  void print(llvm::raw_ostream& Out) const;
>
>   // Utility methods to create NonLocs.
>   static NonLoc MakeVal(BasicValueFactory& BasicVals, uint64_t X,  
> QualType T);
> @@ -151,6 +153,7 @@
>
> public:
>   void print(std::ostream& Out) const;
> +  void print(llvm::raw_ostream& Out) const;
>
>   static Loc MakeVal(AddrLabelExpr* E);
>
>
> Modified: cfe/trunk/lib/Analysis/SVals.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/SVals.cpp?rev=58073&r1=58072&r2=58073&view=diff
>
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> ======================================================================
> --- cfe/trunk/lib/Analysis/SVals.cpp (original)
> +++ cfe/trunk/lib/Analysis/SVals.cpp Fri Oct 24 01:00:12 2008
> @@ -397,3 +397,134 @@
>       break;
>   }
> }
> +
> +// 
> = 
> = 
> = 
> ----------------------------------------------------------------------= 
> ==//
> +// Pretty-Printing with llvm::raw_ostream.
> +// 
> = 
> = 
> = 
> ----------------------------------------------------------------------= 
> ==//
> +
> +void SVal::print(llvm::raw_ostream& Out) const {
> +
> +  switch (getBaseKind()) {
> +
> +    case UnknownKind:
> +      Out << "Invalid"; break;
> +
> +    case NonLocKind:
> +      cast<NonLoc>(this)->print(Out); break;
> +
> +    case LocKind:
> +      cast<Loc>(this)->print(Out); break;
> +
> +    case UndefinedKind:
> +      Out << "Undefined"; break;
> +
> +    default:
> +      assert (false && "Invalid SVal.");
> +  }
> +}
> +
> +static void printOpcode(llvm::raw_ostream& Out,  
> BinaryOperator::Opcode Op) {
> +
> +  switch (Op) {
> +    case BinaryOperator::Mul: Out << '*'  ; break;
> +    case BinaryOperator::Div: Out << '/'  ; break;
> +    case BinaryOperator::Rem: Out << '%'  ; break;
> +    case BinaryOperator::Add: Out << '+'  ; break;
> +    case BinaryOperator::Sub: Out << '-'  ; break;
> +    case BinaryOperator::Shl: Out << "<<" ; break;
> +    case BinaryOperator::Shr: Out << ">>" ; break;
> +    case BinaryOperator::LT:  Out << "<"  ; break;
> +    case BinaryOperator::GT:  Out << '>'  ; break;
> +    case BinaryOperator::LE:  Out << "<=" ; break;
> +    case BinaryOperator::GE:  Out << ">=" ; break;
> +    case BinaryOperator::EQ:  Out << "==" ; break;
> +    case BinaryOperator::NE:  Out << "!=" ; break;
> +    case BinaryOperator::And: Out << '&'  ; break;
> +    case BinaryOperator::Xor: Out << '^'  ; break;
> +    case BinaryOperator::Or:  Out << '|'  ; break;
> +
> +    default: assert(false && "Not yet implemented.");
> +  }
> +}
> +
> +void NonLoc::print(llvm::raw_ostream& Out) const {
> +
> +  switch (getSubKind()) {
> +
> +    case nonloc::ConcreteIntKind:
> +      Out << cast<nonloc::ConcreteInt>(this)- 
> >getValue().getZExtValue();
> +
> +      if (cast<nonloc::ConcreteInt>(this)->getValue().isUnsigned())
> +        Out << 'U';
> +
> +      break;
> +
> +    case nonloc::SymbolValKind:
> +      Out << '$' << cast<nonloc::SymbolVal>(this)->getSymbol();
> +      break;
> +
> +    case nonloc::SymIntConstraintValKind: {
> +      const nonloc::SymIntConstraintVal& C =
> +        *cast<nonloc::SymIntConstraintVal>(this);
> +
> +      Out << '$' << C.getConstraint().getSymbol() << ' ';
> +      printOpcode(Out, C.getConstraint().getOpcode());
> +      Out << ' ' << C.getConstraint().getInt().getZExtValue();
> +
> +      if (C.getConstraint().getInt().isUnsigned())
> +        Out << 'U';
> +
> +      break;
> +    }
> +
> +    case nonloc::LocAsIntegerKind: {
> +      const nonloc::LocAsInteger& C =  
> *cast<nonloc::LocAsInteger>(this);
> +      C.getLoc().print(Out);
> +      Out << " [as " << C.getNumBits() << " bit integer]";
> +      break;
> +    }
> +
> +    default:
> +      assert (false && "Pretty-printed not implemented for this  
> NonLoc.");
> +      break;
> +  }
> +}
> +
> +void Loc::print(llvm::raw_ostream& Out) const {
> +
> +  switch (getSubKind()) {
> +
> +    case loc::ConcreteIntKind:
> +      Out << cast<loc::ConcreteInt>(this)->getValue().getZExtValue()
> +          << " (Loc)";
> +      break;
> +
> +    case loc::SymbolValKind:
> +      Out << '$' << cast<loc::SymbolVal>(this)->getSymbol();
> +      break;
> +
> +    case loc::GotoLabelKind:
> +      Out << "&&"
> +          << cast<loc::GotoLabel>(this)->getLabel()->getID()- 
> >getName();
> +      break;
> +
> +    case loc::MemRegionKind:
> +      Out << '&' << cast<loc::MemRegionVal>(this)->getRegion()- 
> >getString();
> +      break;
> +
> +    case loc::FuncValKind:
> +      Out << "function "
> +          << cast<loc::FuncVal>(this)->getDecl()->getIdentifier()- 
> >getName();
> +      break;
> +
> +    case loc::StringLiteralValKind:
> +      Out << "literal \""
> +          << cast<loc::StringLiteralVal>(this)->getLiteral()- 
> >getStrData()
> +          << "\"";
> +      break;
> +
> +    default:
> +      assert (false && "Pretty-printing not implemented for this  
> Loc.");
> +      break;
> +  }
> +}
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits




More information about the cfe-commits mailing list