Beispiel #1
0
void StyledStreamWriter::writeValue(const Value& value) {
    switch (value.type()) {
    case nullValue:
        pushValue("null");
        break;
    case intValue:
        pushValue(valueToString(value.asLargestInt()));
        break;
    case uintValue:
        pushValue(valueToString(value.asLargestUInt()));
        break;
    case realValue:
        pushValue(valueToString(value.asDouble()));
        break;
    case stringValue:
    {
        // Is NULL possible for value.string_?
        char const* str;
        char const* end;
        bool ok = value.getString(&str, &end);
        if (ok) pushValue(valueToQuotedStringN(str, static_cast<unsigned>(end-str)));
        else pushValue("");
        break;
    }
    case booleanValue:
        pushValue(valueToString(value.asBool()));
        break;
    case arrayValue:
        writeArrayValue(value);
        break;
    case objectValue: {
        Value::Members members(value.getMemberNames());
        if (members.empty())
            pushValue("{}");
        else {
            writeWithIndent("{");
            indent();
            Value::Members::iterator it = members.begin();
            for (;;) {
                const std::string& name = *it;
                const Value& childValue = value[name];
                writeCommentBeforeValue(childValue);
                writeWithIndent(valueToQuotedString(name.c_str()));
                *document_ << " : ";
                writeValue(childValue);
                if (++it == members.end()) {
                    writeCommentAfterValueOnSameLine(childValue);
                    break;
                }
                *document_ << ",";
                writeCommentAfterValueOnSameLine(childValue);
            }
            unindent();
            writeWithIndent("}");
        }
    }
    break;
    }
}
Beispiel #2
0
void BuiltStyledStreamWriter::writeValue(Value const& value) {
    switch (value.type()) {
    case nullValue:
        pushValue(nullSymbol_);
        break;
    case intValue:
        pushValue(valueToString(value.asLargestInt()));
        break;
    case uintValue:
        pushValue(valueToString(value.asLargestUInt()));
        break;
    case realValue:
        pushValue(valueToString(value.asDouble(), useSpecialFloats_, precision_));
        break;
    case stringValue:
    {
        // Is NULL is possible for value.string_?
        char const* str;
        char const* end;
        bool ok = value.getString(&str, &end);
        if (ok) pushValue(valueToQuotedStringN(str, static_cast<unsigned>(end-str)));
        else pushValue("");
        break;
    }
    case booleanValue:
        pushValue(valueToString(value.asBool()));
        break;
    case arrayValue:
        writeArrayValue(value);
        break;
    case objectValue: {
        Value::Members members(value.getMemberNames());
        if (members.empty())
            pushValue("{}");
        else {
            writeWithIndent("{");
            indent();
            Value::Members::iterator it = members.begin();
            for (;;) {
                std::string const& name = *it;
                Value const& childValue = value[name];
                writeCommentBeforeValue(childValue);
                writeWithIndent(valueToQuotedStringN(name.data(), static_cast<unsigned>(name.length())));
                *sout_ << colonSymbol_;
                writeValue(childValue);
                if (++it == members.end()) {
                    writeCommentAfterValueOnSameLine(childValue);
                    break;
                }
                *sout_ << ",";
                writeCommentAfterValueOnSameLine(childValue);
            }
            unindent();
            writeWithIndent("}");
        }
    }
    break;
    }
}
Beispiel #3
0
void 
StyledStreamWriter::writeValue( const Value &value )
{
   switch ( value.type() )
   {
   case nullValue:
      pushValue( "null" );
      break;
   case intValue:
      pushValue( valueToString( value.asLargestInt() ) );
      break;
   case uintValue:
      pushValue( valueToString( value.asLargestUInt() ) );
      break;
   case realValue:
      pushValue( valueToString( value.asDouble() ) );
      break;
   case stringValue:
      pushValue( valueToQuotedString( value.asCString() ) );
      break;
   case booleanValue:
      pushValue( valueToString( value.asBool() ) );
      break;
   case arrayValue:
      writeArrayValue( value);
      break;
   case objectValue:
      {
         Value::Members members( value.getMemberNames() );
         if ( members.empty() )
            pushValue( "{}" );
         else
         {
            writeWithIndent( "{" );
            indent();
            Value::Members::iterator it = members.begin();
            for (;;)
            {
               const std::string &name = *it;
               const Value &childValue = value[name];
               writeCommentBeforeValue( childValue );
               writeWithIndent( valueToQuotedString( name.c_str() ) );
               *document_ << " : ";
               writeValue( childValue );
               if ( ++it == members.end() )
               {
                  writeCommentAfterValueOnSameLine( childValue );
                  break;
               }
               *document_ << ",";
               writeCommentAfterValueOnSameLine( childValue );
            }
            unindent();
            writeWithIndent( "}" );
         }
      }
      break;
   }
}
Beispiel #4
0
	virtual void visit(ExprStmt &n)
	{
		out << indent_str() << "<ExprStmt>\n";
		indent();
		n.expr->accept(*this);
		unindent();
		out << indent_str() << "</ExprStmt>\n";
	}
