Skip to content

Commit 0cc696b

Browse files
author
Daniel Kroening
committed
introduced ID_frontend_pointer
1 parent cc63551 commit 0cc696b

8 files changed

+44
-23
lines changed

src/ansi-c/ansi_c_convert_type.cpp

+11-4
Original file line numberDiff line numberDiff line change
@@ -216,13 +216,20 @@ void ansi_c_convert_typet::read_rec(const typet &type)
216216
{
217217
c_storage_spec.alias=type.subtype().get(ID_value);
218218
}
219-
else if(type.id()==ID_pointer)
219+
else if(type.id()==ID_frontend_pointer)
220220
{
221-
// pointers have a width, much like integers
222-
pointer_typet tmp=to_pointer_type(type);
223-
tmp.set_width(config.ansi_c.pointer_width);
221+
// We turn ID_frontend_pointer to ID_pointer
222+
// Pointers have a width, much like integers,
223+
// which is added here.
224+
typet tmp(type);
225+
tmp.id(ID_pointer);
226+
tmp.set(ID_width, config.ansi_c.pointer_width);
224227
other.push_back(tmp);
225228
}
229+
else if(type.id()==ID_pointer)
230+
{
231+
UNREACHABLE;
232+
}
226233
else
227234
other.push_back(type);
228235
}

src/ansi-c/ansi_c_declaration.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ typet ansi_c_declarationt::full_type(
9898
// this gets types that are still raw parse trees
9999
while(p->is_not_nil())
100100
{
101-
if(p->id()==ID_pointer || p->id()==ID_array ||
101+
if(p->id()==ID_frontend_pointer || p->id()==ID_array ||
102102
p->id()==ID_vector || p->id()==ID_c_bit_field ||
103103
p->id()==ID_block_pointer || p->id()==ID_code)
104104
p=&p->subtype();

src/ansi-c/parser.y

+7-7
Original file line numberDiff line numberDiff line change
@@ -3067,7 +3067,7 @@ unary_identifier_declarator:
30673067
// and not the identifier_declarator
30683068
// The below is deliberately not using pointer_type();
30693069
// the width is added during conversion.
3070-
stack_type($1).id(ID_pointer);
3070+
stack_type($1).id(ID_frontend_pointer);
30713071
stack_type($1).subtype()=typet(ID_abstract);
30723072
$2=merge($2, $1); // dest=$2
30733073
make_subtype($3, $2); // dest=$3
@@ -3254,7 +3254,7 @@ unary_abstract_declarator:
32543254
$$=$1;
32553255
// The below is deliberately not using pointer_type();
32563256
// the width is added during conversion.
3257-
stack_type($$).id(ID_pointer);
3257+
stack_type($$).id(ID_frontend_pointer);
32583258
stack_type($$).subtype()=typet(ID_abstract);
32593259
}
32603260
| '*' attribute_type_qualifier_list
@@ -3263,7 +3263,7 @@ unary_abstract_declarator:
32633263
// not to the (missing) abstract declarator.
32643264
// The below is deliberately not using pointer_type();
32653265
// the width is added during conversion.
3266-
stack_type($1).id(ID_pointer);
3266+
stack_type($1).id(ID_frontend_pointer);
32673267
stack_type($1).subtype()=typet(ID_abstract);
32683268
$$=merge($2, $1);
32693269
}
@@ -3278,7 +3278,7 @@ unary_abstract_declarator:
32783278
// not to the abstract declarator.
32793279
// The below is deliberately not using pointer_type();
32803280
// the width is added during conversion.
3281-
stack_type($1).id(ID_pointer);
3281+
stack_type($1).id(ID_frontend_pointer);
32823282
stack_type($1).subtype()=typet(ID_abstract);
32833283
$2=merge($2, $1); // dest=$2
32843284
make_subtype($3, $2); // dest=$3
@@ -3300,7 +3300,7 @@ parameter_unary_abstract_declarator:
33003300
$$=$1;
33013301
// The below is deliberately not using pointer_type();
33023302
// the width is added during conversion.
3303-
stack_type($$).id(ID_pointer);
3303+
stack_type($$).id(ID_frontend_pointer);
33043304
stack_type($$).subtype()=typet(ID_abstract);
33053305
}
33063306
| '*' attribute_type_qualifier_list
@@ -3309,7 +3309,7 @@ parameter_unary_abstract_declarator:
33093309
// not to the (missing) abstract declarator.
33103310
// The below is deliberately not using pointer_type();
33113311
// the width is added during conversion.
3312-
stack_type($1).id(ID_pointer);
3312+
stack_type($1).id(ID_frontend_pointer);
33133313
stack_type($1).subtype()=typet(ID_abstract);
33143314
$$=merge($2, $1);
33153315
}
@@ -3324,7 +3324,7 @@ parameter_unary_abstract_declarator:
33243324
// not to the (missing) abstract declarator.
33253325
// The below is deliberately not using pointer_type();
33263326
// the width is added during conversion.
3327-
stack_type($1).id(ID_pointer);
3327+
stack_type($1).id(ID_frontend_pointer);
33283328
stack_type($1).subtype()=typet(ID_abstract);
33293329
$2=merge($2, $1); // dest=$2
33303330
make_subtype($3, $2); // dest=$3

src/ansi-c/parser_static.inc

+3-3
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ static void make_subtype(typet &dest, typet &src)
187187
#endif
188188

