Minor style adjustments
This commit is contained in:
23
ASTNode.h
23
ASTNode.h
@@ -614,21 +614,21 @@ private:
|
||||
|
||||
class ASTFormattedValue : public ASTNode {
|
||||
public:
|
||||
static const char* F_STRING_QUOTE;
|
||||
enum ConversionFlag {
|
||||
NONE=0,
|
||||
STR=1,
|
||||
REPR=2,
|
||||
ASCII=3,
|
||||
FMTSPEC=4
|
||||
NONE = 0,
|
||||
STR = 1,
|
||||
REPR = 2,
|
||||
ASCII = 3,
|
||||
FMTSPEC = 4
|
||||
};
|
||||
|
||||
ASTFormattedValue(PycRef<ASTNode> val, ConversionFlag conversion, PycRef<ASTNode> format_spec)
|
||||
ASTFormattedValue(PycRef<ASTNode> val, ConversionFlag conversion,
|
||||
PycRef<ASTNode> format_spec)
|
||||
: ASTNode(NODE_FORMATTEDVALUE),
|
||||
m_val(std::move(val)),
|
||||
m_conversion(conversion),
|
||||
m_format_spec(std::move(format_spec))
|
||||
{}
|
||||
m_val(std::move(val)),
|
||||
m_conversion(conversion),
|
||||
m_format_spec(std::move(format_spec))
|
||||
{ }
|
||||
|
||||
PycRef<ASTNode> val() const { return m_val; }
|
||||
ConversionFlag conversion() const { return m_conversion; }
|
||||
@@ -654,5 +654,4 @@ private:
|
||||
value_t m_values;
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
|
18
ASTree.cpp
18
ASTree.cpp
@@ -10,7 +10,7 @@
|
||||
// E.g. f'{"interpolated "123' literal"}' -> invalid, unescaped quotes in literal.
|
||||
// E.g. f'{"interpolated \"123\' literal"}' -> invalid, f-string expression does not allow backslash.
|
||||
// NOTE: Nested f-strings not supported.
|
||||
const char* F_STRING_QUOTE = "'''";
|
||||
#define F_STRING_QUOTE "'''"
|
||||
|
||||
/* Use this to determine if an error occurred (and therefore, if we should
|
||||
* avoid cleaning the output tree) */
|
||||
@@ -804,8 +804,7 @@ PycRef<ASTNode> BuildFromCode(PycRef<PycCode> code, PycModule* mod)
|
||||
case Pyc::FORMAT_VALUE_A:
|
||||
{
|
||||
auto conversion_flag = static_cast<ASTFormattedValue::ConversionFlag>(operand);
|
||||
switch (conversion_flag)
|
||||
{
|
||||
switch (conversion_flag) {
|
||||
case ASTFormattedValue::ConversionFlag::NONE:
|
||||
case ASTFormattedValue::ConversionFlag::STR:
|
||||
case ASTFormattedValue::ConversionFlag::REPR:
|
||||
@@ -2330,8 +2329,7 @@ void print_formatted_value(PycRef<ASTFormattedValue> formatted_value, PycModule*
|
||||
fputs("{", pyc_output);
|
||||
print_src(formatted_value->val(), mod);
|
||||
|
||||
switch (formatted_value->conversion())
|
||||
{
|
||||
switch (formatted_value->conversion()) {
|
||||
case ASTFormattedValue::ConversionFlag::NONE:
|
||||
break;
|
||||
case ASTFormattedValue::ConversionFlag::STR:
|
||||
@@ -2443,16 +2441,14 @@ void print_src(PycRef<ASTNode> node, PycModule* mod)
|
||||
}
|
||||
break;
|
||||
case ASTNode::NODE_FORMATTEDVALUE:
|
||||
fprintf(pyc_output, "f%s", F_STRING_QUOTE);
|
||||
fputs("f" F_STRING_QUOTE, pyc_output);
|
||||
print_formatted_value(node.cast<ASTFormattedValue>(), mod);
|
||||
fputs(F_STRING_QUOTE, pyc_output);
|
||||
break;
|
||||
case ASTNode::NODE_JOINEDSTR:
|
||||
fprintf(pyc_output, "f%s", F_STRING_QUOTE);
|
||||
for (const auto& val : node.cast<ASTJoinedStr>()->values())
|
||||
{
|
||||
switch (val.type())
|
||||
{
|
||||
fputs("f" F_STRING_QUOTE, pyc_output);
|
||||
for (const auto& val : node.cast<ASTJoinedStr>()->values()) {
|
||||
switch (val.type()) {
|
||||
case ASTNode::NODE_FORMATTEDVALUE:
|
||||
print_formatted_value(val.cast<ASTFormattedValue>(), mod);
|
||||
break;
|
||||
|
@@ -156,10 +156,12 @@ void print_const(PycRef<PycObject> obj, PycModule* mod, const char* parent_f_str
|
||||
|
||||
switch (obj->type()) {
|
||||
case PycObject::TYPE_STRING:
|
||||
OutputString(obj.cast<PycString>(), mod->strIsUnicode() ? 'b' : 0, false, pyc_output, parent_f_string_quote);
|
||||
OutputString(obj.cast<PycString>(), mod->strIsUnicode() ? 'b' : 0,
|
||||
false, pyc_output, parent_f_string_quote);
|
||||
break;
|
||||
case PycObject::TYPE_UNICODE:
|
||||
OutputString(obj.cast<PycString>(), mod->strIsUnicode() ? 0 : 'u', false, pyc_output, parent_f_string_quote);
|
||||
OutputString(obj.cast<PycString>(), mod->strIsUnicode() ? 0 : 'u',
|
||||
false, pyc_output, parent_f_string_quote);
|
||||
break;
|
||||
case PycObject::TYPE_STRINGREF:
|
||||
case PycObject::TYPE_INTERNED:
|
||||
@@ -170,7 +172,8 @@ void print_const(PycRef<PycObject> obj, PycModule* mod, const char* parent_f_str
|
||||
if (mod->majorVer() >= 3)
|
||||
OutputString(obj.cast<PycString>(), 0, false, pyc_output, parent_f_string_quote);
|
||||
else
|
||||
OutputString(obj.cast<PycString>(), mod->strIsUnicode() ? 'b' : 0, false, pyc_output, parent_f_string_quote);
|
||||
OutputString(obj.cast<PycString>(), mod->strIsUnicode() ? 'b' : 0,
|
||||
false, pyc_output, parent_f_string_quote);
|
||||
break;
|
||||
case PycObject::TYPE_TUPLE:
|
||||
case PycObject::TYPE_SMALL_TUPLE:
|
||||
|
@@ -103,15 +103,13 @@ void OutputString(PycRef<PycString> str, char prefix, bool triple, FILE* F, cons
|
||||
while (len--) {
|
||||
if (*ch == '\'') {
|
||||
useQuotes = true;
|
||||
}
|
||||
else if (*ch == '"') {
|
||||
} else if (*ch == '"') {
|
||||
useQuotes = false;
|
||||
break;
|
||||
}
|
||||
ch++;
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
useQuotes = parent_f_string_quote[0] == '"';
|
||||
}
|
||||
ch = str->value();
|
||||
|
@@ -32,6 +32,6 @@ private:
|
||||
};
|
||||
|
||||
void OutputString(PycRef<PycString> str, char prefix = 0, bool triple = false,
|
||||
FILE* F = pyc_output, const char* parent_f_string_quote = nullptr);
|
||||
FILE* F = pyc_output, const char* parent_f_string_quote = nullptr);
|
||||
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user