Beispiel #5
0
	virtual void visit(LetBinding &n)
	{
		out << indent_str() << "<LetBinding name='" << n.name << "'>\n";
		indent();
		n.value->accept(*this);
		unindent();
		out << indent_str() << "</LetBinding>\n";
	}
Beispiel #6
0
	virtual void visit(MemberExpr &n)
	{
		out << indent_str() << "<MemberExpr>\n";
		indent();
		n.object->accept(*this);
		n.member->accept(*this);
		unindent();
		out << indent_str() << "</MemberExpr>\n";
	}
Beispiel #7
0
	virtual void visit(IndexExpr &n)
	{
		out << indent_str() << "<IndexExpr>\n";
		indent();
		n.object->accept(*this);
		n.index->accept(*this);
		unindent();
		out << indent_str() << "</IndexExpr>\n";
	}
Beispiel #8
0
	virtual void visit(Module &n)
	{
		out << indent_str() << "<Module filename='" << n.filename << "'>\n";
		indent();
		for (auto &stmt : n.stmts)
			stmt->accept(*this);
		unindent();
		out << indent_str() << "</Module>\n";
	}
Beispiel #9
0
	virtual void visit(CompoundStmt &n)
	{
		out << indent_str() << "<CompoundStmt>\n";
		indent();
		for (auto &stmt : n.stmts)
			stmt->accept(*this);
		unindent();
		out << indent_str() << "</CompoundStmt>\n";
	}
Beispiel #10
0
	virtual void visit(UnaryExpr &n)
	{
		out << indent_str() << "<UnaryExpr op='" << token_kind_name(n.op)
		    << "'>\n";
		indent();
		n.operand->accept(*this);
		unindent();
		out << indent_str() << "</UnaryExpr>\n";
	}
Beispiel #11
0
	virtual void visit(ListLiteral &n)
	{
		out << indent_str() << "<ListLiteral>\n";
		indent();
		for (auto &elem : n.elements)
			elem->accept(*this);
		unindent();
		out << indent_str() << "</ListLiteral>\n";
	}
Beispiel #12
0
	virtual void visit(UntilStmt &n)
	{
		out << indent_str() << "<UntilStmt>\n";
		indent();
		n.expr->accept(*this);
		n.stmt->accept(*this);
		unindent();
		out << indent_str() << "</UntilStmt>\n";
	}
Beispiel #13
0
	virtual void visit(ForStmt &n)
	{
		out << indent_str() << "<ForStmt>\n";
		indent();
		n.iterator->accept(*this);
		n.sequence->accept(*this);
		unindent();
		out << indent_str() << "</ForStmt>\n";
	}
Beispiel #14
0
	virtual void visit(WhileStmt &n)
	{
		out << indent_str() << "<WhileStmt>\n";
		indent();
		n.expr->accept(*this);
		n.stmt->accept(*this);
		unindent();
		out << indent_str() << "</WhileStmt>\n";
	}
Beispiel #15
0
void
StyledStreamWriter::writeArrayValue ( const Value& value )
{
    unsigned size = value.size ();

    if ( size == 0 )
        pushValue ( "[]" );
    else
    {
        bool isArrayMultiLine = isMultineArray ( value );

        if ( isArrayMultiLine )
        {
            writeWithIndent ( "[" );
            indent ();
            bool hasChildValue = !childValues_.empty ();
            unsigned index = 0;

            while ( true )
            {
                const Value& childValue = value[index];

                if ( hasChildValue )
                    writeWithIndent ( childValues_[index] );
                else
                {
                    writeIndent ();
                    writeValue ( childValue );
                }

                if ( ++index == size )
                    break;

                *document_ << ",";
            }

            unindent ();
            writeWithIndent ( "]" );
        }
        else // output on a single line
        {
            assert ( childValues_.size () == size );
            *document_ << "[ ";

            for ( unsigned index = 0; index < size; ++index )
            {
                if ( index > 0 )
                    *document_ << ", ";

                *document_ << childValues_[index];
            }

            *document_ << " ]";
        }
    }
}
Beispiel #16
0
	virtual void visit(BinaryExpr &n)
	{
		out << indent_str() << "<BinaryExpr op='" << token_kind_name(n.op)
		    << "'>\n";
		indent();
		n.left->accept(*this);
		n.right->accept(*this);
		unindent();
		out << indent_str() << "</BinaryExpr>\n";
	}
Beispiel #17
0
	virtual void visit(SliceExpr &n)
	{
		out << indent_str() << "<SliceExpr>\n";
		indent();
		n.start->accept(*this);
		n.stop->accept(*this);
		n.step->accept(*this);
		unindent();
		out << indent_str() << "</SliceExpr>\n";
	}
