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
/* 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 code annotations, like an assert.
//
#include "ACSLCodeAnnotation.h"
namespace Acsl {
using namespace DLexer;
Parser::ReadResult
CodeAnnotation::readToken(Parser::State& state, Parser::Arguments& arguments)
{ enum Delimiters
{ DBegin, DAssert, DForId, DAfterForId, DEnd };
ReadResult result = RRNeedChars;
switch (state.point()) {
DefineParseCase(Begin)
arguments.setCodeAnnotContext();
// Logic label Pre, Here and Old are always present,
// Post only exists in post-condition, assigns and allocates
arguments.addLogicLabel("Pre");
arguments.addLogicLabel("Here");
arguments.addLogicLabel("Old");
{ AbstractToken token = arguments.queryToken();
if (token.getType() == AbstractToken::TKeyword) {
KeywordToken::Type type = ((const KeywordToken&) token).getType();
if (type == KeywordToken::TAssert) {
TermOrPredicate* pred = new TermOrPredicate;
state.absorbRuleResult(&pred->setPredicate());
{ logic_type thisRecordType = arguments.queryThisType();
if (thisRecordType)
arguments.addLogicFormal("this", thisRecordType);
}
DefineShift(Assert, *pred, &TermOrPredicate::readToken)
}
if (type == KeywordToken::TFor) {
if (_behaviors)
DefineAddError("multiple 'for' behaviors in code annotation")
DefineGotoCase(ForId)
}
};
}
arguments.resetAnnotContext();
DefineAddError("expecting 'assert' or 'for' in code annotation")
DefineGotoCaseAndParse(End)
DefineParseCase(Assert)
{ Parser::State::RuleAccess::TCastFromRule<TermOrPredicate>
rule(state.getRuleResult());
predicate_named pred = rule->extractPredicate(arguments);
state.freeRuleResult();
if (pred) {
_annotResult = code_annotation_Assert(_behaviors, pred);
_behaviors = NULL;
_behaviorAdder.clear();
}
else {
arguments.resetAnnotContext();
DefineAddError("expecting a predicate");
}
}
DefineGotoCaseAndParse(End)
DefineParseCase(ForId)
if (arguments.queryToken().getType() == AbstractToken::TIdentifier) {
const IdentifierToken& token
= (const IdentifierToken&) arguments.getContentToken();
_behaviorAdder.insertContainer(strdup(token.content().c_str()));
DefineGotoCase(AfterForId)
}
if (arguments.queryToken().getType() == AbstractToken::TKeyword) {
const KeywordToken& token
= (const KeywordToken&) arguments.getContentToken();
_behaviorAdder.insertContainer(strdup(token.text().c_str()));
DefineGotoCase(AfterForId)
}
arguments.resetAnnotContext();
DefineAddError("expecting identifier after 'for' in code annotation")
DefineGotoCaseAndParse(End)
DefineParseCase(AfterForId)
{ AbstractToken token = arguments.queryToken();
if (token.getType() == AbstractToken::TOperatorPunctuator) {
OperatorPunctuatorToken::Type
type = ((const OperatorPunctuatorToken&) token).getType();
if (type == OperatorPunctuatorToken::TComma)
DefineGotoCase(ForId)
if (type == OperatorPunctuatorToken::TColon)
DefineGotoCase(Begin)
};
}
arguments.resetAnnotContext();
DefineAddError("expecting ',' or ':' in a code annotation")
DefineGotoCaseAndParse(End)
DefineParseCase(End)
{ AbstractToken token = arguments.queryToken();
if (token.getType() == AbstractToken::TOperatorPunctuator) {
OperatorPunctuatorToken::Type
type = ((const OperatorPunctuatorToken&) token).getType();
if (type == OperatorPunctuatorToken::TSemiColon) {
arguments.resetAnnotContext();
DefineReduce
}
};
}
arguments.resetAnnotContext();
DefineAddError("expecting ';' at the end of a code annotation")
DefineGotoCase(End)
}
return result;
}
} // end of namespace Acsl