 |
|
 |
|
| Files: |
1 |
|
Branches Taken: |
87.1% |
54 / 62 |
| Generated: |
2010-02-10 01:31 |
|
Branches Executed: |
100.0% |
62 / 62 |
| |
|
Line Coverage: |
97.2% |
105 / 108 |
| |
 |
|
 |
1 : //===--- ParsePragma.cpp - Language specific pragma parsing ---------------===//
2 : //
3 : // The LLVM Compiler Infrastructure
4 : //
5 : // This file is distributed under the University of Illinois Open Source
6 : // License. See LICENSE.TXT for details.
7 : //
8 : //===----------------------------------------------------------------------===//
9 : //
10 : // This file implements the language specific #pragma handlers.
11 : //
12 : //===----------------------------------------------------------------------===//
13 :
14 : #include "ParsePragma.h"
15 : #include "clang/Parse/ParseDiagnostic.h"
16 : #include "clang/Lex/Preprocessor.h"
17 : #include "clang/Parse/Action.h"
18 : #include "clang/Parse/Parser.h"
19 : using namespace clang;
20 :
21 : // #pragma pack(...) comes in the following delicious flavors:
22 : // pack '(' [integer] ')'
23 : // pack '(' 'show' ')'
24 : // pack '(' ('push' | 'pop') [',' identifier] [, integer] ')'
25 72: void PragmaPackHandler::HandlePragma(Preprocessor &PP, Token &PackTok) {
26 : // FIXME: Should we be expanding macros here? My guess is no.
27 72: SourceLocation PackLoc = PackTok.getLocation();
28 :
29 72: Token Tok;
30 72: PP.Lex(Tok);
1: branch 1 taken
71: branch 2 taken
31 72: if (Tok.isNot(tok::l_paren)) {
32 1: PP.Diag(Tok.getLocation(), diag::warn_pragma_expected_lparen) << "pack";
33 1: return;
34 : }
35 :
36 71: Action::PragmaPackKind Kind = Action::PPK_Default;
37 71: IdentifierInfo *Name = 0;
38 71: Action::OwningExprResult Alignment(Actions);
39 71: SourceLocation LParenLoc = Tok.getLocation();
40 71: PP.Lex(Tok);
13: branch 1 taken
58: branch 2 taken
41 71: if (Tok.is(tok::numeric_constant)) {
42 13: Alignment = Actions.ActOnNumericConstant(Tok);
0: branch 1 not taken
13: branch 2 taken
43 13: if (Alignment.isInvalid())
44 12: return;
45 :
46 13: PP.Lex(Tok);
54: branch 1 taken
4: branch 2 taken
47 58: } else if (Tok.is(tok::identifier)) {
48 54: const IdentifierInfo *II = Tok.getIdentifierInfo();
10: branch 1 taken
44: branch 2 taken
49 54: if (II->isStr("show")) {
50 10: Kind = Action::PPK_Show;
51 10: PP.Lex(Tok);
52 : } else {
29: branch 1 taken
15: branch 2 taken
53 44: if (II->isStr("push")) {
54 29: Kind = Action::PPK_Push;
14: branch 1 taken
1: branch 2 taken
55 15: } else if (II->isStr("pop")) {
56 14: Kind = Action::PPK_Pop;
57 : } else {
58 1: PP.Diag(Tok.getLocation(), diag::warn_pragma_pack_invalid_action);
59 : return;
60 : }
61 43: PP.Lex(Tok);
62 :
27: branch 1 taken
16: branch 2 taken
63 43: if (Tok.is(tok::comma)) {
64 27: PP.Lex(Tok);
65 :
15: branch 1 taken
12: branch 2 taken
66 27: if (Tok.is(tok::numeric_constant)) {
67 15: Alignment = Actions.ActOnNumericConstant(Tok);
0: branch 1 not taken
15: branch 2 taken
68 15: if (Alignment.isInvalid())
69 : return;
70 :
71 15: PP.Lex(Tok);
8: branch 1 taken
4: branch 2 taken
72 12: } else if (Tok.is(tok::identifier)) {
73 8: Name = Tok.getIdentifierInfo();
74 8: PP.Lex(Tok);
75 :
6: branch 1 taken
2: branch 2 taken
76 8: if (Tok.is(tok::comma)) {
77 6: PP.Lex(Tok);
78 :
3: branch 1 taken
3: branch 2 taken
79 6: if (Tok.isNot(tok::numeric_constant)) {
80 3: PP.Diag(Tok.getLocation(), diag::warn_pragma_pack_malformed);
81 : return;
82 : }
83 :
84 3: Alignment = Actions.ActOnNumericConstant(Tok);
0: branch 1 not taken
3: branch 2 taken
85 3: if (Alignment.isInvalid())
86 : return;
87 :
88 3: PP.Lex(Tok);
89 : }
90 : } else {
91 4: PP.Diag(Tok.getLocation(), diag::warn_pragma_pack_malformed);
92 : return;
93 : }
94 : }
95 : }
96 : }
97 :
4: branch 1 taken
59: branch 2 taken
98 63: if (Tok.isNot(tok::r_paren)) {
99 4: PP.Diag(Tok.getLocation(), diag::warn_pragma_expected_rparen) << "pack";
100 : return;
101 : }
102 :
103 59: PP.Lex(Tok);
0: branch 1 not taken
59: branch 2 taken
104 59: if (Tok.isNot(tok::eom)) {
105 0: PP.Diag(Tok.getLocation(), diag::warn_pragma_extra_tokens_at_eol) << "pack";
106 : return;
107 : }
108 :
109 59: SourceLocation RParenLoc = Tok.getLocation();
110 : Actions.ActOnPragmaPack(Kind, Name, Alignment.release(), PackLoc,
59: branch 3 taken
12: branch 4 taken
111 59: LParenLoc, RParenLoc);
112 : }
113 :
114 : // #pragma unused(identifier)
115 15: void PragmaUnusedHandler::HandlePragma(Preprocessor &PP, Token &UnusedTok) {
116 : // FIXME: Should we be expanding macros here? My guess is no.
117 15: SourceLocation UnusedLoc = UnusedTok.getLocation();
118 :
119 : // Lex the left '('.
120 15: Token Tok;
121 15: PP.Lex(Tok);
1: branch 1 taken
14: branch 2 taken
122 15: if (Tok.isNot(tok::l_paren)) {
123 1: PP.Diag(Tok.getLocation(), diag::warn_pragma_expected_lparen) << "unused";
124 1: return;
125 : }
126 14: SourceLocation LParenLoc = Tok.getLocation();
127 :
128 : // Lex the declaration reference(s).
129 14: llvm::SmallVector<Token, 5> Identifiers;
130 14: SourceLocation RParenLoc;
131 14: bool LexID = true;
132 :
133 19: while (true) {
134 33: PP.Lex(Tok);
135 :
18: branch 0 taken
15: branch 1 taken
136 33: if (LexID) {
15: branch 1 taken
3: branch 2 taken
137 18: if (Tok.is(tok::identifier)) {
138 15: Identifiers.push_back(Tok);
139 15: LexID = false;
140 15: continue;
141 : }
142 :
143 : // Illegal token!
144 3: PP.Diag(Tok.getLocation(), diag::warn_pragma_unused_expected_var);
145 3: return;
146 : }
147 :
148 : // We are execting a ')' or a ','.
4: branch 1 taken
11: branch 2 taken
149 15: if (Tok.is(tok::comma)) {
150 4: LexID = true;
151 4: continue;
152 : }
153 :
11: branch 1 taken
0: branch 2 not taken
154 11: if (Tok.is(tok::r_paren)) {
155 11: RParenLoc = Tok.getLocation();
156 : break;
157 : }
158 :
159 : // Illegal token!
160 0: PP.Diag(Tok.getLocation(), diag::warn_pragma_unused_expected_punc);
161 : return;
162 : }
163 :
164 11: PP.Lex(Tok);
0: branch 1 not taken
11: branch 2 taken
165 11: if (Tok.isNot(tok::eom)) {
166 : PP.Diag(Tok.getLocation(), diag::warn_pragma_extra_tokens_at_eol) <<
167 0: "unused";
168 : return;
169 : }
170 :
171 : // Verify that we have a location for the right parenthesis.
11: branch 1 taken
0: branch 2 not taken
172 11: assert(RParenLoc.isValid() && "Valid '#pragma unused' must have ')'");
11: branch 1 taken
0: branch 2 not taken
173 11: assert(!Identifiers.empty() && "Valid '#pragma unused' must have arguments");
174 :
175 : // Perform the action to handle the pragma.
176 : Actions.ActOnPragmaUnused(Identifiers.data(), Identifiers.size(),
11: branch 4 taken
3: branch 5 taken
177 25: parser.CurScope, UnusedLoc, LParenLoc, RParenLoc);
178 : }
179 :
180 : // #pragma weak identifier
181 : // #pragma weak identifier '=' identifier
182 33: void PragmaWeakHandler::HandlePragma(Preprocessor &PP, Token &WeakTok) {
183 : // FIXME: Should we be expanding macros here? My guess is no.
184 33: SourceLocation WeakLoc = WeakTok.getLocation();
185 :
186 33: Token Tok;
187 33: PP.Lex(Tok);
1: branch 1 taken
32: branch 2 taken
188 33: if (Tok.isNot(tok::identifier)) {
189 1: PP.Diag(Tok.getLocation(), diag::warn_pragma_expected_identifier) << "weak";
190 1: return;
191 : }
192 :
193 32: IdentifierInfo *WeakName = Tok.getIdentifierInfo(), *AliasName = 0;
194 32: SourceLocation WeakNameLoc = Tok.getLocation(), AliasNameLoc;
195 :
196 32: PP.Lex(Tok);
22: branch 1 taken
10: branch 2 taken
197 32: if (Tok.is(tok::equal)) {
198 22: PP.Lex(Tok);
2: branch 1 taken
20: branch 2 taken
199 22: if (Tok.isNot(tok::identifier)) {
200 : PP.Diag(Tok.getLocation(), diag::warn_pragma_expected_identifier)
201 2: << "weak";
202 2: return;
203 : }
204 20: AliasName = Tok.getIdentifierInfo();
205 20: AliasNameLoc = Tok.getLocation();
206 20: PP.Lex(Tok);
207 : }
208 :
2: branch 1 taken
28: branch 2 taken
209 30: if (Tok.isNot(tok::eom)) {
210 2: PP.Diag(Tok.getLocation(), diag::warn_pragma_extra_tokens_at_eol) << "weak";
211 2: return;
212 : }
213 :
19: branch 0 taken
9: branch 1 taken
214 28: if (AliasName) {
215 : Actions.ActOnPragmaWeakAlias(WeakName, AliasName, WeakLoc, WeakNameLoc,
216 19: AliasNameLoc);
217 : } else {
218 9: Actions.ActOnPragmaWeakID(WeakName, WeakLoc, WeakNameLoc);
219 : }
220 : }
Generated: 2010-02-10 01:31 by zcov