inline void SStringTokenizer::RegularExpressionize()
{
	SString exp = m_delimeters;
	exp.Prepend("[^");
	exp.Append("]+");
	m_regexp.SetTo(exp);
}
Esempio n. 2
0
    void CombinePath(SString &pathA,
                     SString &pathB,
                     SString &combinedPath)
    {
        BINDER_LOG_ENTER(W("Utils::CombinePath"));

        BINDER_LOG_STRING(W("path A"), pathA);
        BINDER_LOG_STRING(W("path B"), pathB);

        SString platformPathSeparator(SString::Literal, GetPlatformPathSeparator());
        combinedPath.Set(pathA);
        
        if (!combinedPath.EndsWith(platformPathSeparator))
        {
            combinedPath.Append(platformPathSeparator);
        }
        
        combinedPath.Append(pathB);
        
        BINDER_LOG_LEAVE(W("Utils::CombinePath"));
    }
Esempio n. 3
0
//*****************************************************************************
// This function will handle ignore codes and tell the user what is happening.
//*****************************************************************************
bool _DbgBreakCheck(
    LPCSTR      szFile,
    int         iLine,
    LPCSTR      szExpr, 
    BOOL        fConstrained)
{
    STATIC_CONTRACT_THROWS;
    STATIC_CONTRACT_GC_NOTRIGGER;
    STATIC_CONTRACT_FORBID_FAULT;
    STATIC_CONTRACT_DEBUG_ONLY;

    RaiseExceptionOnAssert(rTestAndRaise);

    if (DebugBreakOnAssert())
    {
        DebugBreak();
    }

    DBGIGNORE* pDBGIFNORE = GetDBGIGNORE();
    _DBGIGNOREDATA *psData;
    int i;

    // Check for ignore all.
    for (i = 0, psData = pDBGIFNORE->Ptr();  i < pDBGIFNORE->Count();  i++, psData++)
    {
        if (psData->iLine == iLine && SString::_stricmp(psData->rcFile, szFile) == 0 && psData->bIgnore == true)
        {
            return false;
        }
    }

    CONTRACT_VIOLATION(FaultNotFatal | GCViolation | TakesLockViolation);
    
    SString debugOutput;
    SString dialogOutput;
    SString modulePath;
    SString dialogTitle;
    SString dialogIgnoreMessage;
    BOOL formattedMessages = FALSE;
    
    // If we are low on memory we cannot even format a message. If this happens we want to
    // contain the exception here but display as much information as we can about the exception.
    if (!fConstrained) 
    {
        EX_TRY
        {
            ClrGetModuleFileName(0, modulePath);
            debugOutput.Printf(
                W("\nAssert failure(PID %d [0x%08x], Thread: %d [0x%04x]): %hs\n")
                W("    File: %hs Line: %d\n")
                W("    Image: "),
                GetCurrentProcessId(), GetCurrentProcessId(),
                GetCurrentThreadId(), GetCurrentThreadId(),
                szExpr, szFile, iLine);
            debugOutput.Append(modulePath);
            debugOutput.Append(W("\n\n"));
         
            // Change format for message box.  The extra spaces in the title
            // are there to get around format truncation.
            dialogOutput.Printf(
                W("%hs\n\n%hs, Line: %d\n\nAbort - Kill program\nRetry - Debug\nIgnore - Keep running\n")
                W("\n\nImage:\n"), szExpr, szFile, iLine);
            dialogOutput.Append(modulePath);
            dialogOutput.Append(W("\n"));
            dialogTitle.Printf(W("Assert Failure (PID %d, Thread %d/0x%04x)"),
                GetCurrentProcessId(), GetCurrentThreadId(), GetCurrentThreadId());
            
            dialogIgnoreMessage.Printf(W("Ignore the assert for the rest of this run?\nYes - Assert will never fire again.\nNo - Assert will continue to fire.\n\n%hs\nLine: %d\n"),
                szFile, iLine);

            formattedMessages = TRUE;
        }
        EX_CATCH
        {            
        }
        EX_END_CATCH(SwallowAllExceptions);
    }
SString
TypeToCPPType(const InterfaceRec* rec, const sptr<IDLType>& obj, bool asConst)
{
	// Convert IDLType into a C++ type name
	// rec can be NULL if we are writing the type inside the class, otherwise
	// it must point to the owning class (for typedefs)

	SString	cpptype = obj->GetName();

	if (cpptype==NULL) {
		bout << "<----- outpututil.cpp -----> invalid type when converting to CPP;"  << endl;
		_exit(1);
	}
	else {		
		// Binder Types
		// IClass* -> sptr<IClass>
		// [weak] IClass* -> wptr<IClass>
		// (both of these types have the name of "sptr")
		if (cpptype=="sptr") {
			if (obj->HasAttribute(kWeak) == true) {
				cpptype = "wptr";
			}
			InterfaceRec* iface=FindInterface(obj->GetIface());				
			cpptype.Append("<");
			if (iface->ID()== "Binder") { cpptype.Append("I"); }
			cpptype.Append(iface->ID());
			cpptype.Append(">");
			if (asConst) {
				cpptype.Prepend("const ");
				cpptype.Append("&");
			}

		} 
		else if ((cpptype=="SString") || (cpptype=="SValue") || (cpptype=="SMessage")) {
			if (asConst) {
				cpptype.Prepend("const ");
				cpptype.Append("&");
			}
		} 
		else if (cpptype=="char*") {
			if (asConst) {			
				// in the rare case this is a const char*
				cpptype.Prepend("const ");
			}
			else {
				cpptype="SString";
			}
		} 
		else if (cpptype=="void") {
			;	// cpptype is fine as is
		} 
		else {

			// deal with typedefs...
			// If the stored type is different than the object type, then
			// we have a user defined typedef... 
			// add in the class name as a qualifier, because they are defined
			// inside the IClass definition.
			sptr<IDLType> storedtype=FindType(obj);
			if (storedtype->GetName() != obj->GetName() && rec != kInsideClassScope) {
				SString classQualifier = rec->ID();
				classQualifier.Append("::");
				cpptype.Prepend(classQualifier);
			}
			if (asConst) {
				uint32_t code = storedtype->GetCode();
				if (code == B_WILD_TYPE || code == B_VARIABLE_ARRAY_TYPE) {
					// If B_WILD_TYPE then we have an exported type
					// that we really don't know about, or
					// if B_VARIABLE_ARRAY_TYPE, then we have a sequence
					// typedef.  Both of which want const references
					// for input parameters.
					cpptype.Prepend("const ");
					cpptype.Append("&");
				}
			}	
		}
	}

	return cpptype;
}
SString 
FromSValueExpression(const InterfaceRec* rec,
					 const sptr<IDLType>& vartype,
					 const SString& varname,
					 const SString& valuename,
					 ExpressionKind kind,
					 bool setError)
{
	// Create the appropriate expression for converting from an SValue
	// We do this here, so we don't have to special case the code all over OutputCPP.cpp
	// There are 8 different places where FromSValueConversion is called,
	// all just slightly different than the other.
	// However, they can be grouped into the following categories:
	//	INITIALIZE,				// BClass v = BClass(value, &err);
	//	ASSIGN,					// arg = BClass(value, &err);
	//	INDIRECT_ASSIGN,		// *arg = BClass(value, &err);
	//	RETURN					// return BClass(value, &err);

	//	sequences, which are handled in C++ as SVector must be treated differently.
	//	INITIALIZE,				// VectorClass v; v.SetFromValue(value, &err);
	//	ASSIGN,					// arg.SetFromValue(value, &err);
	//	INDIRECT_ASSIGN,		// arg->SetFromValue(value, &err);
	//	RETURN					// return VectorClass(value, &err);

	SString expr;
	sptr<IDLType> storedtype=FindType(vartype);
	if (storedtype->GetCode() != B_VARIABLE_ARRAY_TYPE) {
		switch (kind) {
			case INITIALIZE:
				{
				expr.Append(TypeToCPPType(rec, vartype, false));
				expr.Append(" ");
				expr.Append(varname);
				expr.Append(kAssignStr);
				break;
				}
			case ASSIGN:
				expr.Append(varname);
				expr.Append(kAssignStr);
				break;
			case INDIRECT_ASSIGN:
				expr.Append("*");
				expr.Append(varname);
				expr.Append(kAssignStr);
				break;
			case RETURN:
				expr.Append("return ");
				break;
		}
	}
	else {
		// The SFlattenable signature for SetFromValue doesn't set any errors, just returns them
		setError = false;
		switch (kind) {
			case INITIALIZE:
				// VectorClass v; v.SetFromValue(value, &err);
				expr.Append(TypeToCPPType(rec, vartype, false));
				expr.Append(" ");
				expr.Append(varname);
				expr.Append(";\n");
				expr.Append(varname);
				expr.Append(".");
				break;
			case ASSIGN:
				// arg.SetFromValue(value, &err);
				expr.Append(varname);
				expr.Append(".");
				break;
			case INDIRECT_ASSIGN:
				// arg->SetFromValue(value, &err);
				expr.Append(varname);
				expr.Append("->");
				break;
			case RETURN:
				// VectorClass rv; rv.SetFromValue(value, &err); return rv;
				expr.Append(TypeToCPPType(rec, vartype, false));
				expr.Append(" ");
				expr.Append(varname);
				expr.Append(";\n");
				expr.Append(varname);
				expr.Append(".");
				// ... to be continued after FromSValueConversion
				break;
		}
	}
	expr.Append(FromSValueConversion(vartype, valuename, setError));
	expr.Append(";");
	if (storedtype->GetCode() == B_VARIABLE_ARRAY_TYPE && kind == RETURN) {
		expr.Append("\nreturn ");
		expr.Append(varname);
		expr.Append(";");
	}
	return expr;
}
Esempio n. 6
0
    StringLexer::LEXEME_TYPE
    StringLexer::ParseString(SString &currentString, BOOL fPermitUnescapedQuotes)
    {
        BOOL fIsFirstCharacter = TRUE;
        WCHAR wcCurrentChar = INVALID_CHARACTER;
        WCHAR wcOpeningQuote = INVALID_CHARACTER;

        currentString.Clear();

        // Read until we find another lexeme that's not a string character
        for (;;)
        {
            BOOL fIsEscaped = FALSE;
            wcCurrentChar = PopCharacter(&fIsEscaped);

            if (wcCurrentChar == INVALID_CHARACTER)
            {
                // Found invalid character encoding
                BINDER_LOG(L"StringLexer::ParseString: Invalid character encoding");
                return LEXEME_TYPE_INVALID;
            }

            if (IsEOS(wcCurrentChar))
            {
                if (IsQuoteCharacter(wcOpeningQuote))
                {
                    // EOS and unclosed quotes is an error
                    BINDER_LOG(L"StringLexer::ParseString: EOS and unclosed quotes");
                    return LEXEME_TYPE_INVALID;
                }
                else
                {
                    // Reached end of input and therefore of string
                    break;
                }
            }

            if (fIsFirstCharacter)
            {
                fIsFirstCharacter = FALSE;

                // If first character is quote, then record its quoteness
                if (IsQuoteCharacter(wcCurrentChar))
                {
                    wcOpeningQuote = wcCurrentChar;
                    continue;
                }
            }
            
            if (wcCurrentChar == wcOpeningQuote)
            {
                // We've found the closing quote for a quoted string
                break;
            }
           
            if (!fPermitUnescapedQuotes && !fIsEscaped && IsQuoteCharacter(wcCurrentChar) && !IsQuoteCharacter(wcOpeningQuote))
            {
                // Unescaped quotes in the middle of the string are an error
                BINDER_LOG(L"StringLexer::ParseString: Quote in the middle of a string");
                return LEXEME_TYPE_INVALID;
            }

            if (IsSeparatorChar(wcCurrentChar) && !IsQuoteCharacter(wcOpeningQuote) && !fIsEscaped)
            {
                // Unescaped separator char terminates the string
                PushCharacter(wcCurrentChar, fIsEscaped);
                break;
            }

            // Add character to current string
            currentString.Append(wcCurrentChar);
        }

        if (!IsQuoteCharacter(wcOpeningQuote))
        {
            // Remove trailing white spaces from unquoted string
            BINDER_LOG(L"StringLexer::ParseString: Trimming string");
            TrimTrailingWhiteSpaces(currentString);
        }

        BINDER_LOG_STRING(L"string", currentString);

        return LEXEME_TYPE_STRING;
    }