Esempio n. 1
0
QString symToHtml(const Sym& s, int leftMargin, const TextStyle* ts, qreal _spatium)
      {
      qreal size;
      if (ts) {
            size = ts->font(_spatium).pointSizeF();
            }
      else {
#ifdef USE_GLYPHS
            size = s.font().pointSizeF();
#else
            size = s.font().pixelSize();
#endif
            }

      QString family = s.font().family();
      return QString(
      "<data>"
        "<html>"
          "<head>"
            "<meta name=\"qrichtext\" content=\"1\" >"
            "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf8\" />"
            "<style type=\"text/css\">"
              "p, li { white-space: pre-wrap; }"
              "</style>"
            "</head>"
          "<body style=\" font-family:'%1'; font-size:%2pt;\">"
            "<p style=\" margin-top:0px; margin-bottom:0px; margin-left:%3px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">"
                "&#%4;"
              "</p>"
            "</body>"
          "</html>"
      "</data>").arg(family).arg(size).arg(leftMargin).arg(s.code());
      }
Esempio n. 2
0
QString symToHtml(const Sym& s1, const Sym& s2, int leftMargin)
      {
      QFont f        = s1.font();
#ifdef USE_GLYPHS
      qreal size = s1.font().pointSizeF();
#else
      qreal size = s1.font().pixelSize();
#endif
      QString family = f.family();

      return QString(
      "<data>"
        "<html>"
          "<head>"
            "<meta name=\"qrichtext\" content=\"1\" >"
            "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf8\" />"
            "<style type=\"text/css\">"
              "p, li { white-space: pre-wrap; }"
              "</style>"
            "</head>"
          "<body style=\" font-family:'%1'; font-size:%2pt;\">"
            "<p style=\" margin-top:0px; margin-bottom:0px; margin-left:%3px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">"
                "&#%4;&#%5;"
              "</p>"
            "</body>"
          "</html>"
      "</data>").arg(family).arg(size).arg(leftMargin).arg(s1.code()).arg(s2.code());
      }
Esempio n. 3
0
void print_opnd_type(Opnd o) {
  if(is_reg(o)) {
    if(is_hard_reg(o)) {
      std::cout << "(is hard reg)";
    }
    else if(is_virtual_reg(o)) {
      std::cout << "(is virtual reg)[$vr"<<get_reg(o)<<"]";
    }
    else {
      std::cout << "(is undeterminate reg)";
    }
  }
  else if(is_immed(o)) {
    if(is_immed_integer(o)) {
      std::cout << "(is immed integer)";
    }
    else if(is_immed_string(o)) {
      std::cout << "(is immed string)";
    }
    else {
      std::cout << "(is undeterminate immed)";
    }
  }
  else if(is_addr(o)) {
    if(is_addr_sym(o)) {
      FormattedText ft;
      Sym *symbol = get_sym(o);
      symbol->print(ft);
      char* addr_name;
      
      addr_name =  (char*)(symbol->get_name()).c_str();
  
      std::cout << "(is addr sym)["<<addr_name<<"]";
    }
    else if(is_addr_exp(o)) {
      std::cout << "(is addr exp)";
    }
    else {
      std::cout << "(is undeterminate addr)";
    }
  }
  else if(is_var(o)) {
    FormattedText ft;
    VarSym *vsym = get_var(o);
    vsym->print(ft);
    char* var_name;
    
    var_name =  (char*)(vsym->get_name()).c_str();

    std::cout << "(is var)["<<var_name<<"]";
  }
  else if(is_null(o)) {
    std::cout << "(is null)";
  }
  else {
    std::cout << "(I don't know) !!!)";
  }

  return;
}
Esempio n. 4
0
 Sym firstLexicalOutputTpl(Arc const* a) const {
   StateIdContainer const& tails = a->tails_;
   for (StateIdContainer::const_iterator i = tails.begin(), e = tails.end(); i != e; ++i) {
     Sym const sym = outputLabel(*i);
     if (sym.isLexical()) return sym;
   }
   return NoSymbol;
 }
Esempio n. 5
0
 void forStates(V const& v, bool lexical = true, bool unlabeled = true, bool notTerminal = true) const {
   // start first
   Self& hg = const_cast<Self&>(*this);
   for (StateId state = 0, N = size(); state < N; ++state) {
     Sym in = inputLabel(state);
     if (in == NoSymbol) {
       if (unlabeled) v(hg, state);
     } else if (in.isLexical()) {
       if (lexical) v(hg, state);
     } else if (!in.isSpecialTerminal())
       if (notTerminal) v(hg, state);
   }
 }
