Repository: shader-slang/slang
File: source/slang/slang-parser.cpp (C++)

Code before:
        {
            PrefixExpr* prefixExpr = parser->astBuilder->create<PrefixExpr>();
            parser->FillPosition(prefixExpr);
            prefixExpr->functionExpr = parseOperator(parser);

            auto arg = parsePrefixExpr(parser);

            if (auto intLit = as<IntegerLiteralExpr>(arg))
            {
                IntegerLiteralExpr* newLiteral =
                    parser->astBuilder->create<IntegerLiteralExpr>(*intLit);

                IRIntegerValue value = _foldIntegerPrefixOp(tokenType, newLiteral->value);

                // Need to get the basic type, so we can fit to underlying type
                if (auto basicExprType = as<BasicExpressionType>(intLit->type.type))
                {
                    value =
                        _fixIntegerLiteral(basicExprType->getBaseType(), value, nullptr, nullptr);
                }

                newLiteral->value = value;
                // Mark this literal as having been negated if it was a unary minus operation
                if (tokenType == TokenType::OpSub)
                {
                    newLiteral->wasNegated = true;
                }
                // Mark this literal as having been bitwise NOT if it was a unary bitwise NOT
                // operation
                if (tokenType == TokenType::OpBitNot)
                {
                    newLiteral->wasBitwiseNot = true;
                }
                return newLiteral;
            }
            else if (auto floatLit = as<FloatingPointLiteralExpr>(arg))
            {
                FloatingPointLiteralExpr* newLiteral =
                    parser->astBuilder->create<FloatingPointLiteralExpr>(*floatLit);
                newLiteral->value = _foldFloatPrefixOp(tokenType, floatLit->value);
                return newLiteral;
            }

            prefixExpr->arguments.add(arg);
            return prefixExpr;
        }

        break;
    }
}


Review comment (bug):
Since you always use `||` to check these two conditions, why don't you just combine the two flags into one?
```
if (tokenType == TokenType::OpSub || tokenType == TokenType::OpBitNot)
{
  ...
}
```

But other than that, I don't know why we have to differentiate the reasons of overflow?

Code after:
            PrefixExpr* prefixExpr = parser->astBuilder->create<PrefixExpr>();
            parser->FillPosition(prefixExpr);
            prefixExpr->functionExpr = parseOperator(parser);

            auto arg = parsePrefixExpr(parser);

            if (auto intLit = as<IntegerLiteralExpr>(arg))
            {
                IntegerLiteralExpr* newLiteral =
                    parser->astBuilder->create<IntegerLiteralExpr>(*intLit);

                IRIntegerValue value = _foldIntegerPrefixOp(tokenType, newLiteral->value);

                // Need to get the basic type, so we can fit to underlying type
                if (auto basicExprType = as<BasicExpressionType>(intLit->type.type))
                {
                    value =
                        _fixIntegerLiteral(basicExprType->getBaseType(), value, nullptr, nullptr);
                }

                newLiteral->value = value;
                return newLiteral;
            }
            else if (auto floatLit = as<FloatingPointLiteralExpr>(arg))
            {
                FloatingPointLiteralExpr* newLiteral =
                    parser->astBuilder->create<FloatingPointLiteralExpr>(*floatLit);
                newLiteral->value = _foldFloatPrefixOp(tokenType, floatLit->value);
                return newLiteral;
            }

            prefixExpr->arguments.add(arg);
            return prefixExpr;
        }

        break;
    }
}

Expr* Parser::ParseLeafExpression()
{
    return parsePrefixExpr(this);
}

/// Parse an argument to an application of a generic
static Expr* _parseGenericArg(Parser* parser)
{
    // The grammar for generic arguments needs to be a superset of the
    // grammar for types and for expressions, because we do not know
    // which to expect at each argument position during parsing.
    //