/// ParseEQUIVALENCEStmt - Parse the EQUIVALENCE statement. /// /// [R554]: /// equivalence-stmt := /// EQUIVALENCE equivalence-set-list Parser::StmtResult Parser::ParseEQUIVALENCEStmt() { // Check if this is an assignment. if (IsNextToken(tok::equal)) return StmtResult(); auto Loc = ConsumeToken(); SmallVector<Stmt*, 8> StmtList; SmallVector<Expr*, 8> ObjectList; bool OuterError = false; while(true) { auto PartLoc = Tok.getLocation(); if(!ExpectAndConsume(tok::l_paren)) { if(!SkipUntil(tok::l_paren)) { OuterError = true; break; } } ObjectList.clear(); bool InnerError = false; do { auto E = ParseExpectedExpression(); if(E.isInvalid()) { InnerError = true; break; } else if(E.isUsable()) ObjectList.push_back(E.get()); } while(ConsumeIfPresent(tok::comma)); auto S = Actions.ActOnEQUIVALENCE(Context, Loc, PartLoc, ObjectList, nullptr); if(S.isUsable()) StmtList.push_back(S.get()); if(InnerError) { if(!SkipUntil(tok::r_paren, true, true)) { OuterError = true; break; } } if(!ExpectAndConsume(tok::r_paren)) { if(!SkipUntil(tok::r_paren)) { OuterError = true; break; } } if(ConsumeIfPresent(tok::comma)) continue; if(IsPresent(tok::l_paren)) { ExpectAndConsume(tok::comma); continue; } break; } if(OuterError) SkipUntilNextStatement(); else ExpectStatementEnd(); return Actions.ActOnCompoundStmt(Context, Loc, StmtList, StmtLabel); }
vector<Observation> Localization::findGreenObjects(vector<observationBlob>& blobs, string id) { vector<Observation> ob; if ( isUsable(blobs) ) { for(int i = 0; i < blobs.size(); i++ ){ observationBlob blob = blobs[i]; if ( blob.Area() > 30 ) { double angleLeft, angleRight ; ( blob.Left() > 1 ) ? angleLeft = getAngle(blob.Left()) : angleLeft = Observation::InvalidBearing ; ( blob.Right() < 159 ) ? angleRight = getAngle(blob.Right()) : angleRight = Observation::InvalidBearing ; Observation observation = Observation(id, map, observationVariance, angleLeft, angleRight); ob.push_back(observation); blob.setInUse(); if ( !isUsable(blobs) ) { return ob; } } } } return ob; }
void SelectRangeTool::setTargetModel( AbstractModel* model ) { const bool oldIsUsable = isUsable(); const bool oldIsApplyable = isApplyable(); if( mByteArrayView ) mByteArrayView->disconnect( this ); if( mByteArrayModel ) mByteArrayModel->disconnect( this ); mByteArrayView = model ? model->findBaseModel<ByteArrayView*>() : 0; ByteArrayDocument* document = mByteArrayView ? qobject_cast<ByteArrayDocument*>( mByteArrayView->baseModel() ) : 0; mByteArrayModel = document ? document->content() : 0; if( mByteArrayView && mByteArrayModel ) { connect( mByteArrayModel, SIGNAL(contentsChanged(Okteta::ArrayChangeMetricsList)), SLOT(onContentsChanged()) ); // TODO: update isApplyable on cursor movement and size changes } const bool newIsUsable = isUsable(); const bool newIsApplyable = isApplyable(); if( oldIsUsable != newIsUsable ) emit isUsableChanged( newIsUsable ); if( oldIsApplyable != newIsApplyable ) emit isApplyableChanged( newIsApplyable ); }
vector<Observation> Localization::getCornerMarkers(vector<observationBlob>& topBlobs, vector<observationBlob>& bottomBlobs, string id) { vector<Observation> ob; if ( isUsable(topBlobs) && isUsable(bottomBlobs) ){ for( int i = 0; i < topBlobs.size(); i++ ){ for ( int j = 0; j < bottomBlobs.size(); j++ ){ observationBlob& bottom = bottomBlobs[j]; observationBlob& top = topBlobs[i]; // process blob: add the marker only if there isn't a significant gap between them double topL = static_cast<double>(top.Bottom() - top.Top()); double topW = static_cast<double>(top.Right() - top.Left()); double bottomL = static_cast<double>(bottom.Bottom() - bottom.Top()); double bottomW = static_cast<double>(bottom.Right() - bottom.Left()); double eps = 0.5; if (blobOnTopOf(top, bottom) && (bottom.Top() - top.Bottom() < ( topL + bottomL )/2 )) { //cout << "Corner blob found" << endl; int avgLeft = ( top.Left() + bottom.Left() ) / 2 ; int avgRight = ( top.Right() + bottom.Right() ) / 2 ; //int avgCenter = ( avgLeft + avgRight ) / 2 ; //cout << "avgLeft: " << avgLeft << ", avgRight: " << avgRight << /*", avgCenter: " << avgCenter << */endl; //double angleCenter = getAngle(avgCenter); double angleLeft, angleRight ; ( avgLeft > 5 ) ? angleLeft = getAngle(avgLeft) : angleLeft = Observation::InvalidBearing ; ( avgRight < 155 ) ? angleRight = getAngle(avgRight) : angleRight = Observation::InvalidBearing ; //cout << "angleLeft: " << angleLeft << ", angleRight: " << angleRight << /*", avgCenter: " << angleCenter <<*/ endl; Observation observation = Observation(id, map, //angleCenter, observationVariance, angleLeft, angleRight); ob.push_back(observation); top.setInUse(); bottom.setInUse(); if ( !isUsable(topBlobs) || !isUsable(bottomBlobs) ){ return ob; } } } } } return ob; }
Parser::StmtResult Parser::ParseCaseStmt() { auto Loc = ConsumeToken(); if(ConsumeIfPresent(tok::kw_DEFAULT)) { ParseTrailingConstructName(); return Actions.ActOnCaseDefaultStmt(Context, Loc, StmtConstructName, StmtLabel); } SmallVector<Expr*, 8> Values; ExpectAndConsume(tok::l_paren); do { auto ColonLoc = Tok.getLocation(); if(ConsumeIfPresent(tok::colon)) { auto E = ParseExpectedFollowupExpression(":"); if(E.isInvalid()) goto error; if(E.isUsable()) Values.push_back(RangeExpr::Create(Context, ColonLoc, nullptr, E.get())); } else { auto E = ParseExpectedExpression(); if(E.isInvalid()) goto error; ColonLoc = Tok.getLocation(); if(ConsumeIfPresent(tok::colon)) { if(!(IsPresent(tok::comma) || IsPresent(tok::r_paren))) { auto E2 = ParseExpectedFollowupExpression(":"); if(E2.isInvalid()) goto error; if(E.isUsable() || E2.isUsable()) Values.push_back(RangeExpr::Create(Context, ColonLoc, E.get(), E2.get())); } else { if(E.isUsable()) Values.push_back(RangeExpr::Create(Context, ColonLoc, E.get(), nullptr)); } } else { if(E.isUsable()) Values.push_back(E.get()); } } } while(ConsumeIfPresent(tok::comma)); if(ExpectAndConsume(tok::r_paren)) { ParseTrailingConstructName(); } else SkipUntilNextStatement(); return Actions.ActOnCaseStmt(Context, Loc, Values, StmtConstructName, StmtLabel); error: if(SkipUntil(tok::r_paren)) { ParseTrailingConstructName(); } else SkipUntilNextStatement(); return Actions.ActOnCaseStmt(Context, Loc, Values, StmtConstructName, StmtLabel); }
/// FIXME: todo implied-do ExprResult Parser::ParseArrayConstructor() { auto Loc = ConsumeParenSlash(); SourceLocation EndLoc = Tok.getLocation(); SmallVector<Expr*, 16> ExprList; if(ConsumeIfPresent(tok::slashr_paren)) return Actions.ActOnArrayConstructorExpr(Context, Loc, EndLoc, ExprList); do { auto E = ParseExpectedExpression(); if(E.isInvalid()) goto error; if(E.isUsable()) ExprList.push_back(E.get()); } while(ConsumeIfPresent(tok::comma)); EndLoc = Tok.getLocation(); if(!ExpectAndConsume(tok::slashr_paren)) goto error; return Actions.ActOnArrayConstructorExpr(Context, Loc, EndLoc, ExprList); error: EndLoc = Tok.getLocation(); SkipUntil(tok::slashr_paren); return Actions.ActOnArrayConstructorExpr(Context, Loc, EndLoc, ExprList); }
bool SelfLearningMeasurementModel::adapt(shared_ptr<VersionedImage> image, const vector<Sample>& samples) { if (isUsable()) { if (positiveTrainingExamples.size() > 10) { sort(make_indirect_iterator(positiveTrainingExamples.begin()), make_indirect_iterator(positiveTrainingExamples.end()), greater<ClassifiedPatch>()); positiveTrainingExamples.resize(10); } if (negativeTrainingExamples.size() > 10) { sort(make_indirect_iterator(negativeTrainingExamples.begin()), make_indirect_iterator(negativeTrainingExamples.end())); negativeTrainingExamples.resize(10); } usable = classifier->retrain(getFeatureVectors(positiveTrainingExamples), getFeatureVectors(negativeTrainingExamples)); positiveTrainingExamples.clear(); negativeTrainingExamples.clear(); } else { vector<Sample> goodSamples; vector<Sample> badSamples; for (auto sample = samples.cbegin(); sample != samples.cend(); ++sample) { if (sample->getWeight() > positiveThreshold) goodSamples.push_back(*sample); else if (sample->getWeight() < negativeThreshold) badSamples.push_back(*sample); } if (goodSamples.size() > 10) { sort(goodSamples.begin(), goodSamples.end(), greater<Sample>()); goodSamples.resize(10); } if (badSamples.size() > 10) { sort(badSamples.begin(), badSamples.end()); badSamples.resize(10); } featureExtractor->update(image); usable = classifier->retrain(getFeatureVectors(goodSamples), getFeatureVectors(badSamples)); } return true; }
ExprResult DataStmtEngine::CreateSubstringExprInitializer(SubstringExpr *E, QualType CharTy) { auto CTy = CharTy.getSelfOrArrayElementType()->asCharacterType(); uint64_t Len = CTy->hasLength()? CTy->getLength() : 1; uint64_t Begin, End; if(!E->EvaluateRange(Context, Len, Begin, End, &ImpliedDoEvaluator)) { VisitExpr(E); return Sem.ExprError(); } auto Val = getAndCheckValue(E->getType(), E); if(!Val.isUsable()) return Sem.ExprError(); auto StrVal = StringRef(cast<CharacterConstantExpr>(Val.get())->getValue()); llvm::SmallString<64> Str; Str.resize(Len, ' '); uint64_t I; for(I = Begin; I < End; ++I) { if((I - Begin) >= StrVal.size()) break; Str[I] = StrVal[I - Begin]; } for(; I < End; ++I) Str[I] = ' '; return CharacterConstantExpr::Create(Context, Val.get()->getSourceRange(), Str, Context.CharacterTy); }
void Parser::ParseIOList(SmallVectorImpl<ExprResult> &List) { while(!Tok.isAtStartOfStatement()) { auto E = ParseExpression(); if(E.isUsable()) List.push_back(E); if(!ConsumeIfPresent(tok::comma)) break; } }
ExprResult DataStmtEngine::getAndCheckAnyValue(QualType LHSType, const Expr *LHS) { auto Val = getAndCheckValue(LHSType, LHS); auto ET = LHSType.getSelfOrArrayElementType(); if(ET->isCharacterType() && Val.isUsable()) { assert(isa<CharacterConstantExpr>(Val.get())); return cast<CharacterConstantExpr>(Val.get())->CreateCopyWithCompatibleLength(Context, ET); } return Val; }
/// ParseDesignator - Parse a designator. Return null if current token is not a /// designator. /// /// [R601]: /// designator := /// object-name /// or array-element /// or array-section /// or coindexed-named-object /// or complex-part-designator /// or structure-component /// or substring /// /// FIXME: substring for a character array ExprResult Parser::ParseDesignator(bool IsLvalue) { auto E = ParseNameOrCall(); struct ScopedFlag { bool value; bool &dest; ScopedFlag(bool &flag) : dest(flag) { value = flag; } ~ScopedFlag() { dest = value; } }; ScopedFlag Flag(DontResolveIdentifiers); if(DontResolveIdentifiersInSubExpressions) DontResolveIdentifiers = true; while(true) { if(!E.isUsable()) break; if(IsPresent(tok::l_paren)) { auto EType = E.get()->getType(); if(EType->isArrayType()) E = ParseArraySubscript(E); else if(EType->isCharacterType()) E = ParseSubstring(E); else { Diag.Report(Tok.getLocation(), diag::err_unexpected_lparen); return ExprError(); } } else if(IsPresent(tok::percent)) { auto EType = E.get()->getType(); if(EType->isRecordType()) E = ParseStructureComponent(E); else { Diag.Report(Tok.getLocation(), diag::err_unexpected_percent); return ExprError(); } } else if(IsPresent(tok::period)) { auto EType = E.get()->getType(); if(EType->isRecordType()) E = ParseStructureComponent(E); else { Diag.Report(Tok.getLocation(), diag::err_unexpected_period); return ExprError(); } } else break; } return E; }
void DataStmtEngine::VisitVarExpr(VarExpr *E) { if(CheckVar(E)) return; auto VD = E->getVarDecl(); auto Type = VD->getType(); if(auto ATy = Type->asArrayType()) { uint64_t ArraySize; if(!ATy->EvaluateSize(ArraySize, Context)) { VisitExpr(E); return; } // Construct an array constructor expression for initializer SmallVector<Expr*, 32> Items(ArraySize); bool IsUsable = true; SourceLocation Loc; auto ElementType = ATy->getElementType(); for(uint64_t I = 0; I < ArraySize; ++I) { if(!HasValues(E)) return; auto Val = getAndCheckAnyValue(ElementType, E); if(Val.isUsable()) { Items[I] = Val.get(); if(!Loc.isValid()) Loc = Val.get()->getLocation(); } else IsUsable = false; } if(IsUsable) { VD->setInit(ArrayConstructorExpr::Create(Context, Loc, Items, Type)); } return; } // single item auto Val = getAndCheckAnyValue(Type, E); if(Val.isUsable()) VD->setInit(Val.get()); }
/// ParsePARAMETERStmt - Parse the PARAMETER statement. /// /// [R548]: /// parameter-stmt := /// PARAMETER ( named-constant-def-list ) Parser::StmtResult Parser::ParsePARAMETERStmt() { // Check if this is an assignment. if (IsNextToken(tok::equal)) return StmtResult(); auto Loc = ConsumeToken(); SmallVector<Stmt*, 8> StmtList; if(!ExpectAndConsume(tok::l_paren)) { if(!SkipUntil(tok::l_paren)) return StmtError(); } while(true) { auto IDLoc = Tok.getLocation(); auto II = Tok.getIdentifierInfo(); if(!ExpectAndConsume(tok::identifier)) { if(!SkipUntil(tok::comma)) break; else continue; } auto EqualLoc = Tok.getLocation(); if(!ExpectAndConsume(tok::equal)) { if(!SkipUntil(tok::comma)) break; else continue; } ExprResult ConstExpr = ParseExpression(); if(ConstExpr.isUsable()) { auto Stmt = Actions.ActOnPARAMETER(Context, Loc, EqualLoc, IDLoc, II, ConstExpr, nullptr); if(Stmt.isUsable()) StmtList.push_back(Stmt.take()); } if(ConsumeIfPresent(tok::comma)) continue; if(isTokenIdentifier() && !Tok.isAtStartOfStatement()) { ExpectAndConsume(tok::comma); continue; } break; } if(!ExpectAndConsume(tok::r_paren)) SkipUntilNextStatement(); return Actions.ActOnCompoundStmt(Context, Loc, StmtList, StmtLabel); }
vector<Observation> Localization::getEnteranceMarkers(vector<observationBlob>& blobs, string id) { vector<Observation> ob; if ( isUsable(blobs) ) { for(int i = 0; i < blobs.size(); i++ ){ observationBlob blob = blobs[i]; // process blobs: check the length/width ratio. should be close to 2:1. just to be sure 1.5:1 double d = static_cast<double>( blob.Bottom() - blob.Top() ) / ( blob.Right() - blob.Left() ); if ( d > 1.75 ) { //double angleCenter = getAngle((blob.Right() + blob.Left()) / 2); double angleLeft, angleRight ; ( blob.Left() > 1 ) ? angleLeft = getAngle(blob.Left()) : angleLeft = Observation::InvalidBearing ; ( blob.Right() < 159 ) ? angleRight = getAngle(blob.Right()) : angleRight = Observation::InvalidBearing ; Observation observation = Observation(id, map, //angleCenter, observationVariance, angleLeft, angleRight); ob.push_back(observation); blob.setInUse(); if ( !isUsable(blobs) ) { return ob; } } } } return ob; }
QString StackFrame::toToolTip() const { const QString filePath = QDir::toNativeSeparators(file); QString res; QTextStream str(&res); str << "<html><body><table>"; if (address) str << "<tr><td>" << tr("Address:") << "</td><td>" << formatToolTipAddress(address) << "</td></tr>"; if (!function.isEmpty()) str << "<tr><td>" << (language == CppLanguage ? tr("Function:") : tr("JS-Function:")) << "</td><td>" << function << "</td></tr>"; if (!file.isEmpty()) str << "<tr><td>" << tr("File:") << "</td><td>" << filePath << "</td></tr>"; if (line != -1) str << "<tr><td>" << tr("Line:") << "</td><td>" << line << "</td></tr>"; if (!from.isEmpty()) str << "<tr><td>" << tr("From:") << "</td><td>" << from << "</td></tr>"; if (!to.isEmpty()) str << "<tr><td>" << tr("To:") << "</td><td>" << to << "</td></tr>"; str << "</table>"; str <<"<br> <br><i>" << tr("Note:") << " </i> "; bool showDistributionNote = false; if (isUsable()) { str << tr("Sources for this frame are available.<br>Double-click on " "the file name to open an editor."); } else if (line <= 0) { str << tr("Binary debug information is not accessible for this " "frame. This either means the core was not compiled " "with debug information, or the debug information is not " "accessible."); showDistributionNote = true; } else { str << tr("Binary debug information is accessible for this " "frame. However, matching sources have not been found."); showDistributionNote = true; } if (!Utils::HostOsInfo::isWindowsHost() && showDistributionNote) { str << QLatin1Char(' ') << tr("Note that most distributions ship debug information " "in separate packages."); } str << "</body></html>"; return res; }
QString StackFrame::toToolTip() const { const QString filePath = QDir::toNativeSeparators(file); QString res; QTextStream str(&res); str << "<html><body><table>"; if (address) { str << "<tr><td>" << tr("Address:") << "</td><td>0x"; str.setIntegerBase(16); str << address; } str.setIntegerBase(10); str << "</td></tr>"; if (!function.isEmpty()) str << "<tr><td>" << tr("Function:") << "</td><td>" << function << "</td></tr>"; if (!file.isEmpty()) str << "<tr><td>" << tr("File:") << "</td><td>" << filePath << "</td></tr>"; if (line != -1) str << "<tr><td>" << tr("Line:") << "</td><td>" << line << "</td></tr>"; if (!from.isEmpty()) str << "<tr><td>" << tr("From:") << "</td><td>" << from << "</td></tr>"; if (!to.isEmpty()) str << "<tr><td>" << tr("To:") << "</td><td>" << to << "</td></tr>"; str << "</table>"; str <<"<br> <br><i>" << tr("Note:") << " </i> "; if (isUsable()) { str << tr("Sources for this frame are available.<br>Double-click on " "the file name to open an editor."); } else if (line <= 0) { str << tr("Binary debug information is not accessible for this " "frame. This either means the core was not compiled " "with debug information, or the debug information is not " "accessible. Note that most distributions ship debug information " "in separate packages."); } else { str << tr("Binary debug information is accessible for this " "frame. However, matching sources have not been found. " "Note that some distributions ship debug sources in " "in separate packages."); } str << "</body></html>"; return res; }
void DataStmtEngine::VisitSubstringExpr(SubstringExpr *E) { if(auto AE = dyn_cast<ArrayElementExpr>(E->getTarget())) { CreateArrayElementExprInitializer(AE, E); return; } auto Target = dyn_cast<VarExpr>(E->getTarget()); if(!Target) return VisitExpr(E); if(CheckVar(Target)) return; auto VD = Target->getVarDecl(); auto CharTy = VD->getType().getSelfOrArrayElementType(); auto Val = CreateSubstringExprInitializer(E, CharTy); if(Val.isUsable()) VD->setInit(Val.get()); }
FormatSpec *Parser::ParseFMTSpec(bool IsLabeled) { auto Loc = Tok.getLocation(); if(!ConsumeIfPresent(tok::star)) { if(Tok.is(tok::int_literal_constant)) { auto Destination = ParseStatementLabelReference(); if(!Destination.isInvalid()) return Actions.ActOnLabelFormatSpec(Context, Loc, Destination); } auto E = ParseExpression(); if(E.isUsable()) return Actions.ActOnExpressionFormatSpec(Context, Loc, E.get()); // NB: return empty format string on error. return Actions.ActOnExpressionFormatSpec(Context, Loc, CharacterConstantExpr::Create(Context, Loc, "", Context.CharacterTy)); } return Actions.ActOnStarFormatSpec(Context, Loc); }
void DataStmtEngine::VisitMemberExpr(MemberExpr *E) { if(auto AE = dyn_cast<ArrayElementExpr>(E->getTarget())) { CreateArrayElementExprInitializer(AE, E); return; } auto Target = dyn_cast<VarExpr>(E->getTarget()); if(!Target) return VisitExpr(E); if(CheckVar(Target)) return; auto VD = Target->getVarDecl(); const TypeConstructorExpr *Init = VD->hasInit()? cast<TypeConstructorExpr>(VD->getInit()) : nullptr; auto Val = CreateMemberExprInitializer(E, Init); if(Val.isUsable()) VD->setInit(Val.get()); }
ExprResult DataStmtEngine::CreateMemberExprInitializer(const MemberExpr *E, const TypeConstructorExpr *Init) { auto Field = E->getField(); auto Val = getAndCheckAnyValue(E->getType(), E); if(!Val.isUsable()) return Sem.ExprError(); auto FieldCount = E->getTarget()->getType().getSelfOrArrayElementType()->asRecordType()->getElementCount(); SmallVector<Expr*, 16> Items(FieldCount); if(Init) { auto Args = Init->getArguments(); for(unsigned I = 0; I < FieldCount; ++I) Items[I] = Args[I]; } else { for(unsigned I = 0; I < FieldCount; ++I) Items[I] = nullptr; } Items[Field->getIndex()] = Val.get(); return TypeConstructorExpr::Create(Context, Val.get()->getLocation(), Field->getParent(), Items); }
/// ParseINTRINSICStmt - Parse the INTRINSIC statement. /// /// [R1216]: /// intrinsic-stmt := /// INTRINSIC [::] intrinsic-procedure-name-list Parser::StmtResult Parser::ParseINTRINSICStmt(bool IsActuallyExternal) { // Check if this is an assignment. if (IsNextToken(tok::equal)) return StmtResult(); auto Loc = ConsumeToken(); ConsumeIfPresent(tok::coloncolon); SmallVector<Stmt *,8> StmtList; while(true) { auto IDLoc = Tok.getLocation(); auto II = Tok.getIdentifierInfo(); if(!ExpectAndConsume(tok::identifier)) { if(!SkipUntil(tok::comma, tok::identifier, true, true)) break; if(ConsumeIfPresent(tok::comma)) continue; else { IDLoc = Tok.getLocation(); II = Tok.getIdentifierInfo(); ConsumeToken(); } } auto Stmt = IsActuallyExternal? Actions.ActOnEXTERNAL(Context, Loc, IDLoc, II, nullptr): Actions.ActOnINTRINSIC(Context, Loc, IDLoc, II, nullptr); if(Stmt.isUsable()) StmtList.push_back(Stmt.take()); if(Tok.isAtStartOfStatement()) break; if(!ExpectAndConsume(tok::comma)) { if(!SkipUntil(tok::comma)) break; } } return Actions.ActOnCompoundStmt(Context, Loc, StmtList, StmtLabel); }
/// ParseDIMENSIONStmt - Parse the DIMENSION statement. /// /// [R535]: /// dimension-stmt := /// DIMENSION [::] array-name ( array-spec ) # /// # [ , array-name ( array-spec ) ] ... Parser::StmtResult Parser::ParseDIMENSIONStmt() { // Check if this is an assignment. if (IsNextToken(tok::equal)) return StmtResult(); auto Loc = ConsumeToken(); ConsumeIfPresent(tok::coloncolon); SmallVector<Stmt*, 8> StmtList; SmallVector<ArraySpec*, 4> Dimensions; while (true) { auto IDLoc = Tok.getLocation(); auto II = Tok.getIdentifierInfo(); if(!ExpectAndConsume(tok::identifier)) { if(!SkipUntil(tok::comma, tok::identifier, true, true)) break; if(ConsumeIfPresent(tok::comma)) continue; else { IDLoc = Tok.getLocation(); II = Tok.getIdentifierInfo(); ConsumeToken(); } } // FIXME: improve error recovery Dimensions.clear(); if(ParseArraySpec(Dimensions)) return StmtError(); auto Stmt = Actions.ActOnDIMENSION(Context, Loc, IDLoc, II, Dimensions, nullptr); if(Stmt.isUsable()) StmtList.push_back(Stmt.take()); if(Tok.isAtStartOfStatement()) break; if(!ExpectAndConsume(tok::comma)) { if(!SkipUntil(tok::comma)) break; } } return Actions.ActOnCompoundStmt(Context, Loc, StmtList, StmtLabel); }
void TrainableOneClassSvmClassifier::addExamples(const vector<Mat>& newExamples) { // compute hyperplane distances of current positive examples and sort in descending order vector<pair<unsigned int, double>> distances; distances.reserve(examples.size()); if (isUsable()) { for (unsigned int i = 1; i < examples.size(); ++i) distances.push_back(make_pair(i, utils.computeSvmOutput(model.get(), examples[i].get()))); sort(distances.begin(), distances.end(), [](pair<unsigned int, double> a, pair<unsigned int, double> b) { return a.second > b.second; }); } else { for (unsigned int i = 1; i < examples.size(); ++i) distances.push_back(make_pair(i, 0.5)); } // add new positive examples as long as no examples have to be removed auto example = newExamples.cbegin(); for (; examples.size() < examples.capacity() && example != newExamples.cend(); ++example) examples.push_back(move(utils.createNode(*example))); // replace existing examples (beginning with the high distance ones) with new examples auto distanceIndex = distances.cbegin(); for (; example != newExamples.cend() && distanceIndex != distances.cend(); ++example, ++distanceIndex) examples[distanceIndex->first] = move(utils.createNode(*example)); }
vector<Observation> Localization::getRoomMarkers(vector<observationBlob>& topBlobs, vector<observationBlob>& middleBlobs, vector<observationBlob>& bottomBlobs, string id) { vector<Observation> ob; if ( isUsable(topBlobs) && isUsable(middleBlobs) && isUsable(bottomBlobs) ){ for( int i = 0; i < topBlobs.size(); i++ ) { for ( int k = 0; k < middleBlobs.size(); k++ ) { for ( int j = 0; j < bottomBlobs.size(); j++ ) { observationBlob& top = topBlobs[i]; observationBlob& middle = middleBlobs[k]; observationBlob& bottom = bottomBlobs[j]; if ( !top.Used() && !middle.Used() && !bottom.Used() ){ if (blobOnTopOf(top, middle) && blobOnTopOf(middle,bottom)) { int avgLeft = ( top.Left() + middle.Left() + bottom.Left() ) / 3 ; int avgRight = ( top.Right() + middle.Right() + bottom.Right() ) / 3 ; //int avgCenter = ( avgLeft + avgRight ) / 2 ; //double angleCenter = getAngle(avgCenter); double angleLeft, angleRight ; ( avgLeft > 5 ) ? angleLeft = getAngle(avgLeft) : angleLeft = Observation::InvalidBearing ; ( avgRight < 155 ) ? angleRight = getAngle(avgRight) : angleRight = Observation::InvalidBearing ; Observation observation = Observation(id, map, //angleCenter, observationVariance, angleLeft, angleRight); ob.push_back(observation); top.setInUse(); middle.setInUse(); bottom.setInUse(); if ( !isUsable(topBlobs) || !isUsable(middleBlobs) || !isUsable(bottomBlobs) ) return ob; } } } } } } return ob; }
void GLC_Shader::replaceShader(const GLC_Shader& sourceShader) { Q_ASSERT(isUsable() == sourceShader.isUsable()); // Test if the source shader is the same than this shader if (this == &sourceShader) { return; } m_ProgramShader.removeAllShaders(); if (sourceShader.m_VertexShader.isCompiled()) { m_VertexShader.compileSourceCode(sourceShader.m_VertexShader.sourceCode()); } if (sourceShader.m_FragmentShader.isCompiled()) { m_FragmentShader.compileSourceCode(sourceShader.m_FragmentShader.sourceCode()); } m_ProgramShader.link(); }
bool Action::resolve(Actor* source, Actor* target) const { if (!isUsable(source)) { return false; } if (cooldown().count()) { source->triggerCooldown(identifierHash(), cooldown()); } if (!isOffGlobalCooldown()) { source->triggerGlobalCooldown(); } source->triggerAnimationLock(animationLock()); source->setTP(source->tp() - tpCost() + tpRestoration()); source->setMP(source->mp() - mpCost(source) + mpRestoration(source)); Damage damage; if (this->damage(source, target)) { damage = target->acceptDamage(source->generateDamage(this, target)); } resolution(source, target, damage.isCritical); for (auto& aura : sourceAuras()) { source->applyAura(aura, source); } for (auto& aura : targetAuras()) { target->applyAura(aura, source); } source->integrateDamageStats(damage, identifier().c_str()); return true; }
/// ParseArrauSubscript - Parse an Array Subscript Expression ExprResult Parser::ParseArraySubscript(ExprResult Target) { SmallVector<Expr*, 8> ExprList; auto Loc = ConsumeParen(); bool IgnoreRParen = false; auto PunctuationTok = "("; do { if(Tok.isAtStartOfStatement()) IgnoreRParen = true; auto E = ParseArraySection(PunctuationTok); if(E.isInvalid()) SkipUntil(tok::comma, tok::r_paren, true, true); if(E.isUsable()) ExprList.push_back(E.get()); PunctuationTok = ","; } while(ConsumeIfPresent(tok::comma)); auto RParenLoc = getExpectedLoc(); if(!IgnoreRParen) ExpectAndConsume(tok::r_paren, 0, "", tok::r_paren); return Actions.ActOnSubscriptExpr(Context, Loc, RParenLoc, Target.get(), ExprList); }
WindowsSimPort::~WindowsSimPort() { delete portname; if(isUsable()) { CloseHandle(portHandle); } }
/// ParseIMPLICITStmt - Parse the IMPLICIT statement. /// /// [R560]: /// implicit-stmt := /// IMPLICIT implicit-spec-list /// or IMPLICIT NONE Parser::StmtResult Parser::ParseIMPLICITStmt() { // Check if this is an assignment. if (IsNextToken(tok::equal)) return StmtResult(); auto Loc = ConsumeToken(); if (ConsumeIfPresent(tok::kw_NONE)) { auto Result = Actions.ActOnIMPLICIT(Context, Loc, StmtLabel); ExpectStatementEnd(); return Result; } SmallVector<Stmt*, 8> StmtList; while(true) { // FIXME: improved error recovery DeclSpec DS; if (ParseDeclarationTypeSpec(DS, false)) return StmtError(); if(!ExpectAndConsume(tok::l_paren)) { if(!SkipUntil(tok::l_paren)) break; } bool InnerError = false; while(true) { auto FirstLoc = Tok.getLocation(); auto First = Tok.getIdentifierInfo(); if(!ExpectAndConsume(tok::identifier, diag::err_expected_letter)) { if(!SkipUntil(tok::comma)) { InnerError = true; break; } continue; } if(First->getName().size() > 1) { Diag.Report(FirstLoc, diag::err_expected_letter); } const IdentifierInfo *Second = nullptr; if (ConsumeIfPresent(tok::minus)) { auto SecondLoc = Tok.getLocation(); Second = Tok.getIdentifierInfo(); if(!ExpectAndConsume(tok::identifier, diag::err_expected_letter)) { if(!SkipUntil(tok::comma)) { InnerError = true; break; } continue; } if(Second->getName().size() > 1) { Diag.Report(SecondLoc, diag::err_expected_letter); } } auto Stmt = Actions.ActOnIMPLICIT(Context, Loc, DS, std::make_pair(First, Second), nullptr); if(Stmt.isUsable()) StmtList.push_back(Stmt.take()); if(ConsumeIfPresent(tok::comma)) continue; break; } if(InnerError && Tok.isAtStartOfStatement()) break; if(!ExpectAndConsume(tok::r_paren)) { if(!SkipUntil(tok::r_paren)) break; } if(Tok.isAtStartOfStatement()) break; if(!ExpectAndConsume(tok::comma)) { if(!SkipUntil(tok::comma)) break; } } ExpectStatementEnd(); return Actions.ActOnCompoundStmt(Context, Loc, StmtList, StmtLabel); }
void SelectRangeTool::onContentsChanged() { // TODO: find status before content changed, e.g. by caching emit isUsableChanged( isUsable() ); }