Esempio n. 6
0
File: Syms.hpp Progetto: graehl/hyp
//TODO: it would be nice to put print in a .cpp somewhere since performance
//isn't critical. but we have no lib for the toplevel xmt/ headers.
inline void print(std::ostream &out, Sym sym, IVocabulary const* vocab
                  , char const* variablePrefix="X") {
  //TODO: consider always escaping for syntax rule formats (anything with
  //delimiters other than space, which we never allow inside tokens, etc)
  if (variablePrefix && sym.isVariable())
    out << "X" << sym.index();
  // some unit tests use vocabularies that don't set a variables vocab. if
  // that's fixed, we can remove the variablePrefix arg
  else if (vocab)
    out << vocab->str(sym); // if you want quotes + escaping, use Hypergraph/SymbolPrint.hpp
  else
    out << sym.getTypeNameShort() << sym.index();
}
Esempio n. 7
0
PropertySym *
SymTable::FindPropertySym(SymID id) const
{
    Sym *   sym;

    sym = this->Find(id);

    if (sym)
    {
        AssertMsg(sym->IsPropertySym(), "Looking for PropertySym, found something else");
        return sym->AsPropertySym();
    }

    return NULL;
}
Esempio n. 8
0
char* get_addr_name(Opnd addr_sym) {
  
  claim(is_addr_sym(addr_sym), "opnd.cpp::get_addr_name:the type must be addr_sym!");
  
  
  FormattedText ft;
  Sym *symbol = get_sym(addr_sym);
  symbol->print(ft);
  char* addr_name;
  
  addr_name =  (char*)(symbol->get_name()).c_str();
  
  return   addr_name;
  
}
Esempio n. 9
0
  TypeId
