Newer
Older
/**************************************************************************/
/* */
/* This file is part of Frama-Clang */
/* */
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
/* CEA (Commissariat à l'énergie atomique et aux énergies */
/* alternatives) */
/* */
/* you can redistribute it and/or modify it under the terms of the GNU */
/* Lesser General Public License as published by the Free Software */
/* Foundation, version 2.1. */
/* */
/* It is distributed in the hope that it will be useful, */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
/* GNU Lesser General Public License for more details. */
/* */
/* See the GNU Lesser General Public License version 2.1 */
/* for more details (enclosed in the file LICENSE). */
/* */
/**************************************************************************/
//
// Description:
// Implementation of the ACSL++ components.
//
#include "ACSLComponent.h"
#include "Clang_utils.h"
#include "clang/AST/DeclTemplate.h"
#include <sstream>
#include <cstdio>
namespace Acsl {
using namespace DLexer;
Parser::ReadResult
Locations::readToken(Parser::State& state, Parser::Arguments& arguments) {
enum Delimiters { DBegin, DLocation, DNothing };
ReadResult result = RRNeedChars;
switch (state.point()) {
DefineParseCase(Begin) {
AbstractToken token = arguments.queryToken();
if (token.getType() == AbstractToken::TKeyword) {
if (((const KeywordToken&) token).getType() ==
KeywordToken::TNothing) {
if (_locations.getFront()) {
DefineAddError("\\nothing cannot be mixed with a list of lvalues")
DefineReduceAndParse
}
else DefineGotoCase(Nothing)
}
};
TermOrPredicate* term = new TermOrPredicate;
state.absorbRuleResult(&term->setTerm());
DefineShiftAndParse(Location,*term,&TermOrPredicate::readToken)
}
DefineParseCase(Location) {
Parser::State::RuleAccess::TCastFromRule<TermOrPredicate>
node(state.getRuleResult());
logic_type ltype = NULL;
term location = node->extractTermOrSet(arguments,ltype);
state.freeRuleResult();
if (!location) {
DefineAddError("expecting a location");
DefineReduceAndParse
}
_locations.insertContainer(location);
AbstractToken token = arguments.queryToken();
switch (token.getType()) {
case AbstractToken::TOperatorPunctuator:
{ OperatorPunctuatorToken::Type type =
((const OperatorPunctuatorToken&)token).getType();
if (type == OperatorPunctuatorToken::TComma) {
DefineGotoCase(Begin)
}
else DefineReduceAndParse
}
default: DefineReduceAndParse
}
}
DefineParseCase(Nothing) {
AbstractToken token = arguments.queryToken();
switch (token.getType()) {
case AbstractToken::TOperatorPunctuator: {
OperatorPunctuatorToken::Type type =
((const OperatorPunctuatorToken&)token).getType();
if (type == OperatorPunctuatorToken::TComma) {
DefineAddError("\\nothing cannot be mixed with a list of lvalues")
DefineReduceAndParse
} else DefineReduceAndParse
}
default: DefineReduceAndParse
}
}
default:
DefineAddError("internal error in parsing locations list")
}
return RRNeedChars;
}
Parser::ReadResult
AssignsClause::readToken(Parser::State& state, Parser::Arguments& arguments) {
enum Delimiters { DBegin, DLocation, DFrom, DEnd };
ReadResult result = RRNeedChars;
switch (state.point()) {
DefineInitParseCase(Begin) {
Locations* modified = new Locations(copy_loc(_loc));
state.absorbRuleResult(modified);
DefineShiftAndParse(Location,*modified,&Locations::readToken)
}
DefineParseCase(Location)
{ Parser::State::RuleAccess::TCastFromRule<Locations>
node(state.getRuleResult());
/*term*/ForwardList locations = node->getResult();
state.freeRuleResult();
AbstractToken token = arguments.queryToken();
switch (token.getType()) {
case AbstractToken::TOperatorPunctuator: {
OperatorPunctuatorToken::Type type =
((const OperatorPunctuatorToken&)token).getType();
if (type == OperatorPunctuatorToken::TSemiColon) {
list modified = locations.getFront();
while(modified) {
term loc = (term)modified->element.container;
_clause.insertContainer(from_cons(loc,deps_FromAny()));
modified = modified -> next;
}
DefineReduceAndParse
} else {
DefineAddError(
std::string("unexpected token '")
.append(token.str()).append("' after assigns clause"))
DefineReduceAndParse
}
}
case AbstractToken::TKeyword: {
KeywordToken::Type type = ((const KeywordToken &)token).getType();
if (type == KeywordToken::TFrom) {
if (locations.getFront()) {
_modified.append(locations);
DefineGotoCase(From)
} else {
DefineAddError(
"'assigns \nothing' cannot have a '\from' part")
DefineReduceAndParse
}
}
else {
DefineAddError(std::string("unexpected token '")
.append(token.str()).append("' after assigns clause"))
DefineReduceAndParse
}
}
default:
DefineAddError(std::string("unexpected token '").append(token.str())
.append("' after assigns clause"))
DefineReduceAndParse
}
}
DefineParseCase(From) {
Locations* froms =
new Locations(arguments.newTokenLocation());
state.absorbRuleResult(froms);
DefineShiftAndParse(End,*froms,&Locations::readToken)
}
DefineParseCase(End) {
Parser::State::RuleAccess::TCastFromRule<Locations>
node(state.getRuleResult());
/*term*/ForwardList locations = node->getResult();
state.freeRuleResult();
/*term*/list assigned = _modified.getFront();
deps from = deps_From(locations.getFront());
while (assigned) {
term location = (term)assigned->element.container;
_clause.insertContainer(from_cons(term_dup(location),deps_dup(from)));
assigned = assigned->next;
}
DefineReduceAndParse
}
default:
DefineAddError("internal error in parsing assigns clause")
}
return RRNeedChars;
}
Parser::ReadResult
AllocFreeClause::readToken(
Parser::State& state, Parser::Arguments& arguments) {
enum Delimiters { DBegin, DEnd };
ReadResult result = RRNeedChars;
switch (state.point()) {
DefineInitParseCase(Begin) {
Locations* alloc = new Locations(copy_loc(_loc));
state.absorbRuleResult(alloc);
DefineShiftAndParse(End,*alloc,&Locations::readToken)
}
DefineParseCase(End) {
Parser::State::RuleAccess::TCastFromRule<Locations>
node(state.getRuleResult());
/*term*/ForwardList locations = node->getResult();
state.freeRuleResult();
_clause = _clause.append(locations);
DefineReduceAndParse
}
default:
DefineAddError("internal error in parsing frees/allocates clause")
}
return RRNeedChars;
}
} // end of namespace Acsl