std::string parsenext() { static const char *special = "()=!|/*+-[]{}%:;,"; if (eof) return ""; while (isspace(*p)) p++; char *start = p; if (!*p) eof = true; else if (isdigit(*p)) { while(isdigit(*p) || *p == '.') p++; } else if (isId(*p)) { while(isId(*p) || isdigit(*p)) p++; } else if (*p == '"') { p++; while (*p && *p++ != '"') ; } else if (index(special, *p)) { p++; } else { printf("[%s:%d] unknown char '%c'\n", __FUNCTION__, __LINE__, *p); exit(-1); } tokval = std::string(start, p); //printf("[%s:%d] TOKEN start %p p %p pchar %x '%s'\n", __FUNCTION__, __LINE__, start, p, *start, tokval.c_str()); return tokval; }
static bool matchExcludedSymbols(const char *name) { static QStrList &exclSyms = Config_getList("EXCLUDE_SYMBOLS"); if (exclSyms.count()==0) return FALSE; // nothing specified const char *pat = exclSyms.first(); QCString symName = name; while (pat) { QCString pattern = pat; bool forceStart=FALSE; bool forceEnd=FALSE; if (pattern.at(0)=='^') pattern=pattern.mid(1),forceStart=TRUE; if (pattern.at(pattern.length()-1)=='$') pattern=pattern.left(pattern.length()-1),forceEnd=TRUE; if (pattern.find('*')!=-1) // wildcard mode { QRegExp re(substitute(pattern,"*",".*"),TRUE); int i,pl; i = re.match(symName,0,&pl); //printf(" %d = re.match(%s) pattern=%s\n",i,symName.data(),pattern.data()); if (i!=-1) // wildcard match { int sl=symName.length(); // check if it is a whole word match if ((i==0 || pattern.at(0)=='*' || (!isId(symName.at(i-1)) && !forceStart)) && (i+pl==sl || pattern.at(i+pl)=='*' || (!isId(symName.at(i+pl)) && !forceEnd)) ) { //printf("--> name=%s pattern=%s match at %d\n",symName.data(),pattern.data(),i); return TRUE; } } } else if (!pattern.isEmpty()) // match words { int i = symName.find(pattern); if (i!=-1) // we have a match! { int pl=pattern.length(); int sl=symName.length(); // check if it is a whole word match if ((i==0 || (!isId(symName.at(i-1)) && !forceStart)) && (i+pl==sl || (!isId(symName.at(i+pl)) && !forceEnd)) ) { //printf("--> name=%s pattern=%s match at %d\n",symName.data(),pattern.data(),i); return TRUE; } } } pat = exclSyms.next(); } //printf("--> name=%s: no match\n",name); return FALSE; }
static void getAsmLine( VBUF *buff ) { char line[256]; if( endOfAsmStmt() ) return; /* reserve at least MAX_INSTR_SIZE bytes in the buffer */ VbufReqd( buff, ((AsmCodeAddress+MAX_INSTR_SIZE) + (MAX_INSTR_SIZE-1)) & ~(MAX_INSTR_SIZE-1) ); AsmCodeBuffer = VbufBuffer( buff ); ensureBufferReflectsCurToken(); if( isId( CurToken ) && strcmp( Buffer, "__emit" ) == 0 ) { strcpy( line, AsmSysDefineByte() ); strcat( line, " " ); NextToken(); ensureBufferReflectsCurToken(); } else { line[0] = '\0'; } for(;;) { if( endOfAsmStmt() ) break; strncat( line, Buffer, sizeof(line)-1 ); switch( CurToken ) { case T_ALT_XOR: case T_ALT_EXCLAMATION: case T_ALT_AND_AND: case T_ALT_OR_OR: strncat( line, " ", sizeof(line)-1 ); break; default: if( isId( CurToken ) ) strncat( line, " ", sizeof(line)-1 ); break; } NextToken(); ensureBufferReflectsCurToken(); } if( line[0] != '\0' ) { AsmLine( line ); } VbufSetLen( buff, AsmCodeAddress ); if( CurToken == T_SEMI_COLON ) { // ; .ASM comment for(;;) { NextToken(); if( CurToken == T_EOF ) break; if( CurToken == T_NULL ) break; } } }
void Attr::setValue(String * newvalue) throw(DOMException) { if (isReadOnly()) throw DOMException(DOMException::NO_MODIFICATION_ALLOWED_ERR); if (newvalue == null) { if (isId()) removeIdRef(); while (text != null) removeChild(text); return; } if (text == null) { text = getOwnerDocument()->createTextNode(newvalue); text->isFirstChild(true); text->previousSibling = text; text->ownerNode = this; text->isOwned(true); addIdRef(); } else { removeIdRef(); while (text->getNextSibling() != null) { removeChild(text->getNextSibling()); } text->setData(newvalue); addIdRef(); } isSpecified(true); }
static QCString convertIndexWordToAnchor(const QString &word) { static char hex[] = "0123456789abcdef"; uint i; QCString result; for (i=0;i<word.length();i++) { int c = word.at(i); if (isId(c)) { result+=c; } else if (isspace(c)) { result+="_"; } else { char cs[3]; cs[0]=hex[c>>4]; cs[1]=hex[c&0xf]; cs[2]=0; result+=cs; } } return result; }
/* fun <id> ( <formals> ) <body> */ static Fun *fun() { if (!isFun()) return 0; consume(); Fun *p = NEW(Fun); if (!isId()) error(); p->name = getId(); consume(); if (!isLeft()) error(); consume(); p->formals = formals(); if (!isRight()) error(); consume(); p->body = statement(); return p; }
int main( int, char**) { try { std::string driverCSVDir = "drivers"; std::string driverCompressedDir = "drivers_compressed_data"; DirectoryListing dirList( driverCSVDir ); std::list<std::string> driverDirs = dirList.directoryContent(); ProcessLogger log( driverDirs.size() ); for ( std::list<std::string>::const_iterator iDriverDir = driverDirs.begin(); iDriverDir != driverDirs.end(); ++iDriverDir ) { int driverId = 0; std::istringstream isId( *iDriverDir ); isId >> driverId; DriverTripDataIO dataIO( driverId ); dataIO.readTripDataFromCSVFiles( driverCSVDir ).writeDataToBinaryFile( driverCompressedDir ); log.taskEnded(); } } catch (std::exception& e) { std::cerr << e.what() << std::endl; return -1; } catch (...) { std::cerr << "Unknown error" << std::endl; return -1; } return 0; }
static QCString escapeId(const char *s) { QCString res=s; char *p=res.rawData(); while (*p) { if (!isId(*p)) *p='_'; p++; } return res; }
bool Attr::setId() { Element * e = getOwnerElement(); if (e == null) return false; if (e->isId(this)) { isId(true); return true; } return false; }
/* handle id, literals, and (...) */ static Expression *e1(void) { if (isLeft()) { /* ( <expression> ) */ consume(); Expression *e = expression(); if (!isRight()) { error(); } consume(); return e; } else if (isInt()) { /* 123 */ int v = getInt(); consume(); Expression *e = NEW(Expression); e->kind = eVAL; e->val = v; return e; } else if (isId()) { /* xyz */ char *id = getId(); consume(); if (isLeft()) { /* xyz ( <actuals> ) */ consume(); Expression *e = NEW(Expression); e->kind = eCALL; e->callName = id; e->callActuals = actuals(); if (!isRight()) error(); consume(); return e; } else { Expression *e = NEW(Expression); e->kind = eVAR; e->varName = id; return e; } } else { error(); return 0; } }
void Attr::setOwnerElement(Element * e) { if (e == null) { if (ownerNode != null) { ownerNode = getOwnerDocument(); isOwned(false); isSpecified(true); isId(false); } } else { if (isOwned()) throw DOMException(DOMException::INUSE_ATTRIBUTE_ERR); ownerNode = e; isOwned(true); setId(); } }
void parse_lib(std::string filename) { int inpfile = open(filename.c_str(), O_RDONLY); if (inpfile == -1) { printf("[%s:%d] unable to open '%s'\n", __FUNCTION__, __LINE__, filename.c_str()); exit(-1); } int len = read(inpfile, buffer, sizeof(buffer)); if (len >= sizeof(buffer) - 1) { printf("[%s:%d] incomplete read of '%s'\n", __FUNCTION__, __LINE__, filename.c_str()); exit(-1); } parsenext(); if (tokval != "library") { printf("[%s:%d] 'library' keyword not found\n", __FUNCTION__, __LINE__); exit(-1); } validate_token(isId(tokval[0]), "name"); parseparam(); parse_item(false, "", nullptr); }
/* [<id> [, <formals>]] */ static Formals *formals() { Formals *p = 0; if (isId()) { p = NEW(Formals); p->first = getId(); consume(); p->n = 1; p->rest = 0; if (isComma()) { consume(); p->rest = formals(); if (p->rest) { p->n = p->rest->n + 1; } } } return p; }
static char *GetId(char *start) { while (isId(start)) start++; return start; }
void parse_item(bool capture, std::string pinName, AttributeList *attr) { while (tokval != "}" && !eof) { std::string paramname = tokval; validate_token(isId(tokval[0]), "name"); if (paramname == "default_intrinsic_fall" || paramname == "default_intrinsic_rise") { validate_token(tokval == ":", ":(paramname)"); if (capture) addAttr(attr, pinName, paramname, tokval); validate_token(isdigit(tokval[0]), "number"); } else if (paramname == "bus_type") { validate_token(tokval == ":", ":(bus_type)"); if (capture) addAttr(attr, pinName, paramname, tokval); validate_token(isId(tokval[0]), "name"); } else if (tokval == "(") { while (tokval == "(") { std::string paramstr = parseparam(); bool cell = paramname == "cell" && paramstr == options.cell; int ind = paramstr.find("["); if (capture && (paramname == "pin" || paramname == "bus")) { if (ind > 0 && paramstr[paramstr.length()-1] == ']') { std::string sub = paramstr.substr(ind+1); sub = sub.substr(0, sub.length()-1); paramstr = paramstr.substr(0, ind); capturePins[paramstr].pins[atol(sub.c_str())] = 1; } parse_item(true, paramstr, &capturePins[paramstr].attr); } else if (paramname == "type") { parse_item(true, "", &busInfo[paramstr].attr); } else parse_item(capture || cell, pinName, attr); //if (paramname == "cell") //printf("[%s:%d] paramname %s paramstr %s \n", __FUNCTION__, __LINE__, paramname.c_str(), paramstr.c_str()); if (cell) { processCell(); return; } paramname = tokval; if (!isId(tokval[0])) break; parsenext(); } } else { validate_token(tokval == ":", ":(other)"); if (capture && paramname != "timing_type") addAttr(attr, pinName, paramname, tokval); if (isdigit(tokval[0]) || isId(tokval[0]) || tokval[0] == '"') parsenext(); else validate_token(false, "number or name or string"); if (tokval != "}") validate_token(tokval == ";", ";"); } } validate_token(tokval == "}", "}"); }
static Statement *statement(void) { if (isId()) { Statement *p = NEW(Statement); p->kind = sAssignment; p->assignName = getId(); consume(); if (!isEq()) error(); consume(); p->assignValue = expression(); if (isSemi()) { consume(); } return p; } else if (isReturn()) { Statement *p = NEW(Statement); p->kind = sReturn; consume(); p->returnValue = expression(); if (isSemi()) { consume(); } return p; } else if (isLeftBlock()) { Statement *p = NEW(Statement); p->kind = sBlock; consume(); p->block = block(); if (!isRightBlock()) error(); consume(); return p; } else if (isPrint()) { Statement *p = NEW(Statement); p->kind = sPrint; consume(); p->printValue = expression(); if (isSemi()) { consume(); } return p; } else if (isIf()) { Statement *p = NEW(Statement); p->kind = sIf; consume(); p->ifCondition = expression(); p->ifThen = statement(); if (isElse()) { consume(); p->ifElse = statement(); } else { p->ifElse = 0; } return p; } else if (isWhile()) { Statement *p = NEW(Statement); p->kind = sWhile; consume(); /* while */ p->whileCondition = expression(); p->whileBody = statement(); return p; } else if (isSemi()) { Statement *p = NEW(Statement); p->kind = sBlock; p->block = 0; consume(); return p; } else { return 0; } }
static int ScanOneLine(unsigned char *line) { char *q,*p = strchr(line,')'); DataPoint d; const DataPoint *old=NULL; size_t typ=0; int t; if (p == NULL) return -1; q = p+1; *p-- = 0; while (*p == ' ' ) p--; while (isId(p)) { p--; } p++; while (*q == ' ') q++; if (*q == '(') q++; else return -1; if (Data == NULL) { Data = iDictionary.Create(sizeof(DataPoint),200); } old = iDictionary.GetElement(Data,p); memset(&d,0,sizeof(d)); t = istrCollection.IndexOf(Exceptions,p,&typ); //printf("%s: t=%d, index %ull\n",p,t,typ); if (t >= 0) { char *save = p; p = line; while (*p == ' ' || *p == '\t') p++; q = GetId(p); *q = 0; t = FindType(p); if (t < 0) { if (strcmp(p,"ElementType")) { return -1; } typ = 3; } else typ = t; if (old == NULL) d.ApiName = strdup(save); } else { if (old ==NULL) d.ApiName = strdup(p); p = q; q = GetId(q); *q=0; if (!strcmp(p,"const")) { q++; while (*q == ' ' || *q == '\t') q++; p = q; q = GetId(q); *q=0; } t = FindType(p); if (t < 0) { if (strcmp(p,"ElementType")) { free(d.ApiName); return -1; } typ = 12; } else typ = t; } if (old) { memcpy(&d,old,sizeof(DataPoint)); } d.type[typ] = typ+1; if (Data == NULL) { Data = iDictionary.Create(sizeof(DataPoint),200); } iDictionary.Add(Data,d.ApiName,&d); return 1; }
void Attr::addIdRef() const { if (isId()) getOwnerDocument()->putIdentifier(getNodeValue(), getOwnerElement()); }
NitLexer::Token NitLexer::lex() { int tk; while (_ch != CHAR_EOS) { whitespace(); switch (_ch) { case CHAR_EOS: return token(TK_EOS); case '/': next(); switch (_ch) { case '*': next(); blockComment(); continue; case '/': lineComment(); continue; case '=': next(); return token(TK_DIVEQ); default: return token('/'); } break; case '=': next(); if (_ch == '>') { next(); return token(TK_LAMBDA); } if (_ch == '=') { next(); return token(TK_EQ); } return token('='); case '<': next(); if (_ch == '<') { next(); return token(TK_SHIFTL); } if (_ch != '=') return token('<'); next(); if (_ch == '>') { next(); return token(TK_THREEWAYSCMP); } return token(TK_LE); case '>': next(); if (_ch == '=') { next(); return token(TK_GE); } if (_ch != '>') return token('>'); next(); if (_ch == '>') { next(); return token(TK_USHIFTR); } return token(TK_SHIFTR); case '!': next(); if (_ch == '=') { next(); return token(TK_NE); } return token('!'); case '@': next(); if (_ch != '"' && _ch != '\'') return token('@'); if ((tk = readString(_ch, '@')) != -1) return token(tk); return error("error parsing verbatim string"); case '"': case '\'': if (readString(_ch) != -1) return token(TK_STRING_VALUE); return error("error parsing the string"); case '{': case '}': case '(': case ')': case '[': case ']': case ';': case ',': case '?': case '^': case '~': case '$': return token(next()); case '.': next(); if (_ch != '.') return token('.'); next(); if (_ch != '.') return error("invalid token '..'"); next(); return token(TK_VARPARAMS); case '&': next(); if (_ch == '&') { next(); return token(TK_AND); } return token('&'); case '|': next(); if (_ch == '|') { next(); return token(TK_OR); } return token('|'); case ':': next(); if (_ch == '=') { next(); return token(TK_NEWSLOT); } if (_ch == '>') { next(); return token(TK_WITHREF); } if (_ch == ':') { next(); return token(TK_DOUBLE_COLON); } return token(':'); case '*': next(); if (_ch == '=') { next(); return token(TK_MULEQ); } return token('*'); case '%': next(); if (_ch == '=') { next(); return token(TK_MODEQ); } return token('%'); case '-': next(); if (_ch == '=') { next(); return token(TK_MINUSEQ); } if (_ch == '-') { next(); return token(TK_MINUSMINUS); } return token('-'); case '+': next(); if (_ch == '=') { next(); return token(TK_PLUSEQ); } if (_ch == '+') { next(); return token(TK_PLUSPLUS); } return token('+'); default: if (isdigit(_ch)) return token(readNumber()); else if (isId(_ch)) return token(readId()); else return error("unexpected character '%c'", _ch); } } return token(TK_EOS); }
void Attr::removeIdRef() const { if (isId()) getOwnerDocument()->removeIdentifier(getNodeValue()); }