ref: b043794874408ea4331d53ba978ad8cb5c0efe4e
parent: 67dd2d72eacab11d263530d495d0019168ea9d6e
author: Roberto E. Vargas Caballero <[email protected]>
date: Fri Oct 4 10:10:23 EDT 2013
Allow mixed declarations and code c99 allow mix declarations and code, but c89 no. This patch adds this feature with a customizable warning.
--- a/cc.h
+++ b/cc.h
@@ -11,6 +11,7 @@
struct user_opt {
unsigned char implicit;
unsigned char c99;
+ unsigned char mixdcls;
unsigned char useless;
unsigned char repeat;
unsigned char charsign;
--- a/flow.c
+++ b/flow.c
@@ -2,6 +2,7 @@
#include <assert.h>
#include <stdio.h>
+#include "cc.h"
#include "symbol.h"
#include "tokens.h"
#include "syntax.h"
@@ -234,13 +235,22 @@
compound(void)
{
register struct node *lp = nodecomp(), *np;
+ unsigned char nodecl = 0;
expect('{');
new_ctx();
- while (np = decl())
+ while (!accept('}')) {
+ if (np = decl()) {
+ if (nodecl) {
+ warn(options.mixdcls,
+ "mixed declarations and code");
+ }
+ } else {
+ np = stmt();
+ nodecl = 1;
+ }
addstmt(lp, np);
- while (!accept('}'))
- addstmt(lp, stmt());
+ }
del_ctx();
return lp;