Parser.h

Go to the documentation of this file.
00001 //===-- Parser.h ------------------------------------------------*- C++ -*-===//
00002 //
00003 //                     The KLEE Symbolic Virtual Machine
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 
00010 #ifndef KLEE_EXPR_PARSER_H
00011 #define KLEE_EXPR_PARSER_H
00012 
00013 #include "klee/Expr.h"
00014 
00015 #include <vector>
00016 #include <string>
00017 
00018 namespace llvm {
00019   class MemoryBuffer;
00020 }
00021 
00022 namespace klee {
00023 namespace expr {
00024   // These are the language types we manipulate.
00025   typedef ref<Expr> ExprHandle;
00026   typedef UpdateList VersionHandle;
00027   
00029   struct Identifier {
00030     const std::string Name;
00031 
00032   public:
00033     Identifier(const std::string _Name) : Name(_Name) {}
00034   };
00035 
00036   // FIXME: Do we have a use for tracking source locations?
00037 
00039   class Decl {
00040   public:
00041     enum DeclKind {
00042       ArrayDeclKind,
00043       ExprVarDeclKind,
00044       VersionVarDeclKind,
00045       QueryCommandDeclKind,
00046       
00047       DeclKindLast = QueryCommandDeclKind,
00048       VarDeclKindFirst = ExprVarDeclKind,
00049       VarDeclKindLast = VersionVarDeclKind,
00050       CommandDeclKindFirst = QueryCommandDeclKind,
00051       CommandDeclKindLast = QueryCommandDeclKind
00052     };
00053 
00054   private:
00055     DeclKind Kind;
00056 
00057   public:
00058     Decl(DeclKind _Kind);
00059     virtual ~Decl() {}
00060 
00062     DeclKind getKind() const { return Kind; }
00063 
00065     virtual void dump() = 0;
00066 
00067     static bool classof(const Decl *) { return true; }
00068   };
00069 
00075   class ArrayDecl : public Decl {
00076   public:
00078     const Identifier *Name;
00079 
00082     const unsigned Size;
00083 
00085     const unsigned Domain;
00086 
00088     const unsigned Range;
00089 
00091     const Array *Root;
00092 
00096     const std::vector<ExprHandle> Contents;
00097 
00098   public:
00099     ArrayDecl(const Identifier *_Name, unsigned _Size, 
00100               unsigned _Domain, unsigned _Range,
00101               const Array *_Root)
00102       : Decl(ArrayDeclKind), Name(_Name), 
00103         Size(_Size), Domain(_Domain), Range(_Range), 
00104         Root(_Root) {
00105     }
00106 
00107     virtual void dump();
00108 
00109     static bool classof(const Decl *D) {
00110       return D->getKind() == Decl::ArrayDeclKind;
00111     }
00112     static bool classof(const ArrayDecl *) { return true; }
00113   };
00114 
00119   // FIXME: What syntax are we going to use for this? We need it.
00120   class VarDecl : public Decl {
00121   public:
00122     const Identifier *Name;    
00123 
00124     static bool classof(const Decl *D) {
00125       return (Decl::VarDeclKindFirst <= D->getKind() &&
00126               D->getKind() <= Decl::VarDeclKindLast);
00127     }
00128     static bool classof(const VarDecl *) { return true; }
00129   };
00130 
00132   class ExprVarDecl : public VarDecl {
00133   public:
00134     ExprHandle Value;
00135 
00136     static bool classof(const Decl *D) {
00137       return D->getKind() == Decl::ExprVarDeclKind;
00138     }
00139     static bool classof(const ExprVarDecl *) { return true; }
00140   };
00141 
00143   class VersionVarDecl : public VarDecl {
00144   public:
00145     VersionHandle Value;
00146 
00147     static bool classof(const Decl *D) {
00148       return D->getKind() == Decl::VersionVarDeclKind;
00149     }
00150     static bool classof(const VersionVarDecl *) { return true; }
00151   };
00152 
00154   class CommandDecl : public Decl {
00155   public:
00156     CommandDecl(DeclKind _Kind) : Decl(_Kind) {}
00157 
00158     static bool classof(const Decl *D) {
00159       return (Decl::CommandDeclKindFirst <= D->getKind() &&
00160               D->getKind() <= Decl::CommandDeclKindLast);
00161     }
00162     static bool classof(const CommandDecl *) { return true; }
00163   };
00164 
00170   class QueryCommand : public CommandDecl {
00171   public:
00172     // FIXME: One issue with STP... should we require the FE to
00173     // guarantee that these are consistent? That is a cornerstone of
00174     // being able to do independence. We may want this as a flag, if
00175     // we are to interface with things like SMT.
00176 
00179     const std::vector<ExprHandle> Constraints;
00180     
00182     ExprHandle Query;
00183 
00186     const std::vector<ExprHandle> Values;
00187 
00190     const std::vector<const Array*> Objects;
00191 
00192   public:
00193     QueryCommand(const std::vector<ExprHandle> &_Constraints,
00194                  ExprHandle _Query,
00195                  const std::vector<ExprHandle> &_Values,
00196                  const std::vector<const Array*> &_Objects
00197                  )
00198       : CommandDecl(QueryCommandDeclKind),
00199         Constraints(_Constraints),
00200         Query(_Query),
00201         Values(_Values),
00202         Objects(_Objects) {}
00203 
00204     virtual void dump();
00205 
00206     static bool classof(const Decl *D) {
00207       return D->getKind() == QueryCommandDeclKind;
00208     }
00209     static bool classof(const QueryCommand *) { return true; }
00210   };
00211   
00213   class Parser {
00214   protected:
00215     Parser();
00216   public:
00217     virtual ~Parser();
00218 
00220     virtual void SetMaxErrors(unsigned N) = 0;
00221     
00223     virtual unsigned GetNumErrors() const = 0;
00224 
00229     virtual Decl *ParseTopLevelDecl() = 0;
00230 
00235     static Parser *Create(const std::string Name,
00236                           const llvm::MemoryBuffer *MB);
00237   };
00238 }
00239 }
00240 
00241 #endif

Generated on Fri Jun 5 03:31:31 2009 for klee by  doxygen 1.5.8