AsmCode* AsmCodeNew(char *line) { AsmCode* code = ObjNew(AsmCode,1); char head[MAX_LEN]; strCut(line, "/", head, NULL); Array* tokens = split(head, " \t+[],", REMOVE_SPLITER); if (tokens->count == 0) { ArrayFree(tokens, strFree); ObjFree(code); return NULL; } code->line = strNew(head); strTrim(code->line, code->line, SPACE); code->tokens = tokens; int tokenIdx = 0; if (strTail(tokens->item[0], ":")) { code->label = ArrayGet(tokens, tokenIdx++); strTrim(code->label, code->label, ":"); } else code->label = NULL; code->op = ArrayGet(tokens, tokenIdx++); code->opCode = OP_NULL; code->argStart = tokenIdx; code->arg[0] = ArrayGet(tokens, tokenIdx++); code->arg[1] = ArrayGet(tokens, tokenIdx++); code->arg[2] = ArrayGet(tokens, tokenIdx++); // AsmCodePrintln(code); return code; }
/////////////////////////////////////////////////////////////// // // CResourceChecker::CheckLuaSourceForIssues // // Look for function names not in comment blocks // Note: Ignores quotes // /////////////////////////////////////////////////////////////// void CResourceChecker::CheckLuaSourceForIssues ( string strLuaSource, const string& strFileName, const string& strResourceName, bool bClientScript, bool bCompiledScript, ECheckerModeType checkerMode, string* pstrOutResult ) { CHashMap < SString, long > doneWarningMap; long lLineNumber = 1; // Check if this is a UTF-8 script bool bUTF8 = IsUTF8BOM( strLuaSource.c_str(), strLuaSource.length() ); // If it's not a UTF8 script, does it contain foreign language characters that should be upgraded? if ( !bCompiledScript && !bUTF8 && GetUTF8Confidence ( (const unsigned char*)&strLuaSource.at ( 0 ), strLuaSource.length() ) < 80 ) { std::wstring strUTF16Script = ANSIToUTF16 ( strLuaSource ); #ifdef WIN32 std::setlocale(LC_CTYPE,""); // Temporarilly use locales to read the script std::string strUTFScript = UTF16ToMbUTF8 ( strUTF16Script ); std::setlocale(LC_CTYPE,"C"); #else std::string strUTFScript = UTF16ToMbUTF8 ( strUTF16Script ); #endif if ( strLuaSource.length () != strUTFScript.size() ) { // In-place upgrade... if ( checkerMode == ECheckerMode::UPGRADE ) { // Upgrade only if there is no problem ( setlocale() issue? ) if ( strUTF16Script != L"?" ) { // Convert our script to ANSI, appending a BOM at the beginning strLuaSource = "\xEF\xBB\xBF" + strUTFScript; } } if ( checkerMode == ECheckerMode::WARNINGS ) { m_ulDeprecatedWarningCount++; CLogger::LogPrintf ( "WARNING: %s/%s [%s] is encoded in ANSI instead of UTF-8. Please convert your file to UTF-8.\n", strResourceName.c_str (), strFileName.c_str (), bClientScript ? "Client" : "Server" ); } } } // Step through each identifier in the file. for ( long lPos = 0 ; lPos < (long)strLuaSource.length () ; lPos++ ) { long lNameLength; long lNameOffset = FindLuaIdentifier ( strLuaSource.c_str () + lPos, &lNameLength, &lLineNumber ); if ( lNameOffset == - 1 ) break; lNameOffset += lPos; // Make offset absolute from the start of the file lPos = lNameOffset + lNameLength; // Adjust so the next pass starts from just after this identifier string strIdentifierName( strLuaSource.c_str () + lNameOffset, lNameLength ); // In-place upgrade... if ( checkerMode == ECheckerMode::UPGRADE ) { assert ( !bCompiledScript ); string strUpgraded; if ( UpgradeLuaFunctionName( strIdentifierName, bClientScript, strUpgraded ) ) { // Old head string strHead( strLuaSource.c_str (), lNameOffset ); // Old tail string strTail( strLuaSource.c_str () + lNameOffset + lNameLength ); // New source strLuaSource = strHead + strUpgraded + strTail; lPos += -lNameLength + strUpgraded.length (); } CheckVersionRequirements ( strIdentifierName, bClientScript ); } // Log warnings... if ( checkerMode == ECheckerMode::WARNINGS ) { // Only do the identifier once per file if ( doneWarningMap.find ( strIdentifierName ) == doneWarningMap.end () ) { doneWarningMap[strIdentifierName] = 1; if ( !bCompiledScript ) // Don't issue deprecated function warnings if the script is compiled, because we can't upgrade it IssueLuaFunctionNameWarnings ( strIdentifierName, strFileName, strResourceName, bClientScript, lLineNumber ); CheckVersionRequirements ( strIdentifierName, bClientScript ); } } } if ( pstrOutResult ) *pstrOutResult = strLuaSource; }