Computer Laboratory

tesla::TeslaVisitor Class Reference

Detailed Description

Definition at line 45 of file Visitor.h.

#include "Visitor.h"

+ Inheritance diagram for tesla::TeslaVisitor:
+ Collaboration diagram for tesla::TeslaVisitor:

Public Member Functions

 TeslaVisitor (llvm::StringRef Filename, clang::ASTContext *Context)
 
 ~TeslaVisitor ()
 
bool VisitCallExpr (clang::CallExpr *)
 
bool VisitFunctionDecl (clang::FunctionDecl *)
 Visit a function declaration, looking for TESLA automata descriptions. More...
 
const llvm::ArrayRef
< AutomatonDescription * > 
GetAutomata () const
 
const llvm::ArrayRef< const
Usage * > 
RootAutomata () const
 

Constructor & Destructor Documentation

tesla::TeslaVisitor::TeslaVisitor ( llvm::StringRef  Filename,
clang::ASTContext *  Context 
)

Definition at line 54 of file Visitor.cpp.

55  : Filename(Filename), Context(Context)
56 {
57 }
tesla::TeslaVisitor::~TeslaVisitor ( )

Definition at line 59 of file Visitor.cpp.

59  {
60  for (auto *A : Automata)
61  delete A;
62 
63  for (auto *R : Roots)
64  delete R;
65 }

Member Function Documentation

const llvm::ArrayRef<AutomatonDescription*> tesla::TeslaVisitor::GetAutomata ( ) const
inline

Definition at line 55 of file Visitor.h.

Referenced by tesla::TeslaConsumer::HandleTranslationUnit().

55  {
56  return Automata;
57  }

+ Here is the caller graph for this function:

const llvm::ArrayRef<const Usage*> tesla::TeslaVisitor::RootAutomata ( ) const
inline

Definition at line 59 of file Visitor.h.

Referenced by tesla::TeslaConsumer::HandleTranslationUnit().

59  {
60  return Roots;
61  }

+ Here is the caller graph for this function:

bool tesla::TeslaVisitor::VisitCallExpr ( clang::CallExpr *  )

Definition at line 67 of file Visitor.cpp.

References tesla::Parser::AssertionParser(), tesla::INLINE_ASSERTION, and tesla::TESLA_BASE.

67  {
68  FunctionDecl *F = E->getDirectCallee();
69  if (!F) return true;
70 
71  StringRef FnName = F->getName();
72  if (!FnName.startswith(TESLA_BASE)) return true;
73 
74  // TESLA function calls might be inline assertions.
75  if (FnName == INLINE_ASSERTION) {
76  OwningPtr<Parser> P(Parser::AssertionParser(E, *Context));
77  if (!P)
78  return false;
79 
80  OwningPtr<AutomatonDescription> Description;
81  OwningPtr<Usage> Use;
82  if (!P->Parse(Description, Use))
83  return false;
84 
85  Automata.push_back(Description.take());
86  Roots.push_back(Use.take());
87  return true;
88  }
89 
90  return true;
91 }

+ Here is the call graph for this function:

bool tesla::TeslaVisitor::VisitFunctionDecl ( clang::FunctionDecl *  )

Visit a function declaration, looking for TESLA automata descriptions.

Definition at line 94 of file Visitor.cpp.

References tesla::AUTOMATON_DESC, tesla::AUTOMATON_USAGE, tesla::AUTOMATON_USES, tesla::Parser::AutomatonParser(), and tesla::Parser::MappingParser().

94  {
95  // Only analyse non-deleted definitions (i.e. definitions with bodies).
96  if (!F->doesThisDeclarationHaveABody())
97  return true;
98 
99 
100  // We only parse functions that return __tesla_automaton_description*.
101  const Type *RetTy = F->getResultType().getTypePtr();
102  if (!RetTy->isPointerType())
103  return true;
104 
105  QualType Pointee = RetTy->getPointeeType();
106  auto TypeID = Pointee.getBaseTypeIdentifier();
107  if (!TypeID)
108  return true;
109 
110  OwningPtr<Parser> P;
111  StringRef FnName = F->getName();
112 
113  // Build a Parser appropriate to what we're parsing.
114  string RetTypeName = TypeID->getName();
115  if (RetTypeName == AUTOMATON_DESC)
116  P.reset(Parser::AutomatonParser(F, *Context));
117 
118  else if ((RetTypeName == AUTOMATON_USAGE) && (FnName != AUTOMATON_USES))
119  P.reset(Parser::MappingParser(F, *Context));
120 
121  else
122  return true;
123 
124 
125  // Actually parse the function.
126  if (!P)
127  return false;
128 
129  OwningPtr<AutomatonDescription> Description;
130  OwningPtr<Usage> Use;
131  if (!P->Parse(Description, Use))
132  return false;
133 
134  if (Description)
135  Automata.push_back(Description.take());
136 
137  if (Use)
138  Roots.push_back(Use.take());
139 
140  return true;
141 }

+ Here is the call graph for this function:


The documentation for this class was generated from the following files: