void testSymbol() { #if 0 // Operator int i = 0; for(; i < KeywordsCount; ++i) { printf("%s\n", Operators[i]); } #endif // test: isKeyword isLiteral isVar isSemicolon symbol_construct symbol_deconstruct #if 0 // not ok char *symbol[] = {"int", "i", "=", "12", ";"}; for(int i = 0; i < sizeof(symbol) / sizeof(symbol[0]); ++i) { // ok printf("symbol %s : isKeyword:%s isLiteral:%s isVar:%s isSemicolon:%s\n", symbol[i], TO_BOOL_STR(isKeyword(symbol[i])), TO_BOOL_STR(isLiteral(symbol[i])), TO_BOOL_STR(isVar(symbol[i])), TO_BOOL_STR(isSemicolon(symbol[i]))); Symbol *sb = symbol_construct(symbol[i]); if(sb) { // not ok printf("%x %x %x %x \n", IS_KEYWORD(sb->type), IS_LITERAL(sb->type), IS_VAR(sb->type), IS_SEMICOLON(sb->type)); symbol_deconstruct(sb); } } #endif // test: isCharLiteral isStringLiteral isDecNumber isOctNumber isHexNumber isFloatNumer // tes: isDoubleNumber #if 0 // ok int i = 0; const char *strArr[] = {"\'c\'", "\"abc\"", "453", "0453", "781", "a90", "0x34", "0X56", "9.34", "9.4e2", "9.5E5", "9e+2", "9e-3", "9.34f", "9.34F" }; for(; i < sizeof(strArr) / sizeof(strArr[0]); ++i) { printf("%s: isCharLiteral(%s)\n\t", strArr[i], TO_BOOL_STR(isCharLiteral(strArr[i]))); printf("isStringLiteral(%s)\n\t", TO_BOOL_STR(isStringLiteral(strArr[i]))); printf("isDecNumber(%s)\n\t", TO_BOOL_STR(isDecNumber(strArr[i]))); printf("isOctNumber(%s)\n\t", TO_BOOL_STR(isOctNumber(strArr[i]))); printf("isHexNumber(%s)\n\t", TO_BOOL_STR(isHexNumber(strArr[i]))); printf("isFloatNumber(%s)\n\t", TO_BOOL_STR(isFloatNumber(strArr[i]))); printf("isDoubleNumber(%s)\n", TO_BOOL_STR(isDoubleNumber(strArr[i]))); } /* // I don't know why, but it can't output all strings for(; i < sizeof(strArr) / sizeof(strArr[0]); ++i) { printf("%s: isCharLiteral(%s)\n\t isStringLiteral(%s)\n\t isDecNumber(%s)\n\t isOctNumber(%s)\n\t isHexNumber(%s)\n\t isFloatNumber(%s)\n\t isDoubleNumber(%s)\n", strArr[i], TO_BOOL_STR(isCharLiteral(strArr[i])), TO_BOOL_STR(isStringLiteral(strArr[i])), TO_BOOL_STR(isDecNumber(strArr[i])), TO_BOOL_STR(isOctNumber(strArr[i])), TO_BOOL_STR(isHexNumber(strArr[i])), TO_BOOL_STR(isFloatNumber(strArr[i])), TO_BOOL_STR(isDoubleNumber(strArr[i]))); } */ #endif }
UString JSImmediate::toString(JSValuePtr v) { ASSERT(isImmediate(v)); if (isIntegerNumber(v)) return UString::from(getTruncatedInt32(v)); #if USE(ALTERNATE_JSIMMEDIATE) if (isNumber(v)) { ASSERT(isDoubleNumber(v)); double value = doubleValue(v); if (value == 0.0) // +0.0 or -0.0 return "0"; return UString::from(value); } #else ASSERT(!isNumber(v)); #endif if (jsBoolean(false) == v) return "false"; if (jsBoolean(true) == v) return "true"; if (v.isNull()) return "null"; ASSERT(v.isUndefined()); return "undefined"; }
Token_sub_type getTokenSubTypeByName(const char *name) { if(isCharLiteral(name)) return Token_sub_type_char_literal; if(isStringLiteral(name)) return Token_sub_type_str_literal; if(isOctNumber(name)) return Token_sub_type_dec_literal; if(isHexNumber(name)) return Token_sub_type_hex_literal; if(isOctNumber(name)) return Token_sub_type_oct_literal; if(isFloatNumber(name)) return Token_sub_type_float_literal; if(isDoubleNumber(name)) return Token_sub_type_double_literal; return Token_sub_type_err; }
Token_type getTokenTypeByName(const char *name) { if(isKeyword(name)) return Token_type_keyword; if(isCharLiteral(name)) return Token_type_literal; if(isStringLiteral(name)) return Token_type_literal; if(isVar(name)) return Token_type_var; if(isOperator(name)) return Token_type_operator; if(isDecNumber(name) || isHexNumber(name) || isOctNumber(name) || isFloatNumber(name) || isDoubleNumber(name)) return Token_type_num; if(isSemicolon(name)) return Token_type_semicolon; return Token_type_err; }