Beispiel #18
0
static void code_string_elem( Telem* elem )
{
  fprintf( outfile, "( \"%s\",\n", elem->params[0]->data.name );
  indent();
  codeelemparam( elem->params[1] );
  fprintf( outfile, "\n" );
  unindent();
  codeindent();
  fprintf( outfile, ")" );
}
Beispiel #19
0
static void code_elem( Telem* elem )
{
  fprintf( outfile, "(\n" );
  indent();
  codeelemparam( elem->params[0] );
  fprintf( outfile, "\n" );
  unindent();
  codeindent();
  fprintf( outfile, ")" );
}
Beispiel #20
0
	virtual void visit(IfExpr &n)
	{
		out << indent_str() << "<IfExpr>\n";
		indent();
		n.predicate->accept(*this);
		n.consequence->accept(*this);
		n.alternative->accept(*this);
		unindent();
		out << indent_str() << "</IfExpr>\n";
	}
Beispiel #21
0
	virtual void visit(UnlessStmt &n)
	{
		out << indent_str() << "<UnlessStmt>\n";
		indent();
		n.predicate->accept(*this);
		n.consequence->accept(*this);
		if (n.alternative)
			n.alternative->accept(*this);
		unindent();
		out << indent_str() << "</UnlessStmt>\n";
	}
Beispiel #22
0
    void do_end_object() override
    {
        unindent();
        if (indenting_ && !stack_.empty())
        {
            write_indent();
        }
        stack_.pop_back();
        os_->put('}');

        end_value();
    }
Beispiel #23
0
    void do_end_array() override
    {
        unindent();
        if (indenting_ && !stack_.empty() && stack_.back().content_indented_)
        {
            write_indent();
        }
        stack_.pop_back();
        os_->put(']');

        end_value();
    }
    virtual void end_object()
    {
        unindent();
        if (indenting_ && !stack_.empty())
        {
            write_indent();
        }
        stack_.pop_back();
        os_.put('}');

        end_value();
    }
    virtual void end_array()
    {
        unindent();
        if (indenting_ && !stack_.empty() && stack_.back().content_indented_)
        {
            write_indent();
        }
        stack_.pop_back();
        os_.put(']');

        end_value();
    }
Beispiel #26
0
stack_tracer::stack_tracer (const char * sig,
                            const char * file,
                            int          line,
                            const char * msg)
    : sig_      (sig)
    , file_     (file)
    , line_     (line)
    , msg_      (msg)
{
    std::string out;

    indent_++;

    if ( enabled )
    {
        out += indent ();
        out += " -> ";
        out += unindent ();

        if ( 0 == sizeof (msg_) )
        {
            out += msg_;
            out += "\n";
            out += indent ();
            out += "  > \n";
            out += unindent ();
        }

        out += sig_;
        out += " : ";
        out += file_;
        out += " +";
        out += saga::util::itoa (line_);

        saga::util::log (saga::util::logging::Debug, "stack trace level" + saga::util::itoa (indent_), out);

        /// get_stack_ ().push_back (sig_ + " - " + msg_);
    }
}
Beispiel #27
0
void 
StyledWriter::writeArrayValue( const Value &value )
{
   unsigned size = value.size();
   if ( size == 0 )
      pushValue( "[]" );
   else
   {
      bool isArrayMultiLine = isMultineArray( value );
      if ( isArrayMultiLine )
      {
         writeWithIndent( "[" );
         indent();
         bool hasChildValue = !childValues_.empty();
         unsigned index =0;
         for (;;)
         {
            const Value &childValue = value[index];
            writeCommentBeforeValue( childValue );
            if ( hasChildValue )
               writeWithIndent( childValues_[index] );
            else
            {
               writeIndent();
               writeValue( childValue );
            }
            if ( ++index == size )
            {
               writeCommentAfterValueOnSameLine( childValue );
               break;
            }
            document_ += ",";
            writeCommentAfterValueOnSameLine( childValue );
         }
         unindent();
         writeWithIndent( "]" );
      }
      else // output on a single line
      {
         assert( childValues_.size() == size );
         document_ += "[ ";
         for ( unsigned index =0; index < size; ++index )
         {
            if ( index > 0 )
               document_ += ", ";
            document_ += childValues_[index];
         }
         document_ += " ]";
      }
   }
}
Beispiel #28
0
static void code_elemlist( Telem* elem )
{
  int i=0;
  fprintf( outfile, "(\n" );
  indent();
  for (i=0; i<elem->nparams; i++)
  {
    codeelemparam( elem->params[i] );
    fprintf( outfile, ",\n" ); 
  }
  unindent();
  codeindent();
  fprintf( outfile, "NULL)" );
}
Beispiel #29
0
	virtual void visit(ReturnStmt &n)
	{
		if (n.expr)
		{
			out << indent_str() << "<ReturnStmt>\n";
			indent();
			n.expr->accept(*this);
			unindent();
			out << indent_str() << "</ReturnStmt>\n";
		}
		else
		{
			out << indent_str() << "<ReturnStmt/>\n";
		}
	}
	void bufferFromBlock(KviCString & szBuffer)
	{
		szBuffer.trim();

		if((*(szBuffer.ptr()) == '{') && szBuffer.lastCharIs('}'))
		{
			// leading and trailing { must be stripped
			szBuffer.cutLeft(1);
			szBuffer.cutRight(1);
		}

		unindent(szBuffer);

		szBuffer.trim();
	}