Пример #1
0
/***************************************************************
* Function: LoopStmt::toString()
* Purpose : Generate a text representation of this IIR node
* Initial : Maxime Chevalier-Boisvert on November 12, 2008
****************************************************************
Revisions and bug fixes:
*/
std::string LoopStmt::toString() const
{
	// Declare a string to the output
	std::string output;
	
	// Add the init sequence to the output
	output += m_pInitSeq->toString();
	
	// Add the "while" keyword and an always true condition to the output
	output += "while True\n";
	
	// Add the test sequence to the string
	output += indentText(m_pTestSeq->toString());
	
	// Indent and add the loop test condition to the string
	output += indentText("if ~" + m_pTestVar->toString() + "\n" + indentText("break;\n") + "end\n");  
	
	// Indent and add the loop body text
	output += indentText(m_pBodySeq->toString());
	
	// Indent and add the incrementation sequence to the string
	output += indentText(m_pIncrSeq->toString());
	
	// Add the "end" keyword to the string
	output += "end";	
	
	// Return the output
	return output;
}
Пример #2
0
/***************************************************************
* Function: IfElseStmt::toString()
* Purpose : Generate a text representation of this IIR node
* Initial : Maxime Chevalier-Boisvert on November 6, 2008
****************************************************************
Revisions and bug fixes:
*/
std::string IfElseStmt::toString() const
{
	// Declare a string to the output
	std::string output;
	
	// Add the "if" keyword and the condition to the string
	output += "if " + m_pCondition->toString() + "\n";
	
	// Indent and add the if block text
	output += indentText(m_pIfBlock->toString());
	
	// If there is an else block
	if (m_pElseBlock)
	{
		// Add the "else" keyword to the string
		output += "else\n";
	
		// Indent and add the else block text
		output += indentText(m_pElseBlock->toString());
	}
	
	// Add the "end" keyword to the string
	output += "end";
	
	// Return the output
	return output;
}
void LineWidth::updateAvailableWidth(LayoutUnit replacedHeight)
{
    LayoutUnit height = m_block.logicalHeight();
    LayoutUnit logicalHeight = m_block.minLineHeightForReplacedObject(m_isFirstLine, replacedHeight);
    m_left = m_block.logicalLeftOffsetForLine(height, indentText(), logicalHeight).toFloat();
    m_right = m_block.logicalRightOffsetForLine(height, indentText(), logicalHeight).toFloat();

    computeAvailableWidthFromLeftAndRight();
}
Пример #4
0
void LineWidth::shrinkAvailableWidthForNewFloatIfNeeded(
    const FloatingObject& newFloat) {
  LayoutUnit height = m_block.logicalHeight();
  if (height < m_block.logicalTopForFloat(newFloat) ||
      height >= m_block.logicalBottomForFloat(newFloat))
    return;

  ShapeOutsideDeltas shapeDeltas;
  if (ShapeOutsideInfo* shapeOutsideInfo =
          newFloat.layoutObject()->shapeOutsideInfo()) {
    LayoutUnit lineHeight = m_block.lineHeight(
        m_isFirstLine,
        m_block.isHorizontalWritingMode() ? HorizontalLine : VerticalLine,
        PositionOfInteriorLineBoxes);
    shapeDeltas = shapeOutsideInfo->computeDeltasForContainingBlockLine(
        m_block, newFloat, m_block.logicalHeight(), lineHeight);
  }

  if (newFloat.getType() == FloatingObject::FloatLeft) {
    LayoutUnit newLeft = m_block.logicalRightForFloat(newFloat);
    if (shapeDeltas.isValid()) {
      if (shapeDeltas.lineOverlapsShape()) {
        newLeft += shapeDeltas.rightMarginBoxDelta();
      } else {
        // Per the CSS Shapes spec, If the line doesn't overlap the shape, then
        // ignore this shape for this line.
        newLeft = m_left;
      }
    }
    if (indentText() == IndentText && m_block.style()->isLeftToRightDirection())
      newLeft += floorToInt(m_block.textIndentOffset());
    m_left = std::max(m_left, newLeft);
  } else {
    LayoutUnit newRight = m_block.logicalLeftForFloat(newFloat);
    if (shapeDeltas.isValid()) {
      if (shapeDeltas.lineOverlapsShape()) {
        newRight += shapeDeltas.leftMarginBoxDelta();
      } else {
        // Per the CSS Shapes spec, If the line doesn't overlap the shape, then
        // ignore this shape for this line.
        newRight = m_right;
      }
    }
    if (indentText() == IndentText &&
        !m_block.style()->isLeftToRightDirection())
      newRight -= floorToInt(m_block.textIndentOffset());
    m_right = std::min(m_right, newRight);
  }

  computeAvailableWidthFromLeftAndRight();
}
Пример #5
0
void TestResult::printFailure(bool printTestName) const {
  if (failures_.empty()) {
    return;
  }

  if (printTestName) {
    printf("* Detail of %s test failure:\n", name_.c_str());
  }

  // Print in reverse to display the callstack in the right order
  Failures::const_iterator itEnd = failures_.end();
  for (Failures::const_iterator it = failures_.begin(); it != itEnd; ++it) {
    const Failure& failure = *it;
    std::string indent(failure.nestingLevel_ * 2, ' ');
    if (failure.file_) {
      printf("%s%s(%d): ", indent.c_str(), failure.file_, failure.line_);
    }
    if (!failure.expr_.empty()) {
      printf("%s\n", failure.expr_.c_str());
    } else if (failure.file_) {
      printf("\n");
    }
    if (!failure.message_.empty()) {
      std::string reindented = indentText(failure.message_, indent + "  ");
      printf("%s\n", reindented.c_str());
    }
  }
}
Пример #6
0
void LineWidth::fitBelowFloats(bool isFirstLine) {
  ASSERT(!m_committedWidth);
  ASSERT(!fitsOnLine());
  m_block.positionNewFloats(m_block.logicalHeight(), this);

  LayoutUnit floatLogicalBottom;
  LayoutUnit lastFloatLogicalBottom = m_block.logicalHeight();
  LayoutUnit newLineWidth = m_availableWidth;
  LayoutUnit newLineLeft = m_left;
  LayoutUnit newLineRight = m_right;

  FloatingObject* lastFloatFromPreviousLine =
      m_block.lastFloatFromPreviousLine();
  if (lastFloatFromPreviousLine &&
      lastFloatFromPreviousLine->layoutObject()->shapeOutsideInfo())
    return wrapNextToShapeOutside(isFirstLine);

  while (true) {
    floatLogicalBottom =
        m_block.nextFloatLogicalBottomBelow(lastFloatLogicalBottom);
    if (floatLogicalBottom <= lastFloatLogicalBottom)
      break;

    newLineWidth = availableWidthAtOffset(
        m_block, floatLogicalBottom, indentText(), newLineLeft, newLineRight);
    lastFloatLogicalBottom = floatLogicalBottom;

    if (newLineWidth >= m_uncommittedWidth)
      break;
  }
  updateLineDimension(lastFloatLogicalBottom, LayoutUnit(newLineWidth),
                      newLineLeft, newLineRight);
}
Пример #7
0
void LineWidth::wrapNextToShapeOutside(bool isFirstLine) {
  LayoutUnit lineHeight = m_block.lineHeight(
      isFirstLine,
      m_block.isHorizontalWritingMode() ? HorizontalLine : VerticalLine,
      PositionOfInteriorLineBoxes);
  LayoutUnit lineLogicalTop = m_block.logicalHeight();
  LayoutUnit newLineTop = lineLogicalTop;
  LayoutUnit floatLogicalBottom =
      m_block.nextFloatLogicalBottomBelow(lineLogicalTop);

  LayoutUnit newLineWidth;
  LayoutUnit newLineLeft = m_left;
  LayoutUnit newLineRight = m_right;
  while (true) {
    newLineWidth =
        availableWidthAtOffset(m_block, newLineTop, indentText(), newLineLeft,
                               newLineRight, lineHeight);
    if (newLineWidth >= m_uncommittedWidth)
      break;

    if (newLineTop >= floatLogicalBottom)
      break;

    newLineTop++;
  }
  updateLineDimension(newLineTop, LayoutUnit(newLineWidth), newLineLeft,
                      newLineRight);
}
Пример #8
0
void
TextFrame::print()
{
    qDebug("%stext: %.2f,%.2f %.2fx%.2f (%s)", indentText(), _x.toDouble(),
	   _y.toDouble(), _width.toDouble(), _height.toDouble(),
	   text().latin1());
}
Пример #9
0
	//! Generate the debug log event for this set
	void Compiler::CodeGenerator::visitDebugLog(const EventActionsSet& eventActionsSet, unsigned currentBlock)
	{
		wstring text(indentText());
		text += L"_emit DebugLog [";
		
		wstringstream ostr;
		ostr << hex << showbase;
		const QVector<quint16> compressedContent(eventActionsSet.getContentCompressed());
        copy(compressedContent.begin(), compressedContent.end(), ostream_iterator<quint16, wchar_t>(ostr, L", "));
		text += ostr.str();
		text.erase(text.size() - 2);
		
		text += L"]\n";
		generatedCode[currentBlock].append(text);
	}
