Skip to content

Commit 2824885

Browse files
committed
C++ front-end: various fixes and DEBUG
1 parent 2d70182 commit 2824885

File tree

3 files changed

+58
-4
lines changed

3 files changed

+58
-4
lines changed

src/ansi-c/scanner.l

+1-1
Original file line numberDiff line numberDiff line change
@@ -1458,7 +1458,7 @@ __decltype { if(PARSER.cpp98 &&
14581458
"_Atomic"{ws}"(" { // put back all but _Atomic
14591459
yyless(7);
14601460

1461-
if(!PARSER.cpp98 &&
1461+
if((!PARSER.cpp98 || PARSER.cpp11) &&
14621462
(PARSER.mode==configt::ansi_ct::flavourt::GCC ||
14631463
PARSER.mode==configt::ansi_ct::flavourt::CLANG ||
14641464
PARSER.mode==configt::ansi_ct::flavourt::ARM))

src/cpp/cpp_typecheck_template.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ Author: Daniel Kroening, [email protected]
2020
#include "cpp_type2name.h"
2121
#include "cpp_typecheck.h"
2222

23+
#include <iostream>
24+
2325
void cpp_typecheckt::salvage_default_arguments(
2426
const template_typet &old_type,
2527
template_typet &new_type)
@@ -714,6 +716,7 @@ cpp_scopet &cpp_typecheckt::typecheck_template_parameters(
714716
// put template parameters into this scope
715717
template_typet::template_parameterst &parameters=
716718
type.template_parameters();
719+
std::cerr << type.pretty() << std::endl;
717720

718721
unsigned anon_count=0;
719722

@@ -730,6 +733,7 @@ cpp_scopet &cpp_typecheckt::typecheck_template_parameters(
730733
cpp_declarator_convertert cpp_declarator_converter(*this);
731734

732735
// there must be _one_ declarator
736+
std::cerr << declaration.pretty() << std::endl;
733737
PRECONDITION(declaration.declarators().size() == 1);
734738

735739
cpp_declaratort &declarator=declaration.declarators().front();

src/cpp/parse.cpp

+53-3
Original file line numberDiff line numberDiff line change
@@ -778,7 +778,7 @@ bool Parser::isTypeSpecifier()
778778
t == TOK_CPROVER_BOOL || t == TOK_CLASS || t == TOK_STRUCT ||
779779
t == TOK_UNION || t == TOK_ENUM || t == TOK_INTERFACE ||
780780
t == TOK_TYPENAME || t == TOK_TYPEOF || t == TOK_DECLTYPE ||
781-
t == TOK_UNDERLYING_TYPE;
781+
t == TOK_UNDERLYING_TYPE || t == TOK_ATOMIC_TYPE_SPECIFIER;
782782
}
783783

784784
/*
@@ -1343,7 +1343,7 @@ bool Parser::rTempArgDeclaration(cpp_declarationt &declaration)
13431343
if(lex.get_token(tk1) != TOK_CLASS)
13441344
return false;
13451345

1346-
if(lex.LookAhead(0) == ',')
1346+
if(lex.LookAhead(0) == ',' || lex.LookAhead(0) == '>')
13471347
return true;
13481348

13491349
if(!is_identifier(lex.get_token(tk2)))
@@ -2502,6 +2502,17 @@ bool Parser::optAttribute(typet &t)
25022502
break;
25032503
}
25042504

2505+
case TOK_GCC_IDENTIFIER:
2506+
if(tk.text == "clang" && lex.LookAhead(0) == TOK_SCOPE)
2507+
{
2508+
exprt discarded;
2509+
if(!rExpression(discarded, false))
2510+
return false;
2511+
}
2512+
else
2513+
return false;
2514+
break;
2515+
25052516
default:
25062517
// TODO: way may wish to change this: GCC, Clang, Visual Studio merely
25072518
// warn when they see an attribute that they don't recognize
@@ -2737,8 +2748,34 @@ bool Parser::optIntegralTypeOrClassSpec(typet &p)
27372748

27382749
return true;
27392750
}
2751+
else if(t == TOK_ATOMIC_TYPE_SPECIFIER)
2752+
{
2753+
#ifdef DEBUG
2754+
std::cout << std::string(__indent, ' ')
2755+
<< "Parser::optIntegralTypeOrClassSpec 9\n";
2756+
#endif // DEBUG
2757+
cpp_tokent atomic_tk;
2758+
lex.get_token(atomic_tk);
2759+
2760+
cpp_tokent tk;
2761+
if(lex.get_token(tk)!='(')
2762+
return false;
2763+
2764+
// the argument is always a type
2765+
if(!rTypeSpecifier(p, false))
2766+
return false;
2767+
2768+
if(lex.get_token(tk)!=')')
2769+
return false;
2770+
2771+
return true;
2772+
}
27402773
else
27412774
{
2775+
#ifdef DEBUG
2776+
std::cout << std::string(__indent, ' ')
2777+
<< "Parser::optIntegralTypeOrClassSpec 10\n";
2778+
#endif // DEBUG
27422779
p.make_nil();
27432780
return true;
27442781
}
@@ -4549,6 +4586,9 @@ bool Parser::rEnumSpec(typet &spec)
45494586
spec.set(ID_C_class, true);
45504587
}
45514588

4589+
if(!optAttribute(spec))
4590+
return false;
4591+
45524592
if(lex.LookAhead(0)!='{' &&
45534593
lex.LookAhead(0)!=':')
45544594
{
@@ -7903,7 +7943,9 @@ std::optional<codet> Parser::rStatement()
79037943
if(!rUsing(cpp_using))
79047944
return {};
79057945

7906-
UNIMPLEMENTED;
7946+
codet statement(ID_cpp_using);
7947+
// UNIMPLEMENTED;
7948+
return std::move(statement);
79077949
}
79087950

79097951
case TOK_STATIC_ASSERT:
@@ -7920,6 +7962,14 @@ std::optional<codet> Parser::rStatement()
79207962
return std::move(statement);
79217963
}
79227964

7965+
case '[':
7966+
{
7967+
typet discard;
7968+
if(!optAttribute(discard))
7969+
return {};
7970+
return code_blockt{};
7971+
}
7972+
79237973
default:
79247974
return rExprStatement();
79257975
}

0 commit comments

Comments
 (0)