Example #1
0
void printPatchListWithLineNumbers(patchList l) {
    l = inversion(l);
    char string[512];
    int i = 0, iIn = 0, iOut = 0;
    
//    “+ k\n” Ajout : la ligne suivante dans le patch est ajoutée sur le flot de sortie après la ligne k du flot d’entrée. Si k = 0, la ligne est insérée avant la première ligne (numérotée 1) du flot d’entrée.
//    “= k\n” Substitution : la ligne k du flot d’entrée est remplacée sur le flot de sortie par la ligne suivante dans le patch.
//    “d k\n” Destruction : la ligne k du flot d’entrée n’est pas recopiée sur le flot de sortie.
    
    while (l != NULL) {
		//printf("iIn: %d, iOut: %d\n", iIn, iOut);
        
        switch (l->op) {
            case ADD:
                i++;
                printf("%d + %d\n",i, iIn);
                
                iOut++;
                i++;
                
                getOutLine(string, iOut);
                printf("%d %s\n", i, string);
                break;
                
            case DEL:
                i++;
                printf("%d - %d\n",i, iIn+1);
                
                iIn++;
                break;
                
            case SUBST:
                i++;
                printf("%d = %d\n", i, iIn+1);
                
                iIn++;
                iOut++;
                i++;
                getOutLine(string, iOut);
                printf("%d %s\n", i, string);
                break;
                
            case COPY:
                iIn++;
                iOut++;
                break;
        }
		l = l->next;
    }
}
Example #2
0
void
ZDriver::emitValue( const Producer::ValueSetting	&val,
					std::ostream					&out )
{
	if ( ! val.first.empty() )
	{
		emitLineInfo( getSourceFile(), val.second, out );
		out << val.first << endl();
		myCurLineNum += std::count_if( val.first.begin(), val.first.end(),
									   std::bind2nd( std::equal_to<char>(), '\n' ) );
		emitLineInfo( myFileName, getOutLine(), out );
	}
}
Example #3
0
void
ZDriver::emitRule( const Rule *rp, std::ostream &out )
{
	std::string rpCode = rp->getCode();
	std::string::size_type curPos;
	int codeLine = rp->getCodeLine();

	while ( rpCode[0] == ' ' || rpCode[0] == '\t' || rpCode[0] == '\n' )
	{
		if ( rpCode[0] == '\n' )
			++codeLine;
		rpCode.erase( rpCode.begin() );
	}

	emitLineInfo( getSourceFile(), codeLine, out );

	const Rule::RHSList &rhs = rp->getRHS();
	Rule::RHSListConstIter ri, re;

	if ( ! rpCode.empty() )
	{
		curPos = 0;
		rpCode.insert( curPos, "            " );
		while ( curPos != std::string::npos )
		{
			curPos = rpCode.find( '\n', curPos );
			if ( curPos != std::string::npos )
			{
				incOutLine();
				++curPos;
				rpCode.insert( curPos, "        " );
			}
		}

		while ( rpCode[rpCode.size() - 1] == ' ' ||
				rpCode[rpCode.size() - 1] == '\t' )
			rpCode.erase( rpCode.end() - 1 );

		std::string replStr = "Util::any_cast< ";
		Symbol *lhsSym = SymbolTable::get()->find( rp->getLHS() );
		replStr.append( lhsSym->getDataType() );
		replStr.append( " >( data )" );
		substCode( rpCode, rp->getLHSAlias(), replStr, true,
				   lhsSym->getDataType() );

		const std::string &tokenType = getValue( "token_type" ).first;
		
		for ( ri = rhs.begin(), re = rhs.end(); ri != re; ++ri )
		{
			Symbol *sp = SymbolTable::get()->find( (*ri).first );
			const std::string &dataType = sp->getDataType();
			std::ostringstream tmpOut;
			
			replStr = "Util::any_cast< ";
			if ( Symbol::NONTERMINAL == sp->getType() && ! dataType.empty() )
				replStr.append( dataType );
			else
				replStr.append( tokenType );
			replStr.append( " >( rhsData[" );
			tmpOut << ( ri - rhs.begin() );
			replStr.append( tmpOut.str() );
			replStr.append( "] )" );

			substCode( rpCode, (*ri).second, replStr );
		}

		out << rpCode;
	}

	emitLineInfo( myFileName, getOutLine(), out );

	for ( ri = rhs.begin(), re = rhs.end(); ri != re; ++ri )
	{
		Symbol *sp = SymbolTable::get()->find( (*ri).first );
		if ( (*ri).second.empty() )
		{
			out << "            callDtor( " << sp->getIndex()
				<< ", rhsData[" << ( ri - rhs.begin() )
				<< "] );" << endl();
		}
	}
}