示例#1
0
static JILError scanStatement_JCLFile(JCLFile* _this, JCLString* outStr)
{
	JILError err;
	JILLong tokenID;
	JILLong h1, h2, h3;
	JILLong savePos;
	JCLString* pToken = NEW(JCLString);
	JCLClear(outStr);
	h1 = h2 = h3 = 0;
	for(;;) 
	{
		savePos = _this->miLocator;
		err = getToken_JCLFile(_this, pToken, &tokenID);
		if( err )
			break;
		if( !h1 && !h2 && !h3 )
		{
			if( tokenID == tk_semicolon || tokenID == tk_curly_close )
				break;
		}
		TokenToString(_this, tokenID, pToken, outStr);
		switch( tokenID )
		{
			case tk_curly_open: h1++; break;
			case tk_round_open: h2++; break;
			case tk_square_open: h3++; break;
			case tk_curly_close: h1--; break;
			case tk_round_close: h2--; break;
			case tk_square_close: h3--; break;
		}
	}
	_this->miLocator = savePos;
	DELETE(pToken);
	return err;
}
static int ParseOneOf( ParseContext* ctx, ConfigToken* tokens, int sz )
{
	ConfigToken parsed_token = Token_Unknown;
	int i = 0;

	parsed_token = ParseToken( ctx );

	for( i = 0; i < sz; i++ )
	{
		if( parsed_token == tokens[i] ) return tokens[i];
	}

	if( parsed_token != Token_Unknown ) 
	{
		sprintf( error_buffer, "%s: unexpected configuration token: found: '%s', expected one of: %s",
				ERROR_PREFIX, TokenToString( parsed_token ), TokensToString( tokens, sz ) );
	}
	else
	{
		sprintf( error_buffer, "%s: unknown configuration token: '%s', expected one of: %s",
			ERROR_PREFIX, ctx->token, TokensToString( tokens, sz ) );
	}

	return CONFIG_PARSE_ERROR;
}
void BIF_ObjInvoke(ExprTokenType &aResultToken, ExprTokenType *aParam[], int aParamCount)
{
    int invoke_type;
    IObject *obj;
    ExprTokenType *obj_param;

	// Since ObjGet/ObjSet/ObjCall are not publicly accessible as functions, Func::mName
	// (passed via aResultToken.marker) contains the actual flag rather than a name.
	invoke_type = (int)(INT_PTR)aResultToken.marker;

	// Set default return value; ONLY AFTER THE ABOVE.
	aResultToken.symbol = SYM_STRING;
	aResultToken.marker = _T("");
    
    obj_param = *aParam; // aParam[0].  Load-time validation has ensured at least one parameter was specified.
	++aParam;
	--aParamCount;
    
    if (obj = TokenToObject(*obj_param))
	{
		bool param_is_var = obj_param->symbol == SYM_VAR;
		if (param_is_var)
			// Since the variable may be cleared as a side-effect of the invocation, call AddRef to ensure the object does not expire prematurely.
			// This is not necessary for SYM_OBJECT since that reference is already counted and cannot be released before we return.  Each object
			// could take care not to delete itself prematurely, but it seems more proper, more reliable and more maintainable to handle it here.
			obj->AddRef();
        obj->Invoke(aResultToken, *obj_param, invoke_type, aParam, aParamCount);
		if (param_is_var)
			obj->Release();
	}
	// Invoke meta-functions of g_MetaObject.
	else if (INVOKE_NOT_HANDLED == g_MetaObject.Invoke(aResultToken, *obj_param, invoke_type | IF_META, aParam, aParamCount)
		// If above did not handle it, check for attempts to access .base of non-object value (g_MetaObject itself).
		// CALL is unsupported (for simplicity); SET is supported only in "multi-dimensional" mode: "".base[x]:=y
		&& invoke_type != IT_CALL && (invoke_type == IT_SET ? aParamCount > 2 : aParamCount)
		&& !_tcsicmp(TokenToString(*aParam[0]), _T("base")))
	{
		if (aParamCount > 1)	// "".base[x] or similar
		{
			// Re-invoke g_MetaObject without meta flag or "base" param.
			ExprTokenType base_token;
			base_token.symbol = SYM_OBJECT;
			base_token.object = &g_MetaObject;
			g_MetaObject.Invoke(aResultToken, base_token, invoke_type, aParam + 1, aParamCount - 1);
		}
		else					// "".base
		{
			// Return a reference to g_MetaObject.  No need to AddRef as g_MetaObject ignores it.
			aResultToken.symbol = SYM_OBJECT;
			aResultToken.object = &g_MetaObject;
		}
	}
}
int ParseParamGroup( ParseContext* ctx )
{
	ConfigToken ParamTokens[] = { Token_IP, Token_Port, Token_KeyFile, Token_Pwd, Token_PwdFile, Token_RightBrace };
	ConfigToken token = Token_Unknown;
	char token_checks[TOKEN_COUNT];
	int rc = 0; 

	memset( token_checks, 0, sizeof(token_checks) );

	if( MatchToken( ctx, Token_LeftBrace ) == CONFIG_PARSE_ERROR ) return CONFIG_PARSE_ERROR;

	do 
	{
		/* get the parameter */
		token = ParseOneOf( ctx, ParamTokens, ARRAY_SIZE( ParamTokens ) );
		if( token == CONFIG_PARSE_ERROR ) rc = CONFIG_PARSE_ERROR;

		if( rc == 0 && token != Token_RightBrace )
		{
			token_checks[token] = 1;
			/* get the value */
			Advance( ctx );
			if( ctx->token == NULL )
			{
				sprintf( error_buffer, "%s: unexpected EOF found near '%s'", ERROR_PREFIX, TokenToString( token ) );
				rc = CONFIG_PARSE_ERROR;
			}

			/* assign the parameter value */
			if( rc == 0 ) rc = AssignParam( ctx, token, ctx->token );
		}

	} while( rc == 0 && token != Token_RightBrace );

	if( rc == 0 ) 
	{
		/* validate the current server settings */
		if( !token_checks[Token_IP] ) rc = FormatMissingServerParamError( Token_IP );
		if( rc == 0 && !token_checks[Token_KeyFile] ) rc = FormatMissingServerParamError( Token_KeyFile );
		if( rc == 0 && !token_checks[Token_Port] ) rc = FormatMissingServerParamError( Token_Port );

		if( rc == 0 && token_checks[Token_Pwd] && token_checks[Token_PwdFile] )
		{
			sprintf( error_buffer, "%s: Error in server definition: Either 'pwdfile' (recommended) or 'pwd' parameter is expected, but not both",
					ERROR_PREFIX );
			rc = CONFIG_PARSE_ERROR;
		}
	}

	return rc;
}
示例#5
0
void DebugOutput::Write(const ProgramLine& programLine, const AnalyzeResult& result)
{
    outfile << std::setw(3) << std::right << programLine.linenum;
    outfile << '\t' << programLine.line << std::endl;
    for (auto analyzedToken : result.tokens)
    {
        outfile<< "\t\t" << std::setw(16) << TokenToString(analyzedToken.token);
        outfile << analyzedToken.lexeme << std::endl;
        if (analyzedToken.errmsg != "")
        {   
            outfile << analyzedToken.errmsg << std::endl;
        }
    }
}
示例#6
0
static JILError scanBlock_JCLFile(JCLFile* _this, JCLString* outStr)
{
	JILError err;
	JILLong tokenID;
	JILLong startToken;
	JILLong endToken;
	JILLong hier;
	JCLString* pToken = NEW(JCLString);
	JCLClear(outStr);
	err = getToken_JCLFile(_this, pToken, &startToken);
	if( !err && startToken == tk_curly_open || startToken == tk_round_open || startToken == tk_square_open )
	{
		if( startToken == tk_curly_open )
			endToken = tk_curly_close;
		else if( startToken == tk_round_open )
			endToken = tk_round_close;
		else if( startToken == tk_square_open )
			endToken = tk_square_close;
		TokenToString(_this, startToken, pToken, outStr);
		hier = 1;
		do 
		{
			err = getToken_JCLFile(_this, pToken, &tokenID);
			if( err )
				break;
			if( tokenID == startToken )
				hier++;
			else if( tokenID == endToken )
				hier--;
			TokenToString(_this, tokenID, pToken, outStr);
		}
		while( tokenID != endToken && hier > 0 );
	}
	DELETE(pToken);
	return err;
}
/* Scans the next token and checks that it is the one that's expected */
static int MatchToken( ParseContext* ctx, ConfigToken token )
{
	ConfigToken parsed_token;
	
	parsed_token = ParseToken( ctx );

	if( parsed_token != token )
	{
		if( parsed_token != Token_Unknown ) 
		{
			sprintf( error_buffer, "%s: unexpected configuration token: found: '%s', expected: '%s'",
				ERROR_PREFIX, TokenToString( parsed_token ), TokenToString( token ) );
		}
		else
		{
			sprintf( error_buffer, "%s: unknown configuration token: '%s', expected: '%s'",
				ERROR_PREFIX, ctx->token, TokenToString( token ) );
		}

		return CONFIG_PARSE_ERROR;
	}

	return 0;
}
/* Formats a list of tokens to a string */
static const u_char* TokensToString( ConfigToken* tokens, int sz )
{
	static u_char buff[1024];
	int i = 0;

	buff[0] = 0;

	for( i = 0; i < sz; i++ )
	{
		if( i != 0 ) strcat( buff, ", " );
		strcat( buff, "'" );
		strcat( buff, TokenToString( tokens[i] ) );
		strcat( buff, "'" );
	}

	return buff;
}
示例#9
0
void BIF_ObjInvoke(ExprTokenType &aResultToken, ExprTokenType *aParam[], int aParamCount)
{
    int invoke_type;
    IObject *obj;
    ExprTokenType *obj_param;

	// Since ObjGet/ObjSet/ObjCall are not publicly accessible as functions, Func::mName
	// (passed via aResultToken.marker) contains the actual flag rather than a name.
	invoke_type = (int)(INT_PTR)aResultToken.marker;

	// Set default return value; ONLY AFTER THE ABOVE.
	aResultToken.symbol = SYM_STRING;
	aResultToken.marker = _T("");
    
    obj_param = *aParam; // aParam[0].  Load-time validation has ensured at least one parameter was specified.
	++aParam;
	--aParamCount;

	// The following is used in place of TokenToObject to bypass #Warn UseUnset:
	if (obj_param->symbol == SYM_OBJECT)
		obj = obj_param->object;
	else if (obj_param->symbol == SYM_VAR && obj_param->var->HasObject())
		obj = obj_param->var->Object();
	else
		obj = NULL;
    
    if (obj)
	{
		bool param_is_var = obj_param->symbol == SYM_VAR;
		if (param_is_var)
			// Since the variable may be cleared as a side-effect of the invocation, call AddRef to ensure the object does not expire prematurely.
			// This is not necessary for SYM_OBJECT since that reference is already counted and cannot be released before we return.  Each object
			// could take care not to delete itself prematurely, but it seems more proper, more reliable and more maintainable to handle it here.
			obj->AddRef();
        obj->Invoke(aResultToken, *obj_param, invoke_type, aParam, aParamCount);
		if (param_is_var)
			obj->Release();
	}
	// Invoke meta-functions of g_MetaObject.
	else if (INVOKE_NOT_HANDLED == g_MetaObject.Invoke(aResultToken, *obj_param, invoke_type | IF_META, aParam, aParamCount))
	{
		// Since above did not handle it, check for attempts to access .base of non-object value (g_MetaObject itself).
		if (   invoke_type != IT_CALL // Exclude things like "".base().
			&& aParamCount > (invoke_type == IT_SET ? 2 : 0) // SET is supported only when an index is specified: "".base[x]:=y
			&& !_tcsicmp(TokenToString(*aParam[0]), _T("base"))   )
		{
			if (aParamCount > 1)	// "".base[x] or similar
			{
				// Re-invoke g_MetaObject without meta flag or "base" param.
				ExprTokenType base_token;
				base_token.symbol = SYM_OBJECT;
				base_token.object = &g_MetaObject;
				g_MetaObject.Invoke(aResultToken, base_token, invoke_type, aParam + 1, aParamCount - 1);
			}
			else					// "".base
			{
				// Return a reference to g_MetaObject.  No need to AddRef as g_MetaObject ignores it.
				aResultToken.symbol = SYM_OBJECT;
				aResultToken.object = &g_MetaObject;
			}
		}
		else
		{
			// Since it wasn't handled (not even by g_MetaObject), maybe warn at this point:
			if (obj_param->symbol == SYM_VAR)
				obj_param->var->MaybeWarnUninitialized();
		}
	}
}
static int FormatMissingServerParamError( ConfigToken token )
{
	sprintf( error_buffer, "%s: Error in server definition: parameter '%s' is missing", ERROR_PREFIX, TokenToString( token ) );
	return CONFIG_PARSE_ERROR;
}