int DirectiveParser::parseExpressionIf(Token *token) { assert((getDirective(token) == DIRECTIVE_IF) || (getDirective(token) == DIRECTIVE_ELIF)); MacroExpander macroExpander(mTokenizer, mMacroSet, mDiagnostics, true); ExpressionParser expressionParser(¯oExpander, mDiagnostics); int expression = 0; ExpressionParser::ErrorSettings errorSettings; errorSettings.integerLiteralsMustFit32BitSignedRange = false; errorSettings.unexpectedIdentifier = Diagnostics::PP_CONDITIONAL_UNEXPECTED_TOKEN; bool valid = true; expressionParser.parse(token, &expression, false, errorSettings, &valid); // Check if there are tokens after #if expression. if (!isEOD(token)) { mDiagnostics->report(Diagnostics::PP_CONDITIONAL_UNEXPECTED_TOKEN, token->location, token->text); skipUntilEOD(mTokenizer, token); } return expression; }
//----------------------------------------------------------------------------- // Function: ParameterDelegate::setEditorData() //----------------------------------------------------------------------------- void ParameterDelegate::setEditorData(QWidget* editor, QModelIndex const& index) const { if (index.column() == valueColumn() && valueIsArray(index)) { ArrayView* view = dynamic_cast<ArrayView*>(dynamic_cast<QScrollArea*>(editor)->widget()); QModelIndex arrayLeftIndex = index.sibling(index.row(), arrayLeftColumn()); int arrayLeftValue = arrayLeftIndex.data(Qt::ToolTipRole).toInt(); QModelIndex arrayRightIndex = index.sibling(index.row(), arrayRightColumn()); int arrayRightValue = arrayRightIndex.data(Qt::ToolTipRole).toInt(); int arraySize = getArraySize(arrayLeftValue, arrayRightValue); int arrayStartIndex = arrayLeftValue; if (arrayRightValue < arrayLeftValue) { arrayStartIndex = arrayRightValue; } QSharedPointer<IPXactSystemVerilogParser> expressionParser(new IPXactSystemVerilogParser( getParameterFinder())); QSharedPointer<Choice> selectedChoice = findChoice(index); ParameterArrayModel* model = new ParameterArrayModel(arraySize, expressionParser, getParameterFinder(), expressionFormatter_, selectedChoice, QColor("LemonChiffon"), arrayStartIndex, view); QModelIndex valueIndex = index.sibling(index.row(), valueColumn()); QString parameterValue = valueIndex.data(Qt::EditRole).toString(); model->setArrayData(parameterValue); QModelIndex typeIndex = index.sibling(index.row(), formatColumn()); QString parameterType = typeIndex.data(Qt::EditRole).toString(); model->setParameterType(parameterType); view->setItemDelegate(new ArrayDelegate(getNameCompleter(), getParameterFinder(), selectedChoice, this->parent())); view->setModel(model); view->setSortingEnabled(false); view->resizeColumnsToContents(); connect(model, SIGNAL(contentChanged()), this, SIGNAL(contentChanged()), Qt::UniqueConnection); connect(model, SIGNAL(dataChanged(const QModelIndex&, const QModelIndex&)), this, SIGNAL(contentChanged()), Qt::UniqueConnection); connect(view->itemDelegate(), SIGNAL(increaseReferences(QString)), this, SIGNAL(increaseReferences(QString)), Qt::UniqueConnection); connect(view->itemDelegate(), SIGNAL(decreaseReferences(QString)), this, SIGNAL(decreaseReferences(QString)), Qt::UniqueConnection); }
//----------------------------------------------------------------------------- // Function: RemapConditionDelegate::setArrayEditor() //----------------------------------------------------------------------------- void RemapConditionDelegate::setArrayEditor(QWidget* editor, QModelIndex const& index) const { ArrayView* view = dynamic_cast<ArrayView*>(dynamic_cast<QScrollArea*>(editor)->widget()); int arraySize = getPortWidth(index); QSharedPointer<IPXactSystemVerilogParser> expressionParser(new IPXactSystemVerilogParser( getParameterFinder())); QModelIndex portLeftIndex = index.sibling(index.row(), RemapConditionColumns::LEFT_COLUMN); int portLeft = portLeftIndex.data(Qt::ToolTipRole).toInt(); QModelIndex portRightIndex = index.sibling(index.row(), RemapConditionColumns::RIGHT_COLUMN); int portRight = portRightIndex.data(Qt::ToolTipRole).toInt(); int arrayStart = portLeft; if (portRight < portLeft) { arrayStart = portRight; } ParameterArrayModel* model = new ParameterArrayModel(arraySize, expressionParser, getParameterFinder(), expressionFormatter_, QSharedPointer<Choice>(new Choice()), QColor("white"), arrayStart, view); QModelIndex valueIndex = index.sibling(index.row(), RemapConditionColumns::VALUE_COLUMN); QString portValue = valueIndex.data(Qt::EditRole).toString(); model->setArrayData(portValue); view->setItemDelegate(new ArrayDelegate(getNameCompleter(), getParameterFinder(), QSharedPointer<Choice>(new Choice()), this->parent())); view->setModel(model); view->setSortingEnabled(false); view->resizeColumnsToContents(); connect(model, SIGNAL(contentChanged()), this, SIGNAL(contentChanged()), Qt::UniqueConnection); connect(view->itemDelegate(), SIGNAL(increaseReferences(QString)), this, SIGNAL(increaseReferences(QString)), Qt::UniqueConnection); connect(view->itemDelegate(), SIGNAL(decreaseReferences(QString)), this, SIGNAL(decreaseReferences(QString)), Qt::UniqueConnection); }
int DirectiveParser::parseExpressionIf(Token *token) { assert((getDirective(token) == DIRECTIVE_IF) || (getDirective(token) == DIRECTIVE_ELIF)); DefinedParser definedParser(mTokenizer, mMacroSet, mDiagnostics); MacroExpander macroExpander(&definedParser, mMacroSet, mDiagnostics); ExpressionParser expressionParser(¯oExpander, mDiagnostics); int expression = 0; macroExpander.lex(token); expressionParser.parse(token, &expression); // Warn if there are tokens after #if expression. if (!isEOD(token)) { mDiagnostics->report(Diagnostics::PP_CONDITIONAL_UNEXPECTED_TOKEN, token->location, token->text); skipUntilEOD(mTokenizer, token); } return expression; }
//----------------------------------------------------------------------------- // Function: ModuleParameterEditor::ModuleParameterEditor() //----------------------------------------------------------------------------- ModuleParameterEditor::ModuleParameterEditor(QSharedPointer<QList<QSharedPointer<ModelParameter> > > parameters, QSharedPointer<QList<QSharedPointer<Choice> > > componentChoices, QSharedPointer<ParameterFinder> parameterFinder, QSharedPointer<ExpressionFormatter> expressionFormatter, QWidget *parent) : QGroupBox(tr("Module parameters"), parent), proxy_(new QSortFilterProxyModel(this)), model_(0) { QSharedPointer<IPXactSystemVerilogParser> expressionParser(new IPXactSystemVerilogParser(parameterFinder)); model_ = new ModelParameterModel(parameters, componentChoices, expressionParser, parameterFinder, expressionFormatter, this); model_->setParameterFactory(QSharedPointer<ModelParameterFactory>(new ModuleParameterFactoryImplementation())); QSharedPointer<EditableTableView> moduleParameterView(new EditableTableView(this)); moduleParameterView->verticalHeader()->setSectionResizeMode(QHeaderView::Fixed); moduleParameterView->verticalHeader()->show(); ColumnFreezableTable* view = new ColumnFreezableTable(1, moduleParameterView, this); connect(model_, SIGNAL(contentChanged()), this, SIGNAL(contentChanged()), Qt::UniqueConnection); connect(model_, SIGNAL(dataChanged(const QModelIndex&, const QModelIndex&)), this, SIGNAL(contentChanged()), Qt::UniqueConnection); connect(model_, SIGNAL(errorMessage(const QString&)), this, SIGNAL(errorMessage(const QString&)), Qt::UniqueConnection); connect(model_, SIGNAL(noticeMessage(const QString&)), this, SIGNAL(noticeMessage(const QString&)), Qt::UniqueConnection); connect(view, SIGNAL(addItem(const QModelIndex&)), model_, SLOT(onAddItem(const QModelIndex&)), Qt::UniqueConnection); connect(view, SIGNAL(removeItem(const QModelIndex&)), model_, SLOT(onRemoveItem(const QModelIndex&)), Qt::UniqueConnection); ModelParameterEditorHeaderView* parameterHorizontalHeader = new ModelParameterEditorHeaderView(Qt::Horizontal, this); view->setHorizontalHeader(parameterHorizontalHeader); view->horizontalHeader()->setSectionsClickable(true); view->horizontalHeader()->setStretchLastSection(true); // set view to be sortable view->setSortingEnabled(true); // items can not be dragged view->setItemsDraggable(false); ComponentParameterModel* parameterModel = new ComponentParameterModel(parameterFinder, this); parameterModel->setExpressionParser(expressionParser); ParameterCompleter* parameterCompleter = new ParameterCompleter(this); parameterCompleter->setModel(parameterModel); view->setDelegate(new ModelParameterDelegate(componentChoices, parameterCompleter, parameterFinder, expressionFormatter, this)); connect(view->itemDelegate(), SIGNAL(increaseReferences(QString)), this, SIGNAL(increaseReferences(QString)), Qt::UniqueConnection); connect(view->itemDelegate(), SIGNAL(decreaseReferences(QString)), this, SIGNAL(decreaseReferences(QString)), Qt::UniqueConnection); connect(model_, SIGNAL(decreaseReferences(QString)), this, SIGNAL(decreaseReferences(QString)), Qt::UniqueConnection); connect(view->itemDelegate(), SIGNAL(openReferenceTree(QString)), this, SIGNAL(openReferenceTree(QString)), Qt::UniqueConnection); // set source model for proxy proxy_->setSourceModel(model_); // set proxy to be the source for the view view->setModel(proxy_); // sort the view view->sortByColumn(0, Qt::AscendingOrder); view->setColumnHidden(ModelParameterColumns::ID, true); QVBoxLayout* layout = new QVBoxLayout(this); layout->addWidget(view); }
void DirectiveParser::parseLine(Token *token) { assert(getDirective(token) == DIRECTIVE_LINE); bool valid = true; bool parsedFileNumber = false; int line = 0, file = 0; MacroExpander macroExpander(mTokenizer, mMacroSet, mDiagnostics, false); // Lex the first token after "#line" so we can check it for EOD. macroExpander.lex(token); if (isEOD(token)) { mDiagnostics->report(Diagnostics::PP_INVALID_LINE_DIRECTIVE, token->location, token->text); valid = false; } else { ExpressionParser expressionParser(¯oExpander, mDiagnostics); ExpressionParser::ErrorSettings errorSettings; // See GLES3 section 12.42 errorSettings.integerLiteralsMustFit32BitSignedRange = true; errorSettings.unexpectedIdentifier = Diagnostics::PP_INVALID_LINE_NUMBER; // The first token was lexed earlier to check if it was EOD. Include // the token in parsing for a second time by setting the // parsePresetToken flag to true. expressionParser.parse(token, &line, true, errorSettings, &valid); if (!isEOD(token) && valid) { errorSettings.unexpectedIdentifier = Diagnostics::PP_INVALID_FILE_NUMBER; // After parsing the line expression expressionParser has also // advanced to the first token of the file expression - this is the // token that makes the parser reduce the "input" rule for the line // expression and stop. So we're using parsePresetToken = true here // as well. expressionParser.parse(token, &file, true, errorSettings, &valid); parsedFileNumber = true; } if (!isEOD(token)) { if (valid) { mDiagnostics->report(Diagnostics::PP_UNEXPECTED_TOKEN, token->location, token->text); valid = false; } skipUntilEOD(mTokenizer, token); } } if (valid) { mTokenizer->setLineNumber(line); if (parsedFileNumber) mTokenizer->setFileNumber(file); } }
//----------------------------------------------------------------------------- // Function: ModelParameterEditor() //----------------------------------------------------------------------------- ModelParameterEditor::ModelParameterEditor(QSharedPointer<Component> component, LibraryInterface* handler, QSharedPointer<ParameterFinder> parameterFinder, QSharedPointer<ExpressionFormatter> expressionFormatter, QWidget *parent): ItemEditor(component, handler, parent), view_(0), model_(0) { QSharedPointer<EditableTableView> parametersView(new EditableTableView(this)); parametersView->verticalHeader()->setSectionResizeMode(QHeaderView::Fixed); parametersView->verticalHeader()->show(); view_ = new ColumnFreezableTable(1, parametersView, this); QSharedPointer<IPXactSystemVerilogParser> expressionParser(new IPXactSystemVerilogParser(parameterFinder)); model_ = new ModelParameterModel(component->getModelParameters(), component->getChoices(), expressionParser, parameterFinder, expressionFormatter, this); ComponentParameterModel* componentParametersModel = new ComponentParameterModel(parameterFinder, this); componentParametersModel->setExpressionParser(expressionParser); ParameterCompleter* parameterCompleter = new ParameterCompleter(this); parameterCompleter->setModel(componentParametersModel); connect(model_, SIGNAL(contentChanged()), this, SIGNAL(contentChanged()), Qt::UniqueConnection); connect(model_, SIGNAL(dataChanged(const QModelIndex&, const QModelIndex&)), this, SLOT(modelDataChanged(const QModelIndex&)), Qt::UniqueConnection); connect(model_, SIGNAL(errorMessage(const QString&)), this, SIGNAL(errorMessage(const QString&)), Qt::UniqueConnection); connect(model_, SIGNAL(noticeMessage(const QString&)), this, SIGNAL(noticeMessage(const QString&)), Qt::UniqueConnection); connect(view_, SIGNAL(addItem(const QModelIndex&)), model_, SLOT(onAddItem(const QModelIndex&)), Qt::UniqueConnection); connect(view_, SIGNAL(removeItem(const QModelIndex&)), model_, SLOT(onRemoveItem(const QModelIndex&)), Qt::UniqueConnection); const QString compPath = ItemEditor::handler()->getDirectoryPath(*ItemEditor::component()->getVlnv()); QString defPath = QString("%1/modelParamList.csv").arg(compPath); ModelParameterEditorHeaderView* modelParameterHorizontalHeader = new ModelParameterEditorHeaderView(Qt::Horizontal, this); view_->setHorizontalHeader(modelParameterHorizontalHeader); view_->horizontalHeader()->setSectionsClickable(true); view_->horizontalHeader()->setStretchLastSection(true); view_->setDefaultImportExportPath(defPath); view_->setAllowImportExport(true); // set view to be sortable view_->setSortingEnabled(true); // set the delegate to edit the usage column view_->setDelegate(new ModelParameterDelegate(component->getChoices(), parameterCompleter, parameterFinder, expressionFormatter, this)); connect(view_->itemDelegate(), SIGNAL(increaseReferences(QString)), this, SIGNAL(increaseReferences(QString)), Qt::UniqueConnection); connect(view_->itemDelegate(), SIGNAL(decreaseReferences(QString)), this, SIGNAL(decreaseReferences(QString)), Qt::UniqueConnection); connect(model_, SIGNAL(decreaseReferences(QString)), this, SIGNAL(decreaseReferences(QString)), Qt::UniqueConnection); connect(view_->itemDelegate(), SIGNAL(openReferenceTree(QString)), this, SIGNAL(openReferenceTree(QString)), Qt::UniqueConnection); // items can not be dragged view_->setItemsDraggable(false); QSortFilterProxyModel* sortingProxy = new QSortFilterProxyModel(this); // set source model for proxy sortingProxy->setSourceModel(model_); // set proxy to be the source for the view view_->setModel(sortingProxy); // Set case-insensitive sorting. sortingProxy->setSortCaseSensitivity(Qt::CaseInsensitive); // sort the view view_->sortByColumn(0, Qt::AscendingOrder);; view_->setColumnHidden(ModelParameterColumns::ID, true); // display a label on top the table SummaryLabel* summaryLabel = new SummaryLabel(tr("Model parameters"), this); // create the layout, add widgets to it QVBoxLayout* layout = new QVBoxLayout(this); layout->addWidget(summaryLabel, 0, Qt::AlignCenter); layout->addWidget(view_); layout->setContentsMargins(0, 0, 0, 0); refresh(); }
//----------------------------------------------------------------------------- // Function: LocalMemoryMapEditor::LocalMemoryMapEditor() //----------------------------------------------------------------------------- LocalMemoryMapEditor::LocalMemoryMapEditor(QSharedPointer<MemoryMap> memoryMap, QSharedPointer<Component> component, LibraryInterface* handler, QSharedPointer<ParameterFinder> parameterFinder, QSharedPointer<ExpressionFormatter> expressionFormatter, QWidget *parent) : QGroupBox(tr("Local memory map"), parent), localMemoryMap_(memoryMap), nameEditor_(new NameGroupEditor(memoryMap->getNameGroup(), this)), view_(new EditableTableView(this)), model_(0), component_(component), handler_(handler) { setCheckable(true); setChecked(!localMemoryMap_->isEmpty()); nameEditor_->setTitle(tr("Memory map name and description")); QSharedPointer<IPXactSystemVerilogParser> expressionParser(new IPXactSystemVerilogParser(parameterFinder)); model_ = new MemoryMapModel(memoryMap, component->getChoices(), expressionParser, parameterFinder, expressionFormatter, this); ComponentParameterModel* componentParameterModel = new ComponentParameterModel(parameterFinder, this); componentParameterModel->setExpressionParser(expressionParser); ParameterCompleter* parameterCompleter = new ParameterCompleter(this); parameterCompleter->setModel(componentParameterModel); ExpressionProxyModel* proxy = new ExpressionProxyModel(expressionParser, this); proxy->setColumnToAcceptExpressions(MemoryMapColumns::BASE_COLUMN); proxy->setColumnToAcceptExpressions(MemoryMapColumns::RANGE_COLUMN); proxy->setSourceModel(model_); view_->setModel(proxy); // display a label on top the table SummaryLabel* summaryLabel = new SummaryLabel(tr("Address blocks"), this); proxy->setSourceModel(model_); view_->setModel(proxy); const QString compPath = handler_->getDirectoryPath(*component_->getVlnv()); QString defPath = QString("%1/localAddrBlockList.csv").arg(compPath); view_->setDefaultImportExportPath(defPath); view_->setAllowImportExport(true); // items can not be dragged view_->setItemsDraggable(false); view_->setItemDelegate(new MemoryMapDelegate(parameterCompleter, parameterFinder, this)); view_->setSortingEnabled(true); view_->sortByColumn(MemoryMapColumns::BASE_COLUMN, Qt::AscendingOrder); connect(this, SIGNAL(toggled(bool)), this, SLOT(onCheckStateChanged()), Qt::UniqueConnection); connect(nameEditor_, SIGNAL(contentChanged()), this, SIGNAL(contentChanged()), Qt::UniqueConnection); connect(model_, SIGNAL(contentChanged()), this, SIGNAL(contentChanged()), Qt::UniqueConnection); connect(model_, SIGNAL(itemAdded(int)), this, SIGNAL(itemAdded(int)), Qt::UniqueConnection); connect(model_, SIGNAL(itemRemoved(int)), this, SIGNAL(itemRemoved(int)), Qt::UniqueConnection); connect(model_, SIGNAL(graphicsChanged()), this, SIGNAL(graphicsChanged()), Qt::UniqueConnection); connect(model_, SIGNAL(itemAdded(int)), this, SIGNAL(graphicsChanged()), Qt::UniqueConnection); connect(model_, SIGNAL(itemRemoved(int)), this, SIGNAL(graphicsChanged()), Qt::UniqueConnection); // connect view to model connect(view_, SIGNAL(addItem(const QModelIndex&)), model_, SLOT(onAddItem(const QModelIndex&)), Qt::UniqueConnection); connect(view_, SIGNAL(removeItem(const QModelIndex&)), model_, SLOT(onRemoveItem(const QModelIndex&)), Qt::UniqueConnection); connect(view_->itemDelegate(), SIGNAL(increaseReferences(QString)), this, SIGNAL(increaseReferences(QString)), Qt::UniqueConnection); connect(view_->itemDelegate(), SIGNAL(decreaseReferences(QString)), this, SIGNAL(decreaseReferences(QString)), Qt::UniqueConnection); connect(model_, SIGNAL(decreaseReferences(QString)), this, SIGNAL(decreaseReferences(QString)), Qt::UniqueConnection); QVBoxLayout* layout = new QVBoxLayout(this); layout->addWidget(nameEditor_); layout->addWidget(summaryLabel, 0, Qt::AlignCenter); layout->addWidget(view_); }