Example #1
0
void CodeGenerator::printString(const std::string &str, AnalysisResultPtr ar,
                                bool stringWrapper /* = true */,
                                bool check /* = true */) {
  int index = -1;
  int stringId = check ? checkLiteralString(str, index, ar) : -1;
  bool isBinary = false;
  string escaped = escapeLabel(str, &isBinary);
  if (stringId >= 0) {
    if (index == -1) {
      printf("LITSTR(%d, \"%s\")", stringId, escaped.c_str());
    } else {
      assert(index >= 0);
      string lisnam = ar->getLiteralStringName(stringId, index);
      printf("NAMSTR(%s, \"%s\")", lisnam.c_str(), escaped.c_str());
    }
  } else if (isBinary) {
    if (stringWrapper) {
      printf("String(\"%s\", %d, AttachLiteral)",
             escaped.c_str(), str.length());
    } else {
      printf("\"%s\", %d", escaped.c_str(), str.length());
    }
  } else {
    printf("\"%s\"", escaped.c_str());
  }
}
Example #2
0
string CodeGenerator::printNamedString(const string &str,
  const string &escaped, AnalysisResultPtr ar, BlockScopeRawPtr bs,
  bool print) {
  int index = -1;
  bool scalarVariant = !print;
  int stringId = checkLiteralString(str, index, ar, bs, scalarVariant);
  always_assert(index >= 0);
  string lisnam = ar->getLiteralStringName(stringId, index);
  if (print) {
    printf("NAMSTR(%s, \"%s\")", lisnam.c_str(), escaped.c_str());
  }
  return lisnam;
}