void PeekStatementAST::generate(string& code, Type* return_type_ptr) const
{
  code += indent_str() + "{\n";  // Start scope
  inc_indent();
  g_sym_table.pushFrame();

  Type* msg_type_ptr = m_type_ptr->lookupType();

  // Add new local var to symbol table
  g_sym_table.newTempSym(new Var("in_msg", getLocation(), msg_type_ptr, "(*in_msg_ptr)", getPairs()));

  // Check the queue type
  m_queue_name_ptr->assertType("InPort");

  // Declare the new "in_msg_ptr" variable
  code += indent_str() + "const " + msg_type_ptr->cIdent() + "* in_msg_ptr;\n";  // Declare message
  //  code += indent_str() + "in_msg_ptr = static_cast<const ";
  code += indent_str() + "in_msg_ptr = dynamic_cast<const ";
  code += msg_type_ptr->cIdent() + "*>(";
  code += "(" + m_queue_name_ptr->getVar()->getCode() + ")";
  code += ".";
  code += m_method;
  code += "());\n";

  code += indent_str() + "assert(in_msg_ptr != NULL);\n";        // Check the cast result
  m_statementlist_ptr->generate(code, return_type_ptr);                // The other statements
  dec_indent();
  g_sym_table.popFrame();
  code += indent_str() + "}\n";  // End scope
}
Exemplo n.º 2
0
	virtual void visit(ExprStmt &n)
	{
		out << indent_str() << "<ExprStmt>\n";
		indent();
		n.expr->accept(*this);
		unindent();
		out << indent_str() << "</ExprStmt>\n";
	}
Exemplo n.º 3
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";
	}
Exemplo n.º 4
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";
	}
Exemplo n.º 5
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";
	}
Exemplo n.º 6
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";
	}
Exemplo n.º 7
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";
	}
Exemplo n.º 8
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";
	}
Exemplo n.º 9
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";
	}
Exemplo n.º 10
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";
	}
Exemplo n.º 11
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";
	}
Exemplo n.º 12
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";
	}
Exemplo n.º 13
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";
	}
Exemplo n.º 14
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";
	}
Exemplo n.º 15
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";
	}
Exemplo n.º 16
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";
	}
Exemplo n.º 17
0
	virtual void visit(CallExpr &n)
	{
		out << indent_str() << "<CallExpr>\n";
		indent();
		n.callee->accept(*this);
		out << indent_str() << "<Arguments>\n";
		indent();
		for (auto &arg : n.arguments)
			arg->accept(*this);
		unindent();
		out << indent_str() << "</Arguments>\n";
		unindent();
		out << indent_str() << "</CallExpr>\n";
	}
Exemplo n.º 18
0
	virtual void visit(FunctionLiteral &n)
	{
		out << indent_str() << "<FunctionLiteral>\n";
		indent();
		out << indent_str() << "<Arguments>\n";
		indent();
		for (size_t i = 0; i < n.arguments.size(); i++)
		{
			out << indent_str() << "<Argument name='" << n.arguments[i] << "'";
			if (i < n.default_arguments.size())
			{
				out << ">\n";
				n.default_arguments[i]->accept(*this);
				out << indent_str() << "</Argument>\n";
			}
			else
				out << "/>\n";
		}
		unindent();
		out << indent_str() << "</Arguments>\n";
		out << indent_str() << "<Body>\n";
		indent();
		for (auto &stmt : n.stmts)
			stmt->accept(*this);
		unindent();
		out << indent_str() << "</Body>\n";
		unindent();
		out << indent_str() << "</FunctionLiteral>\n";
	}
Exemplo n.º 19
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";
		}
	}
Exemplo n.º 20
0
	virtual void visit(ObjectLiteral &n)
	{
		out << indent_str() << "<ObjectLiteral>\n";
		indent();
		for (size_t i = 0; i < n.member_names.size(); i++)
		{
			out << indent_str() << "<Member name='" << n.member_names[i]
			    << "'>\n";
			indent();
			n.member_values[i]->accept(*this);
			unindent();
			out << indent_str() << "</Member>\n";
		}
		unindent();
		out << indent_str() << "</ObjectLiteral>\n";
	}
