Computer Laboratory

Detailed Description

A parser for TESLA automata descriptions.

Definition at line 68 of file Parser.h.

#include "Parser.h"

Public Types

typedef std::vector< const
clang::ValueDecl * > 
RefVector
 Variables referenced by an automaton. More...
 

Public Member Functions

bool Parse (llvm::OwningPtr< AutomatonDescription > &Descrip, llvm::OwningPtr< Usage > &Usage)
 Parse the automaton and its usage. More...
 

Static Public Member Functions

static ParserAssertionParser (clang::CallExpr *, clang::ASTContext &)
 Create a Parser for an inline assertion. More...
 
static ParserAutomatonParser (clang::FunctionDecl *, clang::ASTContext &)
 Create a Parser for an automaton description. More...
 
static ParserMappingParser (clang::FunctionDecl *, clang::ASTContext &)
 Create a Parser for a struct-automaton mapping. More...
 

Member Typedef Documentation

typedef std::vector<const clang::ValueDecl*> tesla::Parser::RefVector

Variables referenced by an automaton.

Definition at line 71 of file Parser.h.

Member Function Documentation

Parser * Parser::AssertionParser ( clang::CallExpr *  ,
clang::ASTContext &   
)
static

Create a Parser for an inline assertion.

Definition at line 51 of file Parser.cpp.

References tesla::INLINE_ASSERTION, and tesla::TeslaContext().

Referenced by tesla::TeslaVisitor::VisitCallExpr().

51  {
52  assert(Call->getDirectCallee()->getName().compare(INLINE_ASSERTION) == 0);
53 
54  OwningPtr<Parser> Bootstrap(new Parser(Ctx));
55 
56  if (Call->getNumArgs() != 7) {
57  Bootstrap->ReportError(
58  "expected seven arguments: "
59  "filename, line, counter, context, start, end, expression",
60  Call);
61  return NULL;
62  }
63 
64  Expr *Filename = Call->getArg(0);
65  Expr *Line = Call->getArg(1);
66  Expr *Counter = Call->getArg(2);
67  Expr *Context = Call->getArg(3);
68  Expr *Beginning = Call->getArg(4);
69  Expr *End = Call->getArg(5);
70  Expr *Expression = Call->getArg(6);
71 
72  Identifier ID;
73  if (!Bootstrap->Parse(ID.mutable_location(), Filename, Line, Counter))
74  return NULL;
75 
77  if (!Bootstrap->Parse(&TeslaContext, Context))
78  return NULL;
79 
80  Flags RootFlags;
81  RootFlags.FnInstrContext = FunctionEvent::Callee;
82  RootFlags.OrOperator = BooleanExpr::BE_Or;
83  RootFlags.StrictMode = false;
84 
85  return new Parser(Ctx, ID, TeslaContext, Beginning, End, Expression, RootFlags);
86 }

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Parser * Parser::AutomatonParser ( clang::FunctionDecl *  ,
clang::ASTContext &   
)
static

Create a Parser for an automaton description.

Definition at line 89 of file Parser.cpp.

Referenced by tesla::TeslaVisitor::VisitFunctionDecl().

89  {
90  assert(F != NULL);
91  assert(F->doesThisDeclarationHaveABody());
92 
93  Identifier ID;
94  ID.set_name(F->getName());
95 
96  OwningPtr<Parser> Bootstrap(new Parser(Ctx));
97 
98  // We should reference one variable: the struct pointer.
99  if (F->getNumParams() != 1) {
100  Bootstrap->ReportError("expected one parameter: the struct", F);
101  return NULL;
102  }
103 
104  // TODO: programmer-specified context
106 
107  ValueDecl *StructRef = F->getParamDecl(0);
108 
109  const PointerType *StructPtrTy = dyn_cast<PointerType>(StructRef->getType());
110  if (!StructPtrTy || !StructPtrTy->getPointeeType()->getAsStructureType()) {
111  Bootstrap->ReportError("expected pointer to struct", StructRef);
112  return NULL;
113  }
114 
115  Flags RootFlags;
116  RootFlags.FnInstrContext = FunctionEvent::Callee;
117  RootFlags.OrOperator = BooleanExpr::BE_Xor;
118  RootFlags.StrictMode = true;
119 
120  return new Parser(Ctx, ID, Context, NULL, NULL, F->getBody(), RootFlags);
121 }

+ Here is the caller graph for this function:

Parser * Parser::MappingParser ( clang::FunctionDecl *  ,
clang::ASTContext &   
)
static

Create a Parser for a struct-automaton mapping.

Definition at line 124 of file Parser.cpp.

References tesla::AUTOMATON_USES.

Referenced by tesla::TeslaVisitor::VisitFunctionDecl().

124  {
125  assert(F != NULL);
126  assert(F->doesThisDeclarationHaveABody());
127 
128  OwningPtr<Parser> Bootstrap(new Parser(Ctx));
129 
130  auto Body = dyn_cast<CompoundStmt>(F->getBody());
131  if (!Body) {
132  Bootstrap->ReportError("expected a function body (compound statement)", F);
133  return NULL;
134  }
135 
136  if (Body->size() != 1) {
137  Bootstrap->ReportError("expected a single statement", F->getBody());
138  return NULL;
139  }
140 
141  auto Ret = dyn_cast<ReturnStmt>(Body->body_back());
142  if (!Ret) {
143  Bootstrap->ReportError("expected a return statement", Body->body_back());
144  return NULL;
145  }
146 
147  auto Call = dyn_cast<CallExpr>(Ret->getRetValue());
148  if (!Call || !Call->getDirectCallee()
149  || (Call->getDirectCallee()->getName() != AUTOMATON_USES)) {
150  Bootstrap->ReportError("expected call to " + AUTOMATON_USES, Ret);
151  return NULL;
152  }
153 
154  Expr* Args[4];
155  const size_t ArgCount = sizeof(Args) / sizeof(Args[0]);
156 
157  if (Call->getNumArgs() != ArgCount) {
158  Bootstrap->ReportError("expected automaton, locality, start, end", Call);
159  return NULL;
160  }
161 
162  for (size_t i = 0; i < ArgCount; i++)
163  Args[i] = Call->getArg(i)->IgnoreImplicit();
164 
165  auto Automaton = Bootstrap->ParseStringLiteral(Call->getArg(0));
166  if (Automaton.empty()) {
167  Bootstrap->ReportError("expected automaton name", Call->getArg(0));
168  return NULL;
169  }
170 
171  auto Locality = dyn_cast<DeclRefExpr>(Call->getArg(1)->IgnoreImplicit());
172  if (!Locality) {
173  Bootstrap->ReportError("expected TESLA locality", Call->getArg(1));
174  return NULL;
175  }
176 
177  auto Beginning = Call->getArg(2);
178  auto End = Call->getArg(3);
179 
180  Identifier ID;
181  ID.set_name(Automaton);
182 
184  if (!Bootstrap->Parse(&Context, Locality))
185  return NULL;
186 
187  Flags RootFlags;
188  RootFlags.FnInstrContext = FunctionEvent::Callee;
189 
190  return new Parser(Ctx, ID, Context, Beginning, End, NULL, RootFlags);
191 }

+ Here is the caller graph for this function:

bool tesla::Parser::Parse ( llvm::OwningPtr< AutomatonDescription > &  Descrip,
llvm::OwningPtr< Usage > &  Usage 
)

Parse the automaton and its usage.

Parameters
[out]Descripthe automaton description will be stored here
[out]Usagethe usage of the automaton will be stored here
Returns
true on success, false on failure

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