189189
assert(src.id()==ID_array ||
190-
src.id()==ID_pointer ||
190+
src.id()==ID_frontend_pointer ||
191191
src.id()==ID_code ||
192192
src.id()==ID_merged_type ||
193193
src.id()==ID_abstract ||
@@ -207,7 +207,7 @@ static void make_subtype(typet &dest, typet &src)
207207
sub=&(p->subtypes().back());
208208
}
209209

210-
if(sub->id()==ID_pointer ||
210+
if(sub->id()==ID_frontend_pointer ||
211211
sub->id()==ID_array ||
212212
sub->id()==ID_code)
213213
{
@@ -292,7 +292,7 @@ static void make_pointer(const YYSTYPE dest)
292292
{
293293
// The below deliberately avoids pointer_type().
294294
// The width is set during conversion.
295-
stack_type(dest).id(ID_pointer);
295+
stack_type(dest).id(ID_frontend_pointer);
296296
stack_type(dest).subtype()=typet(ID_abstract);
297297
}
298298

src/cpp/cpp_convert_type.cpp

+13-1
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,19 @@ void cpp_convert_typet::read_rec(const typet &type)
159159
tmp.id(ID_empty);
160160
other.push_back(tmp);
161161
}
162+
else if(type.id()==ID_frontend_pointer)
163+
{
164+
// add width and turn into ID_pointer
165+
typet tmp=type;
166+
tmp.id(ID_pointer);
167+
tmp.set(ID_width, config.ansi_c.pointer_width);
168+
other.push_back(tmp);
169+
}
170+
else if(type.id()==ID_pointer)
171+
{
172+
// ignore, we unfortunately convert multiple times
173+
other.push_back(type);
174+
}
162175
else
163176
{
164177
other.push_back(type);
@@ -549,7 +562,6 @@ void cpp_convert_plain_type(typet &type)
549562
if(type.id()==ID_cpp_name ||
550563
type.id()==ID_struct ||
551564
type.id()==ID_union ||
552-
type.id()==ID_pointer ||
553565
type.id()==ID_array ||
554566
type.id()==ID_code ||
555567
type.id()==ID_unsignedbv ||

src/cpp/cpp_convert_type.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@ Author: Daniel Kroening, [email protected]
1414

1515
#include <util/type.h>
1616

17-
void cpp_convert_plain_type(typet &type);
17+
void cpp_convert_plain_type(typet &);
1818

1919
#endif // CPROVER_CPP_CPP_CONVERT_TYPE_H

src/cpp/parse.cpp

+7-6
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ Author: Daniel Kroening, [email protected]
2020
#include <util/std_types.h>
2121

2222
#include <ansi-c/ansi_c_y.tab.h>
23+
#include <util/c_types.h>
2324

2425
#include "cpp_token_buffer.h"
2526
#include "cpp_member_spec.h"
@@ -3015,7 +3016,7 @@ bool Parser::optPtrOperator(typet &ptrs)
30153016

30163017
if(t=='*')
30173018
{
3018-
typet op(ID_pointer); // width gets set during conversion
3019+
typet op(ID_frontend_pointer); // width gets set during conversion
30193020
cpp_tokent tk;
30203021
lex.get_token(tk);
30213022
set_location(op, tk);
@@ -3078,7 +3079,7 @@ bool Parser::optPtrOperator(typet &ptrs)
30783079
{
30793080
cpp_tokent tk;
30803081
lex.get_token(tk);
3081-
typet op(ID_pointer); // width gets set during conversion
3082+
typet op(ID_frontend_pointer); // width gets set during conversion
30823083
op.set(ID_C_reference, true);
30833084
set_location(op, tk);
30843085
t_list.push_front(op);
@@ -3087,7 +3088,7 @@ bool Parser::optPtrOperator(typet &ptrs)
30873088
{
30883089
cpp_tokent tk;
30893090
lex.get_token(tk);
3090-
typet op(ID_pointer); // width gets set during conversion
3091+
typet op(ID_frontend_pointer); // width gets set during conversion
30913092
op.set(ID_C_rvalue_reference, true);
30923093
set_location(op, tk);
30933094
t_list.push_front(op);
@@ -3530,7 +3531,7 @@ bool Parser::rPtrToMember(irept &ptr_to_mem)
35303531
std::cout << std::string(__indent, ' ') << "Parser::rPtrToMember 0\n";
35313532
#endif
35323533

3533-
typet ptm(ID_pointer); // width gets set during conversion
3534+
typet ptm(ID_frontend_pointer); // width gets set during conversion
35343535
irept &name = ptm.add("to-member");
35353536
name=cpp_namet();
35363537
irept::subt &components=name.get_sub();
@@ -6477,8 +6478,8 @@ bool Parser::rPrimaryExpr(exprt &exp)
64776478

64786479
case TOK_NULLPTR:
64796480
lex.get_token(tk);
6480-
// width of pointer gets done during conversion
6481-
exp=constant_exprt(ID_NULL, typet(ID_pointer, typet(ID_nullptr)));
6481+
// as an exception, we set the width of pointer
6482+
exp=constant_exprt(ID_NULL, pointer_type(typet(ID_nullptr)));
64826483
set_location(exp, tk);
64836484
#ifdef DEBUG
64846485
std::cout << std::string(__indent, ' ') << "Parser::rPrimaryExpr 6\n";

src/util/irep_ids.def

+1
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ IREP_ID_ONE(skip)
104104
IREP_ID_ONE(arguments)
105105
IREP_ID_ONE(array)
106106
IREP_ID_ONE(size)
107+
IREP_ID_ONE(frontend_pointer)
107108
IREP_ID_ONE(pointer)
108109
IREP_ID_ONE(block_pointer)
109110
IREP_ID_ONE(switch)

0 commit comments

Comments
 (0)