Ignore:
Timestamp:
Jan 26, 2008, 10:27:57 AM (17 years ago)
Author:
[email protected]
Message:

Reviewed by Mark Rowe.

Cleanup node2string a little.

  • Remove some unnecessary branching.
  • Factor out bracket and dot streaming into static inline functions.
  • kjs/nodes.h:
  • kjs/nodes2string.cpp: (KJS::bracketNodeStreamTo): (KJS::dotNodeStreamTo): (KJS::FunctionCallBracketNode::streamTo): (KJS::FunctionCallDotNode::streamTo): (KJS::PostIncBracketNode::streamTo): (KJS::PostDecBracketNode::streamTo): (KJS::PostIncDotNode::streamTo): (KJS::PostDecDotNode::streamTo): (KJS::DeleteBracketNode::streamTo): (KJS::DeleteDotNode::streamTo): (KJS::PreIncBracketNode::streamTo): (KJS::PreDecBracketNode::streamTo): (KJS::PreIncDotNode::streamTo): (KJS::PreDecDotNode::streamTo): (KJS::ReadModifyBracketNode::streamTo): (KJS::AssignBracketNode::streamTo): (KJS::ReadModifyDotNode::streamTo): (KJS::AssignDotNode::streamTo): (KJS::WhileNode::streamTo):
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/kjs/nodes2string.cpp

    r29804 r29809  
    262262}
    263263
     264static inline void bracketNodeStreamTo(SourceStream& s, const RefPtr<ExpressionNode>& base, const RefPtr<ExpressionNode>& subscript)
     265{
     266    s << PrecCall << base.get() << "[" << subscript.get() << "]";
     267}
     268
     269static inline void dotNodeStreamTo(SourceStream& s, const RefPtr<ExpressionNode>& base, const Identifier& ident)
     270{
     271    s << DotExpr << PrecCall << base.get() << "." << ident;
     272}
     273
    264274// --------
    265275
     
    420430void FunctionCallBracketNode::streamTo(SourceStream& s) const
    421431{
    422     s << PrecCall << base << "[" << subscript << "]" << args;
     432    bracketNodeStreamTo(s, base, subscript);
     433    s << args;
    423434}
    424435
    425436void FunctionCallDotNode::streamTo(SourceStream& s) const
    426437{
    427     s << DotExpr << PrecCall << base << "." << ident << args;
     438    dotNodeStreamTo(s, base, ident);
     439    s << args;
    428440}
    429441
     
    438450}
    439451
    440 void PostfixBracketNode::streamTo(SourceStream& s) const
    441 {
    442     s << PrecCall << m_base << "[" << m_subscript << "]";
    443     if (isIncrement())
    444         s << "++";
    445     else
    446         s << "--";
    447 }
    448 
    449 void PostfixDotNode::streamTo(SourceStream& s) const
    450 {
    451     s << DotExpr << PrecCall << m_base << "." << m_ident;
    452     if (isIncrement())
    453         s << "++";
    454     else
    455         s << "--";
     452void PostIncBracketNode::streamTo(SourceStream& s) const
     453{
     454    bracketNodeStreamTo(s, m_base, m_subscript);
     455    s << "++";
     456}
     457
     458void PostDecBracketNode::streamTo(SourceStream& s) const
     459{
     460    bracketNodeStreamTo(s, m_base, m_subscript);
     461    s << "--";
     462}
     463
     464void PostIncDotNode::streamTo(SourceStream& s) const
     465{
     466    dotNodeStreamTo(s, m_base, m_ident);
     467    s << "++";
     468}
     469
     470void PostDecDotNode::streamTo(SourceStream& s) const
     471{
     472    dotNodeStreamTo(s, m_base, m_ident);
     473    s << "--";
    456474}
    457475
     
    472490void DeleteBracketNode::streamTo(SourceStream& s) const
    473491{
    474     s << "delete " << PrecCall << m_base << "[" << m_subscript << "]";
     492    s << "delete ";
     493    bracketNodeStreamTo(s, m_base, m_subscript);
    475494}
    476495
    477496void DeleteDotNode::streamTo(SourceStream& s) const
    478497{
    479     s << "delete " << DotExpr << PrecCall << m_base << "." << m_ident;
     498    s << "delete ";
     499    dotNodeStreamTo(s, m_base, m_ident);
    480500}
    481501
     
    510530}
    511531
    512 void PrefixBracketNode::streamTo(SourceStream& s) const
    513 {
    514     if (isIncrement())
    515         s << "++";
    516     else
    517         s << "--";
    518     s << PrecCall << m_base << "[" << m_subscript << "]";
    519 }
    520 
    521 void PrefixDotNode::streamTo(SourceStream& s) const
    522 {
    523     if (isIncrement())
    524         s << "++";
    525     else
    526         s << "--";
    527     s << DotExpr << PrecCall << m_base << "." << m_ident;
     532void PreIncBracketNode::streamTo(SourceStream& s) const
     533{
     534    s << "++";
     535    bracketNodeStreamTo(s, m_base, m_subscript);
     536}
     537
     538void PreDecBracketNode::streamTo(SourceStream& s) const
     539{
     540    s << "--";
     541    bracketNodeStreamTo(s, m_base, m_subscript);
     542}
     543
     544void PreIncDotNode::streamTo(SourceStream& s) const
     545{
     546    s << "++";
     547    dotNodeStreamTo(s, m_base, m_ident);
     548}
     549
     550void PreDecDotNode::streamTo(SourceStream& s) const
     551{
     552    s << "--";
     553    dotNodeStreamTo(s, m_base, m_ident);
    528554}
    529555
     
    690716void ReadModifyBracketNode::streamTo(SourceStream& s) const
    691717{
    692     s << PrecCall << m_base << '[' << m_subscript << "] "
    693         << operatorString(m_oper) << ' ' << PrecAssignment << m_right;
     718    bracketNodeStreamTo(s, m_base, m_subscript);
     719    s << ' ' << operatorString(m_oper) << ' ' << PrecAssignment << m_right;
    694720}
    695721
    696722void AssignBracketNode::streamTo(SourceStream& s) const
    697723{
    698     s << PrecCall << m_base << '[' << m_subscript << "] = " << PrecAssignment << m_right;
     724    bracketNodeStreamTo(s, m_base, m_subscript);
     725    s << " = " << PrecAssignment << m_right;
    699726}
    700727
    701728void ReadModifyDotNode::streamTo(SourceStream& s) const
    702729{
    703     s << DotExpr << PrecCall << m_base << "." << m_ident << ' '
    704         << operatorString(m_oper) << ' ' << PrecAssignment << m_right;
     730    dotNodeStreamTo(s, m_base, m_ident);
     731    s << ' ' << operatorString(m_oper) << ' ' << PrecAssignment << m_right;
    705732}
    706733
    707734void AssignDotNode::streamTo(SourceStream& s) const
    708735{
    709     s << DotExpr << PrecCall << m_base << "." << m_ident << " = " << PrecAssignment << m_right;
     736    dotNodeStreamTo(s, m_base, m_ident);
     737    s << " = " << PrecAssignment << m_right;
    710738}
    711739
     
    807835void WhileNode::streamTo(SourceStream& s) const
    808836{
    809   s << Endl << "while (" << expr << ')' << Indent << statement << Unindent;
     837    s << Endl << "while (" << expr << ')' << Indent << statement << Unindent;
    810838}
    811839
     
    934962}
    935963
    936 }
     964} // namespace KJS
Note: See TracChangeset for help on using the changeset viewer.