Exemplo n.º 21
0
std::string StatsNode::str(int indent) const {
    if (is_terminal()) {
        std::ostringstream out;
        
        if (terminal_items_.size() == 1) {
            out << "\"" << terminal_items_.front() << "\"";
        } else {
            out << "[";
            for (std::size_t i = 0; i < terminal_items_.size() - 1; ++i) {
                out << "\"" << terminal_items_[i] << "\", ";
            }
            out << "\"" << terminal_items_.back() << "\"]";
        }
        return out.str();
    }
    
    std::ostringstream out;
    std::string indent_str(indent*indent_size, ' ');
    std::string indent_deep_str((indent + 1)*indent_size, ' ');
    out << "{" << std::endl;
    for (auto it = std::begin(nodes_); it != std::end(nodes_); ++it) {
        out << indent_deep_str << "\"" << it->first << "\": " << it->second.str(indent + 1);
        if (std::distance(std::begin(nodes_), it) < nodes_.size() - 1) {
            out << ",";
        }
        out << std::endl;
    }
    out << indent_str << "}";
    return out.str();
}
void ExprStatementAST::generate(string& code, Type* return_type_ptr) const
{
    code += indent_str();
    Type* actual_type_ptr = m_expr_ptr->generate(code);
    code += ";\n";

    // The return type must be void
    Type* expected_type_ptr = g_sym_table.getType("void");
    if (expected_type_ptr != actual_type_ptr) {
        m_expr_ptr->error("Non-void return must not be ignored, return type is '" + actual_type_ptr->toString() + "'");
    }
}
Exemplo n.º 23
0
void CopyHeadStatementAST::generate(string& code, Type* return_type_ptr) const
{
  m_in_queue_ptr->assertType("InPort");
  m_out_queue_ptr->assertType("OutPort");

  code += indent_str();
  code += m_out_queue_ptr->getVar()->getCode() + ".enqueue(" + m_in_queue_ptr->getVar()->getCode() + ".getMsgPtrCopy()";

  if (getPairs().exist("latency")) {
    code += ", " + getPairs().lookup("latency");
  } else {
    code += ", COPY_HEAD_LATENCY";
  }

  code += ");\n";
}
Exemplo n.º 24
0
Arquivo: log.cpp Projeto: 2php/mp4v2
/**
 * Dump info if it has appropriate verbosity, either to
 * standard out (with a newline appended to @p format) or to
 * the callback function (with no newline appended).
 *
 * @param indent the number of spaces to indent the info
 *
 * @param verbosity the level of detail the message contains
 *
 * @param format the format string to use to process @p ap.
 * @p format should not contain a newline.
 *
 * @param ap varargs to build the message
 */