get_deref_type(Opnd opnd)
{
  if (is_addr_sym(opnd)) {
    Sym *sym = get_sym(opnd);
    if (is_kind_of<LabelSym>(sym))
      return NULL;
    else {
      claim(is_kind_of<VarSym>(sym) || is_kind_of<ProcSym>(sym));
      return sym->get_type();
    }
  }
  claim(is_addr_exp(opnd));

  IrOpnd *o = opnd;
  return static_cast<OpndAddrExp*>(o)->get_deref_type();
}
Esempio n. 10
0
/* finds and inserts the full code in a hashmap */
HashMap::iterator find_code(Sym sym, HashMap& map) {
    HashMap::iterator result = map.find(sym);

    if (result == map.end()) { // new entry
	const SymVec& args = sym.args();
	vector<string> argstr(args.size());
	for (unsigned i = 0; i < args.size(); ++i) {
	    argstr[i] = find_code(args[i], map)->second;
	}

	// write out the code
	const FunDef& fun = get_element(sym.token());
	string code = fun.c_print(argstr, vector<string>());
	result = map.insert( make_pair(sym, code) ).first; // only want iterator
    }
    
    return result;
}
Esempio n. 11
0
std::pair<Sym,bool> insert_subtree_impl(const Sym& cur, size_t w, const Sym& nw) {
    if (w-- == 0) return make_pair(nw, !(nw == cur));
    
    const SymVec& vec = cur.args();
    std::pair<Sym,bool> result;
    unsigned i; 
    
    for (i = 0; i < vec.size(); ++i) {
	if (w < vec[i].size()) {
	    result = insert_subtree_impl(vec[i], w, nw);
	    if (result.second == false) return std::make_pair(cur, false); // unchanged
	    break;
	}
	w -= vec[i].size();
    }
    SymVec newvec = cur.args();
    newvec[i] = result.first;
    return make_pair(Sym(cur.token(), newvec), true);
}
Esempio n. 12
0
Sym get_subtree(const Sym& cur, size_t w) {
    if (w-- == 0) return cur;
    
    const SymVec& vec = cur.args();
    for (unsigned i = 0; i < vec.size(); ++i) {
	if (w < vec[i].size()) return get_subtree(vec[i], w);
	w-=vec[i].size();
    }
    return cur;
}
Esempio n. 13
0
HashMap::iterator find_entry(const Sym& sym, string& str, HashMap& map) {
    HashMap::iterator result = map.find(sym);

    if (result == map.end()) { // new entry
	const SymVec& args = sym.args();
	
	vector<string> argstr(args.size());
	for (unsigned i = 0; i < args.size(); ++i) {
	    argstr[i] = find_entry(args[i], str, map)->second;
	}

	string var = make_var(map.size()); // map.size(): unique id
	string code;	
	// write out the code
	const FunDef& fun = get_element(sym.token());
	code = fun.c_print(argstr, vector<string>() );
	    
	str += "double " + var + "=" + code + ";\n";
	result = map.insert( make_pair(sym, var ) ).first; // only want iterator
    }
    
    return result;
}
Esempio n. 14
0
std::pair<Sym, bool> do_mutate(Sym sym, double p, const LanguageTable& table) {
    
    bool changed = false;
    SymVec args = sym.args();
    if (rng.flip(p)) {
	token_t new_token = table.get_random_function(sym.token(), args.size());
	if (new_token != sym.token()) {
	    changed = true;
	    sym = Sym(new_token, args);
	}
    }

    for (unsigned i = 0; i < args.size(); ++i) {
	std::pair<Sym,bool> r = do_mutate(args[i], p, table);	
	changed |= r.second;
	if (r.second) 
	    args[i] = r.first;
    }

    if (changed)
	return std::make_pair(Sym(sym.token(), args), true);
    // else
    return std::make_pair(sym, false);
}
Esempio n. 15
0
Sym Sym::operator+(Sym &symbolic)
{
//    bool **comp;
//    comp = compSym(*this, symbolic);

   Sym ret;
   int max = this->rowSym;

   if(symbolic.rowSym > this->rowSym)
       max = symbolic.rowSym;

   ret.initSym(this->rowSym+symbolic.rowSym, max);

   for(int i = 0; i < ret.rowSym; i++)
       for(int j = 0; j < ret.colSym; j++)
       {
           if( i == this->rowSym)
               ret.var[i+this->rowSym-1][j] = symbolic.var[i-this->rowSym][j];
           else
               ret.var[i][j] = this->var[i][j];
       }

   return ret;
}
Esempio n. 16
0
    bool handleKeyEvent (const Sym &s, bool pressed)
    {
        bool res = false;
        switch ( s.getKey() )
        {
        case Key_Escape: //Quit
            if (!pressed)
            {
                logger << nl << "Quit requested !" << std::endl;

                App::getInstance().requestTermination();
                res=true;
            }
            break;

        case Key_F5: //iconify
            if (pressed)
                App::getInstance().getDisplay().getWindow().iconify();
            res = true;
            break;

        case Key_F6: //FullScreen
            if (pressed)
            {
                App::getInstance().getDisplay().requestSize(640, 480);
                App::getInstance().getDisplay().requestBPP(App::getInstance().getDisplay().getRequestedBPP());
                App::getInstance().getDisplay().requestFullscreen(!App::getInstance().getDisplay().getScreenBuffer().getScreenInfo().isFullscreen());
            }
            res = true;
            break;

        default:
            res = false;
        }

        return res;
    }
Esempio n. 17
0
inline bool specialTerminalIsAnnotation(Sym specialTerminal) {
  assert(specialTerminal.type() == kSpecialTerminal);
  return !isFstComposeSpecial(specialTerminal);
}
Esempio n. 18
0
inline bool isAnnotation(Sym sym) {
  return sym.type() == kSpecialTerminal && !isFstComposeSpecial(sym);
}
Esempio n. 19
0
/**
   Returns true if terminal but not epsilon or phi
   etc.
 */
inline bool isConsuming(Sym sym) {
  return sym.isTerminal() && !(sym == EPSILON::ID || sym == PHI::ID);
}
Esempio n. 20
0
inline void writeLabel(Util::StringBuilder& out, Sym sym, IVocabulary const& voc, SymbolQuotation quote = kQuoted) {
  writeLabel(out, voc.str(sym), sym.isLexical() ? quote : kUnquoted);
}
Esempio n. 21
0
inline void writeLabel(std::ostream& out, Sym sym, IVocabulary const& voc, SymbolQuotation quote = kQuoted) {
  writeLabel(out, voc.str(sym), sym.isLexical() ? quote : kUnquoted);
}
Esempio n. 22
0
File: Sym.hpp Progetto: graehl/hyp
 inline void operator-=(Sym delta) {
   assert(delta.type() == type());
   operator-=(delta.index());
 }
Esempio n. 23
0
bool ResidentVocabulary::_containsSym(Sym symId) const {
  return getVocab(symId.type()).containsSym(symId);
}
Esempio n. 24
0
 bool boundsSym(Sym sym) const { return sym.index() < offset_ + symbols_.size(); }
