dtc: Sync with upstream commit 23387dd

Add the ability to parse char literals needed to compile DTBs currently
in base.

Reviewed by:	theraven, emaste
Approved by:	emaste (mentor)
Differential Revision:	https://reviews.freebsd.org/D42438
This commit is contained in:
Jose Luis Duran 2025-06-16 19:31:43 +00:00
parent 956100d60f
commit 4dfbc03d64
No known key found for this signature in database
GPG key ID: 5415E244477475CC
2 changed files with 75 additions and 0 deletions

View file

@ -337,6 +337,47 @@ input_buffer::consume(const char *str)
return false;
}
bool
input_buffer::consume_char_literal(unsigned long long &outInt)
{
outInt = (unsigned char)((*this)[0]);
cursor++;
if(outInt != '\\')
{
return true;
}
else if(cursor >= size)
{
return false;
}
outInt = (unsigned char)((*this)[0]);
cursor++;
switch (outInt) {
default:
return false;
case 'n':
outInt = (unsigned char)'\n';
break;
case 'r':
outInt = (unsigned char)'\r';
break;
case 't':
outInt = (unsigned char)'\t';
break;
case '0':
outInt = 0;
break;
case '\'':
case '\\':
break;
}
return true;
}
bool
input_buffer::consume_integer(unsigned long long &outInt)
{
@ -874,6 +915,18 @@ expression_ptr text_input_buffer::parse_expression(bool stopAtParen)
source_location l = location();
switch (*(*this))
{
case '\'':
consume('\'');
if(!consume_char_literal(leftVal))
{
return nullptr;
}
if (!consume('\''))
{
return nullptr;
}
lhs.reset(new terminal_expr(l, leftVal));
break;
case '0'...'9':
if (!consume_integer(leftVal))
{

View file

@ -193,6 +193,13 @@ class input_buffer
* current point in the input.
*/
bool consume(const char *str);
/**
* Reads unsigned from char literal. Returns true and advances
* the cursor to next char.
*
* The parsed value is returned via the argument.
*/
bool consume_char_literal(unsigned long long &outInt);
/**
* Reads an integer in base 8, 10, or 16. Returns true and advances
* the cursor to the end of the integer if the cursor points to an
@ -412,6 +419,21 @@ class text_input_buffer
}
return input_stack.top()->consume(str);
}
/**
* Converts next char into unsigned
*
* The parsed value is returned via the argument.
*
* This method does not scan between files.
*/
bool consume_char_literal(unsigned long long &outInt)
{
if (input_stack.empty())
{
return false;
}
return input_stack.top()->consume_char_literal(outInt);
}
/**
* Reads an integer in base 8, 10, or 16. Returns true and advances
* the cursor to the end of the integer if the cursor points to an