Пример #10
0
/***************************************************************
* Function: WhileStmt::toString()
* Purpose : Generate a text representation of this IIR node
* Initial : Maxime Chevalier-Boisvert on November 8, 2008
****************************************************************
Revisions and bug fixes:
*/
std::string WhileStmt::toString() const
{
	// Declare a string to the output
	std::string output;
	
	// Add the "while" keyword and the condition expression to the string
	output += "while " + m_pCondExpr->toString() + "\n";
	
	// Indent and add the loop body text
	output += indentText(m_pLoopBody->toString());
	
	// Add the "end" keyword to the string
	output += "end";
	
	// Return the output
	return output;
}
Пример #11
0
/***************************************************************
* Function: ForStmt::toString()
* Purpose : Generate a text representation of this IIR node
* Initial : Maxime Chevalier-Boisvert on November 8, 2008
****************************************************************
Revisions and bug fixes:
*/
std::string ForStmt::toString() const
{
	// Declare a string to the output
	std::string output;
	
	// Add the "for" keyword and the assignment statement to the string
	output += "for " + m_pAssignStmt->toString() + "\n";
	
	// Indent and add the loop body text
	output += indentText(m_pLoopBody->toString());
	
	// Add the "end" keyword to the string
	output += "end";
	
	// Return the output
	return output;
}
Пример #12
0
	wstring Compiler::CodeGenerator::visitActionSound(const Block* block)
	{
		static const int noteTable[6] = { 262, 311, 370, 440, 524, 0 };
		static const int durationTable[3] = {-1, 7, 14};
		
		// find last non-silent note
		unsigned noteCount(block->valuesCount());
		assert(noteCount > 0);
		while ((noteCount > 0) && ((block->getValue(noteCount-1) & 0xff) == 5))
			--noteCount;
		
		// if there is no note, return
		if (noteCount == 0)
			return indentText() + L"# zero notes in sound block\n";
		
		// generate code for notes
		wstring notesCopyText;
		wstring durationsCopyText;
		unsigned accumulatedDuration(0);
		unsigned activeNoteCount(0);
		for (unsigned i = 0; i<noteCount; ++i)
		{
			const unsigned note(block->getValue(i) & 0xff);
			const unsigned duration((block->getValue(i)>>8) & 0xff);
			
			if (note == 5 && i+1 < noteCount && (block->getValue(i+1) & 0xff) == 5)
			{
				// next note is silence, skip
				accumulatedDuration += durationTable[duration];
			}
			else
			{
				notesCopyText += toWstring(noteTable[note]);
				if (i+1 != noteCount)
					notesCopyText += L", ";
				durationsCopyText += toWstring(durationTable[duration]+accumulatedDuration);
				if (i+1 != noteCount)
					durationsCopyText += L", ";
				++activeNoteCount;
				accumulatedDuration = 0;
			}
		}
		
		// enable sound
		useSound = true;
		
		// prepare target string
		wstring text;
		const wstring indString(indentText());
		// notes
		text += indString;
		text += L"call math.copy(notes[0:";
		text += toWstring(activeNoteCount-1);
		text += L"], [";
		text += notesCopyText;
		text += L"])\n";
		// durations
		text += indString;
		text += L"call math.copy(durations[0:";
		text += toWstring(activeNoteCount-1);
		text += L"], [";
		text += durationsCopyText;
		text += L"])\n";
		// write variables
		text += indString;
		text += L"note_index = 1\n";
		text += indString;
		text += L"note_count = " + toWstring(activeNoteCount) + L"\n";
		// start playing
		text += indString;
		text += L"call sound.freq(notes[0], durations[0])\n";
		
		return text;
	}