Esempio n. 25
0
void initSymbols(int idx)
      {
      if (symbolsInitialized[idx])
            return;
      symbolsInitialized[idx] = true;
      symbols[idx] = QVector<Sym>(lastSym);

      symbols[idx][clefEightSym] = Sym(0x38, 2);
      symbols[idx][clefOneSym]   = Sym(0x31, 2);
      symbols[idx][clefFiveSym]  = Sym(0x35, 2);
      symbols[idx][letterTSym]   = Sym('T',  2);
      symbols[idx][letterSSym]   = Sym('S',  2);
      symbols[idx][letterPSym]   = Sym('P',  2);

      QString path;
#ifdef Q_OS_IOS
      {
      extern QString resourcePath();
      QString rpath = resourcePath();
      path = rpath + QString(idx == 0 ? "/mscore20.xml" : "/mscore/gonville.xml");
      }
#else
      path = idx == 0 ? ":/fonts/mscore20.xml" : ":/fonts/gonville.xml";
#endif
      QFile f(path);
      if (!f.open(QFile::ReadOnly)) {
            qDebug("cannot open symbols file %s", qPrintable(path));
            if (!MScore::debugMode)
                  exit(-1);
            }
      XmlReader e(&f);
      int fid = idx == 0 ? 0 : 3;

      while (e.readNextStartElement()) {
            if (e.name() == "museScore") {
                  while (e.readNextStartElement()) {
                        if (e.name() == "Glyph") {
                              QString name;
                              int code = -1;
                              QPointF p;
                              QRectF b;
                              while (e.readNextStartElement()) {
                                    const QStringRef& tag(e.name());
                                    if (tag == "name")
                                          name = e.readElementText();
                                    else if (tag == "code") {
                                          QString val(e.readElementText());
                                          bool ok;
                                          code = val.mid(2).toInt(&ok, 16);
                                          if (!ok)
                                                qDebug("cannot read code");
                                          }
                                    else if (tag == "attach")
                                          p = e.readPoint();
                                    else if (tag == "bbox")
                                          b = e.readRect();
                                    else
                                          e.unknown();
                                    }
                              if (code == -1)
                                    qDebug("no code for glyph <%s>", qPrintable(name));
                              SymId idx1 = Sym::name2id(name);
                              if (idx1 != noSym)
                                    symbols[idx][idx1] = Sym(code, fid, p, b);
                              else {
                                    qDebug("symbol <%s> declared in %s for symbol set %d not used",
                                       qPrintable(name), qPrintable(path), idx);
                                    }
                              }
                        else
                              e.unknown();
                        }
                  }
            else
                  e.unknown();
            }
      for (int i = 0; i < lastSym; ++i) {
            Sym* sym = &symbols[idx][i];
            if (sym->code() == -1) {
                  qDebug("no code for symbol %s", Sym::id2name(SymId(i)));
                  if (idx > 0) {
                        //fallback to default font
                        symbols[idx][i] = symbols[0][i];
                        }
                  }
            }
      }
Esempio n. 26
0
bool ResidentVocabulary::_boundsSym(Sym symId) const {
  return getVocab(symId.type()).boundsSym(symId);
}
Esempio n. 27
0
inline BlockId blockIndexForStart(Sym sym) {
  assert(isBlockStartSymbol(sym));
  return sym.id() - BLOCK_START::ID.id();
}
Esempio n. 28
0
SyntaxNode* ActionSymbol::Invoke(const std::vector<void*>& container) {
	Sym* sym = (Sym*)container[container.size() - argument_.parameters.front()];
	SyntaxNode* ans = new SyntaxNode(SyntaxNodeSymbol, sym->ToString());
	ans->SetSymbolAddress(sym);
	return ans;
}
Esempio n. 29
0
File: Sym.hpp Progetto: graehl/hyp
 /*
     "constructor" (static factory method).
  *
     Given an unsignedeger, a bit-mask indicating the type,
     this method verifies that the id is within range and creates
     an instance of Sym of the correct type.
  *
     This method should only be used by the Vocabulary and in unit tests.
  *
     @param identifier, the id.
     @param type, a bitmask identifying the type of the symbol.
  */
 static inline Sym createSym(SymInt index, SymbolType type) {
   Sym id;
   id.set(index, type);
   return id;
 }
Esempio n. 30
0
 bool containsSym(Sym sym) const {
   assert(sym.type() == type_);
   SymInt index = sym.index();
   assert(index >= offset_);
   return index - offset_ < symbols_.size();
 }