void
Log::vdump( uint8_t     indent,
            MP4LogLevel verbosity_,
            const char* format,
            va_list     ap )
{
    // Make sure nothing gets logged with MP4_LOG_NONE.
    // That way people who ask for nothing to get logged
    // won't get anything logged.
    ASSERT(verbosity_ != MP4_LOG_NONE);
    ASSERT(format);
    ASSERT(format[0] != '\0');

    if (verbosity_ > this->_verbosity)
    {
        // We're not set verbose enough to log this
        return;
    }

    if (Log::_cb_func)
    {
        ostringstream   new_format;

        if (indent > 0)
        {
            string      indent_str(indent,' ');
            // new_format << setw(indent) << setfill(' ') << "" << setw(0);
            // new_format << format;
            new_format << indent_str << format;
            Log::_cb_func(verbosity_,new_format.str().c_str(),ap);
            return;
        }

        Log::_cb_func(verbosity_,format,ap);
        return;
    }

    // No callback set so log to standard out.  
    if (indent > 0)
    {
        ::fprintf(stdout,"%*c",indent,' ');
    }
    ::vfprintf(stdout,format,ap);
    ::fprintf(stdout,"\n");
}
Exemplo n.º 25
0
std::string expr2javat::convert_code_java_delete(
  const exprt &src,
  unsigned indent)
{
  std::string dest=indent_str(indent)+"delete ";

  if(src.operands().size()!=1)
  {
    unsigned precedence;
    return convert_norep(src, precedence);
  }

  std::string tmp=convert(src.op0());

  dest+=tmp+";\n";

  return dest;
}
Exemplo n.º 26
0
void ReturnStatementAST::generate(string& code, Type* return_type_ptr) const
{
  code += indent_str();
  code += "return ";
  Type* actual_type_ptr = m_expr_ptr->generate(code);
  code += ";\n";

  // Is return valid here?
  if (return_type_ptr == NULL) {
    error("Invalid 'return' statement");
  }

  // The return type must match the return_type_ptr
  if (return_type_ptr != actual_type_ptr) {
    m_expr_ptr->error("Return type miss-match, expected return type is '" + return_type_ptr->toString() + 
                      "', actual is '" + actual_type_ptr->toString() + "'");
  }
}
Exemplo n.º 27
0
static void pretty_print(const Json::array &values, string &out, PrettyPrintOptions &options) {
    options.current_indentation += options.indent_increment;
    string indent_str(options.current_indentation, ' ');

    bool first = true;
    out += "[\n";
    for (auto &value : values) {
        if (!first)
            out += ",\n";
        out += indent_str;
        value.pretty_print(out, options);
        first = false;
    }
    out += "\n";
    options.current_indentation -= options.indent_increment;
    out += string(options.current_indentation, ' ');
    out += "]";
}
Exemplo n.º 28
0
static void pretty_print(const Json::object &values, string &out, PrettyPrintOptions &options) {
    options.current_indentation += options.indent_increment;
    string indent_str(options.current_indentation, ' ');

    bool first = true;
    out += "{\n";
    for (const auto &kv : values) {
        if (!first)
            out += ",\n";
        out += indent_str;
        pretty_print(kv.first, out, options);
        out += ": ";
        kv.second.pretty_print(out, options);
        first = false;
    }
    out += "\n";
    options.current_indentation -= options.indent_increment;
    out += string(options.current_indentation, ' ');
    out += "}";
}
Exemplo n.º 29
0
std::string expr2javat::convert_code_function_call(
  const code_function_callt &src,
  unsigned indent)
{
  if(src.operands().size()!=3)
  {
    unsigned precedence;
    return convert_norep(src, precedence);
  }

  std::string dest=indent_str(indent);

  if(src.lhs().is_not_nil())
  {
    unsigned p;
    std::string lhs_str=convert(src.lhs(), p);

    // TODO: ggf. Klammern je nach p
    dest+=lhs_str;
    dest+='=';
  }

  const code_typet &code_type=
    to_code_type(src.function().type());

  bool has_this=code_type.has_this() &&
                !src.arguments().empty();

  if(has_this)
  {
    unsigned p;
    std::string this_str=convert(src.arguments()[0], p);
    dest+=this_str;
    dest+=" . "; // extra spaces for readability
  }

  {
    unsigned p;
    std::string function_str=convert(src.function(), p);
    dest+=function_str;
  }

  dest+='(';

  const exprt::operandst &arguments=src.arguments();

  bool first=true;

  forall_expr(it, arguments)
  {
    if(has_this && it==arguments.begin())
    {
    }
    else
    {
      unsigned p;
      std::string arg_str=convert(*it, p);

      if(first) first=false; else dest+=", ";
      // TODO: ggf. Klammern je nach p
      dest+=arg_str;
    }
  }

  dest+=");";

  return dest;
}
Exemplo n.º 30
0
    /**
     * Recursively add properties from a nexus file to
     * the workspace run.
     *
     * @param nxfileID    :: Nexus file handle to be parsed, just after an NXopengroup
     * @param runDetails  :: where to add properties
     * @param parent_name :: nexus caller name
     * @param parent_class :: nexus caller class
     * @param level       :: current level in nexus tree
     *
     */
    void LoadHelper::recurseAndAddNexusFieldsToWsRun(NXhandle nxfileID, API::Run& runDetails,
        std::string& parent_name, std::string& parent_class, int level)
    {

      std::string indent_str(level * 2, ' '); // Two space by indent level

      // Link ?

      // Attributes ?

      // Classes
      NXstatus getnextentry_status;       ///< return status
      int datatype; ///< NX data type if a dataset, e.g. NX_CHAR, NX_FLOAT32, see napi.h
      char nxname[NX_MAXNAMELEN], nxclass[NX_MAXNAMELEN];
      nxname[0] = '0';
      nxclass[0] = '0';

      bool has_entry = true; // follows getnextentry_status
      while (has_entry)
      {
        getnextentry_status = NXgetnextentry(nxfileID, nxname, nxclass, &datatype);

        if (getnextentry_status == NX_OK)
        {
          g_log.debug() << indent_str << parent_name << "." << nxname << " ; " << nxclass << std::endl;

          NXstatus opengroup_status;
          NXstatus opendata_status;

          if ((opengroup_status = NXopengroup(nxfileID, nxname, nxclass)) == NX_OK)
          {

            // Go down to one level
            std::string p_nxname(nxname); //current names can be useful for next level
            std::string p_nxclass(nxclass);

            recurseAndAddNexusFieldsToWsRun(nxfileID, runDetails, p_nxname, p_nxclass, level + 1);

            NXclosegroup(nxfileID);
          }        // if(NXopengroup
          else if ((opendata_status = NXopendata(nxfileID, nxname)) == NX_OK)
          {
            //dump_attributes(nxfileID, indent_str);
            g_log.debug() << indent_str << nxname << " opened." << std::endl;

            if (parent_class == "NXData" || parent_class == "NXMonitor" || std::string(nxname) == "data")
            {
              g_log.debug() << indent_str << "skipping " << parent_class << " (" << nxname << ")"
                  << std::endl;
              /* nothing */
            }
            else
            { // create a property
              int rank;
              int dims[4];
              int type;
              dims[0] = dims[1] = dims[2] = dims[3] = 0;

              std::string property_name = (parent_name.empty() ? nxname : parent_name + "." + nxname);

              g_log.debug() << indent_str << "considering property " << property_name << std::endl;

              // Get the value
              NXgetinfo(nxfileID, &rank, dims, &type);

              // Note, we choose to only build properties on small float arrays
              // filter logic is below
              bool build_small_float_array = false;              // default

              if ((type == NX_FLOAT32) || (type == NX_FLOAT64))
              {
                if ((rank == 1) && (dims[0] <= 9))
                {
                  build_small_float_array = true;
                }
                else
                {
                  g_log.debug() << indent_str << "ignored multi dimension float data on "
                      << property_name << std::endl;
                }
              }
              else if (type != NX_CHAR)
              {
                if ((rank != 1) || (dims[0] != 1) || (dims[1] != 1) || (dims[2] != 1) || (dims[3] != 1))
                {
                  g_log.debug() << indent_str << "ignored multi dimension data on " << property_name
                      << std::endl;
                }
              }

              void *dataBuffer;
              NXmalloc(&dataBuffer, rank, dims, type);

              if (NXgetdata(nxfileID, dataBuffer) != NX_OK)
              {
                NXfree(&dataBuffer);
                throw std::runtime_error("Cannot read data from NeXus file");
              }

              if (type == NX_CHAR)
              {
                std::string property_value((const char *) dataBuffer);
                if (boost::algorithm::ends_with(property_name, "_time"))
                {
                  // That's a time value! Convert to Mantid standard
                  property_value = dateTimeInIsoFormat(property_value);
                }
                runDetails.addProperty(property_name, property_value);

              }
              else if ((type == NX_FLOAT32) || (type == NX_FLOAT64) || (type == NX_INT16)
                  || (type == NX_INT32) || (type == NX_UINT16))
              {

                // Look for "units"
                NXstatus units_status;
                char units_sbuf[NX_MAXNAMELEN];
                int units_len = NX_MAXNAMELEN;
                int units_type = NX_CHAR;

                units_status = NXgetattr(nxfileID, const_cast<char*>("units"), (void *) units_sbuf,
                    &units_len, &units_type);
                if (units_status != NX_ERROR)
                {
                  g_log.debug() << indent_str << "[ " << property_name << " has unit " << units_sbuf
                      << " ]" << std::endl;
                }

                if ((type == NX_FLOAT32) || (type == NX_FLOAT64))
                {
                  // Mantid numerical properties are double only.
                  double property_double_value = 0.0;

                  // Simple case, one value
                  if (dims[0] == 1)
                  {
                    if (type == NX_FLOAT32)
                    {
                      property_double_value = *((float*) dataBuffer);
                    }
                    else if (type == NX_FLOAT64)
                    {
                      property_double_value = *((double*) dataBuffer);
                    }
                    if (units_status != NX_ERROR)
                      runDetails.addProperty(property_name, property_double_value,
                          std::string(units_sbuf));
                    else
                      runDetails.addProperty(property_name, property_double_value);
                  }
                  else if (build_small_float_array)
                  {
                    // An array, converted to "name_index", with index < 10 (see test above)
                    for (int dim_index = 0; dim_index < dims[0]; dim_index++)
                    {
                      if (type == NX_FLOAT32)
                      {
                        property_double_value = ((float*) dataBuffer)[dim_index];
                      }
                      else if (type == NX_FLOAT64)
                      {
                        property_double_value = ((double*) dataBuffer)[dim_index];
                      }
                      std::string indexed_property_name = property_name + std::string("_")
                          + boost::lexical_cast<std::string>(dim_index);
                      if (units_status != NX_ERROR)
                        runDetails.addProperty(indexed_property_name, property_double_value,
                            std::string(units_sbuf));
                      else
                        runDetails.addProperty(indexed_property_name, property_double_value);
                    }
                  }

                }
                else
                {
                  // int case
                  int property_int_value = 0;
                  if (type == NX_INT16)
                  {
                    property_int_value = *((short int*) dataBuffer);
                  }
                  else if (type == NX_INT32)
                  {
                    property_int_value = *((int*) dataBuffer);
                  }
                  else if (type == NX_UINT16)
                  {
                    property_int_value = *((short unsigned int*) dataBuffer);
                  }

                  if (units_status != NX_ERROR)
                    runDetails.addProperty(property_name, property_int_value, std::string(units_sbuf));
                  else
                    runDetails.addProperty(property_name, property_int_value);

                } // if (type==...

              }
              else
              {
                g_log.debug() << indent_str << "unexpected data on " << property_name << std::endl;
              } // test on nxdata type

              NXfree(&dataBuffer);
              dataBuffer = NULL;

            } // if (parent_class == "NXData" || parent_class == "NXMonitor") else

            NXclosedata(nxfileID);
          }
          else
          {
            g_log.debug() << indent_str << "unexpected status (" << opendata_status << ") on " << nxname
                << std::endl;
          }

        }
        else if (getnextentry_status == NX_EOD)
        {
          g_log.debug() << indent_str << "End of Dir" << std::endl;
          has_entry = false; // end of loop
        }
        else
        {
          g_log.debug() << indent_str << "unexpected status (" << getnextentry_status << ")"
              << std::endl;
          has_entry = false; // end of loop
        }

      } // while

    } // recurseAndAddNexusFieldsToWsRun