Пример #13
0
int main()
{
    int c, nbErreur = 0, accolade = 0, ligne = 0;

   
    enum {ETAT_DEBUT_LIGNE, ETAT_NORMAL, ETAT_COMMENTAIRE, ETAT_DEBUT_COMMENTAIRE, ETAT_GUILLEMET, ETAT_DIESE, ETAT_OPERATOR, ETAT_SIMPLE_QUOTE } etat = ETAT_DEBUT_LIGNE;



    /* plop
      plip
     ploup */

    while ((c=getchar()) != EOF) 
    {
ligne++;
switch (etat)
{
            case ETAT_DEBUT_LIGNE:
                switch (c) 
                {
                    case ' ': /*cas d'un espace*/
                  		break;
      
                    case '\t': /*cas d'une tabulation*/
                        break;

                  	case '\n': /*cas d'un retour a la ligne*/
        				setCharacter(c);
                  		break;
                  		
                    case ';' : /*cas d'un point virgule*/
                    	indentText();
                    	putchar(c);
                    	putchar('\n');
        				setCharacter(c);
						break;

                    case '/' : /*cas d'un slash*/
        				setCharacter(c);
        				break;
        				
                    case '#':
                    	setCharacter(c);
                    	putchar(c);
                    	etat = ETAT_DIESE;
                    	break;

                    case '*' : /*cas d'un début de commentaire*/
                    	if (previousCharacters[0] == '/')
                    	{
                    		putchar('\n');
                    		indentText();
		                	etat = ETAT_DEBUT_COMMENTAIRE;
		                	putchar(previousCharacters[0]);
		                	putchar(c);
		                }
        				setCharacter(c);
                    	break;
                    	
                    case '{' :  /*cas d'une acolade ouvrante*/
                    	if (previousCharacters[0] != '\n' && previousCharacters[0] != ';' && previousCharacters[0] != '}')

                    	putchar('\n');
                    	indentText();
                    	putchar(c);
                    	putchar('\n');
                    	indent++;
                    	accolade++;
        				setCharacter(c);
                    	break;
                   		
                   	case '}' : /*cas d'une accolade fermante*/
                   		if (previousCharacters[0] != '\n' && previousCharacters[0] != ';' && previousCharacters[0] != '}' )
                    		putchar('\n');

                   		indent--;

                   		indentText();
                    	putchar(c);
                    	putchar('\n');
                        
                    	accolade--;
        				setCharacter(c);
                    	break;

					case '\0': /*cas de fin de fichier*/
                    	break;
                    	
                   	default: /* sinon */
                   		indentText();
   						putchar(c);
   						
        				setCharacter(c);
                        etat = ETAT_NORMAL;
                        break;
                }
               	break;
               	
            case ETAT_NORMAL:
                switch (c) 
                {
                 	case '\n': /*cas d'un retour a la ligne*/
                        putchar(c);
                        etat = ETAT_DEBUT_LIGNE;

        				setCharacter(c);
                        break;
                    
                    case ';' : /*cas d'un point virgule*/
                    	putchar(c);
                    	putchar('\n');
                    	
                    	etat = ETAT_DEBUT_LIGNE;

        				setCharacter(c);
                    	break;
                    	
                	case '/' : /* cas d'un slash */

        				setCharacter(c);
        				break;
        				
                	case '*' : /*cas d'un début de commentaire*/
                    	if (previousCharacters[0] == '/')
                    	{
                    		if (previousCharacters[1] != '\n')
                    			putchar('\n');
                    		
                    		indentText();
		                	etat = ETAT_DEBUT_COMMENTAIRE;
		                	putchar(previousCharacters[0]);
		                	putchar(c);
		                }
		                
        				setCharacter(c);
                    	break;
					
                	case 'r': /* cas du for */
                		putchar(c);

                		if ((previousCharacters[0] == 'o') && (previousCharacters[1] == 'f')) etat = ETAT_OPERATOR;
						setCharacter(c);
                		break;

                	case 'f': /* cas du if */
                		putchar(c);

                		if (previousCharacters[0] == 'i') etat = ETAT_OPERATOR;
						setCharacter(c);
                		break;

					case '\'' : /* cas d'un simple quote */
						putchar(c);
	        			setCharacter(c);
						etat = ETAT_SIMPLE_QUOTE;
	                    break;

					case '"' : /* cas d'un guillemet ouvrant */
						putchar(c);
						setCharacter(c);
						etat = ETAT_GUILLEMET;
						break;

						
                    case '{' :  /*cas d'une accolade ouvrante*/
                    	if (previousCharacters[0] != '\n' && previousCharacters[0] != ';' && previousCharacters[0] != '}')
						putchar('\n');
	
                    	indentText();
						putchar(c);
						putchar('\n');
						indent++;
						
						accolade++;
   						etat = ETAT_DEBUT_LIGNE;

        				setCharacter(c);
                    	break;
                    
                    case '}' : /*cas d'une accolade fermante*/
                    	if (previousCharacters[0] != '\n' && previousCharacters[0] != ';' && previousCharacters[0] != '}')
	                    	putchar('\n');
	                    
	                    indent--;       
	                    indentText();
                    	putchar(c);
                    	putchar('\n');
                    	
                    	accolade--;
                    	etat = ETAT_DEBUT_LIGNE;

        				setCharacter(c);
                    	break;
                    	
                   case '\0': /*cas de fin de fichier*/
                    	break;
                    	
                    default : /*sinon*/
                        putchar(c);

        				setCharacter(c);
                        break;
        		}
        		break;
        	
        	case ETAT_DEBUT_COMMENTAIRE :
        		switch(c)
        		{
        			case ' ' :
        				break;
        				
        			case '\t' :
        				break;
        			
        			default :
        				putchar(' ');
        				putchar(c);
        				
        				setCharacter(c);
        				etat = ETAT_COMMENTAIRE;
        				break;
        		}
        		break;
        		
        	case ETAT_COMMENTAIRE :
        		switch(c)
        		{		
        			case '\n' : /* cas de retour a la ligne sans fin de commentaire*/
        				if (previousCharacters[1] == '*' && previousCharacters[0] == '/')
        				{
        					putchar(c);
        				}
        				else
        				{
        					if (previousCharacters[2] != ' ')
        						putchar(' ');
        						
        					putchar('*');
        					putchar('/');
        					putchar('\n');
        					indentText();
        					putchar('/');
        					putchar('*');
        					fputs("commentaire non fini détecté à la ligne : "+ligne,stderr);
        					nbErreur++;
        				}


        				setCharacter(c);
        				etat = ETAT_DEBUT_COMMENTAIRE;
        				break;
        		
        			case '/' : /* cas de fin de commentaire */
        				if (previousCharacters[0] == '*')
        				{
        					if (previousCharacters[1] != ' ')
        						putchar(' ');
        						
        					etat = ETAT_DEBUT_LIGNE;
	        				putchar('/');
	        				putchar('\n');
	        			}
	        			else
	        			{
	        				putchar('/');
	        			}


        				setCharacter(c);
	        			break;
	        			
	        		case '\0': /*cas de fin de fichier*/
                    	break;
                    	
        			default : /* sinon */

        				setCharacter(c);
        				putchar(c);
        				break;
        		}
        		break;

				case  ETAT_GUILLEMET :
					switch (c)
					{
						case '"' :

							setCharacter(c);
							putchar(c);
							etat = ETAT_NORMAL;
							break;
						default : /* sinon */

							setCharacter(c);
							putchar(c);
							break;
					}
					break;


				case ETAT_SIMPLE_QUOTE :
					switch (c)
					{
						case '\'' :

							if (previousCharacters[0] == '\\' || ( previousCharacters[0] == '\\' && previousCharacters[1] == '\\' ))
							{
								putchar(c);

								etat = ETAT_SIMPLE_QUOTE;
							}else
							{
								putchar(c);
								etat = ETAT_NORMAL;
							}
							setCharacter(c);
							break;
						default : /* sinon */
							setCharacter(c);
							putchar(c);
							break;
					}
					break;


				case  ETAT_DIESE :
					switch (c)
					{
						case '\n' :

							setCharacter(c);
							putchar(c);
							etat = ETAT_DEBUT_LIGNE;
							break;
						default : /* sinon */

							setCharacter(c);
							putchar(c);
							break;
					}
					break;
					case  ETAT_OPERATOR :
						switch (c)
						{
							case ')' :
								setCharacter(c);
								putchar(c);
								etat = ETAT_NORMAL;
								break;
							default : /* sinon */

								setCharacter(c);
								putchar(c);
								break;
						}
						break;
   		}
   	}
   	
   	if (accolade != 0)
   	{
    	if (accolade > 0) 
   			fputs("too much {" ,stderr);
   		else 
   			fputs("too much }" ,stderr);
   			
   		exit(EXIT_FAILURE);
    }
   	else if (nbErreur != 0)
   	{
   		printf("there are %d errors\n", nbErreur);
   		
   		exit(EXIT_FAILURE);
   	}

   	exit(EXIT_SUCCESS);

}
Пример #14
0
void SyntaxTextEditor::keyPressEvent(QKeyEvent *e)
{
    if (editCompleter && editCompleter->popup()->isVisible()) {
        // The following keys are forwarded by the completer to the widget
        switch (e->key()) {
        case Qt::Key_Enter:
        case Qt::Key_Return:
        case Qt::Key_Escape:
        case Qt::Key_Tab:
        case Qt::Key_Backtab:            
            e->ignore();
            return; // let the completer do default behavior
        default:
            break;
        }
    }
    if (e->key() == Qt::Key_Tab) {
        indentText(document(), textCursor(),true);
        e->accept();
        return;
    } else if (e->key() == Qt::Key_Backtab) {
        indentText(document(),textCursor(),false);
        e->accept();
        return;
    }

    if ( e->key() == Qt::Key_Enter || e->key() == Qt::Key_Return ) {
        if (this->autoIndent) {
            indentEnter(textCursor());
        } else {
            e->accept();
        }
        emit update();
        return;
    }

    if (this->autoBlock && e->key() == '{') {
        QTextCursor cursor(this->textCursor());
        cursor.insertText("{}");
        cursor.movePosition(QTextCursor::PreviousCharacter);
        setTextCursor(cursor);
        e->accept();
        return;
    }

    if (!this->autoWord) {
        QPlainTextEdit::keyPressEvent(e);
        return;
    }

    bool isShortcut = ((e->modifiers() & Qt::ControlModifier) && e->key() == Qt::Key_E); // CTRL+E
    if (!editCompleter || !isShortcut) // do not process the shortcut when we have a completer
        QPlainTextEdit::keyPressEvent(e);

    const bool ctrlOrShift = e->modifiers() & (Qt::ControlModifier | Qt::ShiftModifier);
    if (!editCompleter || (ctrlOrShift && e->text().isEmpty()))
        return;

    static QString eow("~!@#$%^&*()+{}|:\"<>?,./;'[]\\-= "); // end of word
    bool hasModifier = (e->modifiers() != Qt::NoModifier) && !ctrlOrShift;

    QString word = wordUnderCursor();
    QString text = textUnderCursor();

    if (editCompleter->underCursor(e->key(),textCursor(), text,word)) {
        return;
    }

    if (!isShortcut && (hasModifier || e->text().isEmpty() || text.length() <= 2
                        || eow.contains(e->text().right(1)))) {
        editCompleter->hidePopup();
        return;
    }
    editCompleter->showPopup(word);
}