コード例 #1
0
ファイル: swsl_compiler.cpp プロジェクト: SirJonthe/SWSL
bool CompileStatement(CompileInstance &inst, const mtlChars &statement)
{
    if (IsGlobal(inst)) {
        AddError(inst, "Global statements not allowed", statement);
        return false;
    }

    Parser parser;
    parser.SetBuffer(statement);
    mtlList<mtlChars> m;
    mtlChars seq;
    bool result = false;
    switch (parser.Match("%w%w=%s%|%s=%s%|%w(%s)%|%w%w", m, &seq)) {
    case 0:
        result = DeclareVar(inst, m.GetFirst()->GetItem(), m.GetFirst()->GetNext()->GetItem(), m.GetFirst()->GetNext()->GetNext()->GetItem());
        break;
    case 1:
        result = AssignVar(inst, m.GetFirst()->GetItem(), m.GetFirst()->GetNext()->GetItem());
        break;
    case 2:
        // TODO: implement function calling
        // store result in temp
        result = false;
        AddError(inst, "Calling functions is not supported yet", seq);
        break;
    case 3:
        result = DeclareVar(inst, m.GetFirst()->GetItem(), m.GetFirst()->GetNext()->GetItem(), "");
        break;
    default:
        result = false;
        AddError(inst, "Malformed statement", statement);
        break;
    }
    return result;
}
コード例 #2
0
bool Muon::PassUserID_MuonTight_PFIso04 ( bool verbose ){

  double pfiso04 = ( PFIsoR04ChargedHadron() + std::max (0., PFIsoR04NeutralHadron() + PFIsoR04Photon() - ( 0.5 * PFIsoR04PU() ))) / Pt();
  
  bool pass_isGlobal  = bool ( IsGlobal()                   == 1   );
  bool pass_isPF      = bool ( IsPFMuon()                   == 1   );
  bool pass_chi2      = bool ( GlobalChi2 ()                 < 10. );
  bool pass_muonHits  = bool ( GlobalTrkValidHits()          > 0   );
  bool pass_stations  = bool ( StationMatches()              > 1   );
  bool pass_dxy       = bool ( fabs(BestTrackVtxDistXY())    < 0.2 );
  bool pass_dz        = bool ( fabs(BestTrackVtxDistZ ())    < 0.5 );
  bool pass_pixelHits = bool ( TrkPixelHits()                > 0   );
  bool pass_trkLayers = bool ( TrackLayersWithMeasurement()  > 5   );
  bool pass_pfiso04   = bool ( pfiso04                       < 0.12);
  
  bool decision = ( pass_isGlobal  && 
		    pass_isPF      && 
		    pass_chi2      && 
		    pass_muonHits  && 
		    pass_stations  && 
		    pass_dxy       && 
		    pass_dz        && 
		    pass_pixelHits && 
		    pass_trkLayers && 
		    pass_pfiso04   );
  
  return decision;
}
コード例 #3
0
ファイル: RegexPattern.cpp プロジェクト: EdMaurer/ChakraCore
    void RegexPattern::Print(DebugWriter* w)
    {
        w->Print(_u("/"));

        Js::InternalString str = GetSource();
        if (str.GetLength() == 0)
            w->Print(_u("(?:)"));
        else
        {
            for (charcount_t i = 0; i < str.GetLength(); ++i)
            {
                const char16 c = str.GetBuffer()[i];
                switch(c)
                {
                case _u('/'):
                    w->Print(_u("\\%lc"), c);
                    break;
                case _u('\n'):
                case _u('\r'):
                case _u('\x2028'):
                case _u('\x2029'):
                    w->PrintEscapedChar(c);
                    break;
                case _u('\\'):
                    Assert(i + 1 < str.GetLength()); // cannot end in a '\'
                    w->Print(_u("\\%lc"), str.GetBuffer()[++i]);
                    break;
                default:
                    w->PrintEscapedChar(c);
                    break;
                }
            }
        }
        w->Print(_u("/"));
        if (IsIgnoreCase())
            w->Print(_u("i"));
        if (IsGlobal())
            w->Print(_u("g"));
        if (IsMultiline())
            w->Print(_u("m"));
        if (IsUnicode())
            w->Print(_u("u"));
        if (IsSticky())
            w->Print(_u("y"));
        w->Print(_u(" /* "));
        w->Print(_u(", "));
        w->Print(isLiteral ? _u("literal") : _u("dynamic"));
        w->Print(_u(" */"));
    }
コード例 #4
0
    void RegexPattern::Print(DebugWriter* w)
    {
        w->Print(L"/");

        Js::InternalString str = GetSource();
        if (str.GetLength() == 0)
            w->Print(L"(?:)");
        else
        {
            for (charcount_t i = 0; i < str.GetLength(); ++i)
            {
                const wchar_t c = str.GetBuffer()[i];
                switch(c)
                {
                case L'/':
                    w->Print(L"\\%lc", c);
                    break;
                case L'\n':
                case L'\r':
                case L'\x2028':
                case L'\x2029':
                    w->PrintEscapedChar(c);
                    break;
                case L'\\':
                    Assert(i + 1 < str.GetLength()); // cannot end in a '\'
                    w->Print(L"\\%lc", str.GetBuffer()[++i]);
                    break;
                default:
                    w->PrintEscapedChar(c);
                    break;
                }
            }
        }
        w->Print(L"/");
        if (IsIgnoreCase())
            w->Print(L"i");
        if (IsGlobal())
            w->Print(L"g");
        if (IsMultiline())
            w->Print(L"m");
        if (IsUnicode())
            w->Print(L"u");
        if (IsSticky())
            w->Print(L"y");
        w->Print(L" /* ");
        w->Print(L", ");
        w->Print(isLiteral ? L"literal" : L"dynamic");
        w->Print(L" */");
    }
コード例 #5
0
ファイル: swsl_compiler.cpp プロジェクト: SirJonthe/SWSL
bool CompileFunction(CompileInstance &inst, const mtlChars &ret_type, const mtlChars &name, const mtlChars &params, const mtlChars &body)
{
    if (!IsGlobal(inst)) { // TODO: I want to support this eventually, but I need to emit jump instructions
        AddError(inst, "Nested functions not allowed", name);
        return false;
    }

    PushScope(inst, false);
    inst.scopes.GetLast()->GetItem().rel_sptr = 0; // reset the relative stack pointer
    bool result = true;
    bool is_main = false;
    result &= DeclareVar(inst, ret_type, name, "");

    if (name.Compare("main", true)) {
        ++inst.main;
        if (inst.main > 1) {
            AddError(inst, "Multiple entry points", "");
            return false;
        }
        *inst.prog_entry = (char)inst.program.GetSize();
        is_main = true;
    }

    Parser p;
    p.SetBuffer(params);
    mtlList<mtlChars> m;
    int stack_start = inst.scopes.GetLast()->GetItem().size;
    while (!p.IsEnd()) {
        if (p.MatchPart("%w%w", m, NULL) == 0) {
            result &= DeclareVar(inst, m.GetFirst()->GetItem(), m.GetFirst()->GetNext()->GetItem(), "");
        } else {
            AddError(inst, "Parameter syntax", params);
            return false;
        }
        p.MatchPart(",", m);
    }
    int stack_end = inst.scopes.GetLast()->GetItem().size;
    result &= CompileScope(inst, body, false);
    PopScope(inst);
    if (is_main) {
        *inst.prog_inputs = stack_end - stack_start;
        EmitInstruction(inst, swsl::END);
    } else {
        // FIX: This is a placeholder to prevent the compiler from optimizing stack manipulations
        EmitInstruction(inst, swsl::NOP); // this should emit a SET instruction (set the value of the return value)
    }
    return result;
}
コード例 #6
0
ファイル: variable.cpp プロジェクト: jjkee/hyphy
//__________________________________________________________________________________
void    _Variable::ClearConstraints (void)
{
    if (IsCategory ()) {
        _Variable newVar (*GetName(), IsGlobal());
        newVar.SetValue ((_PMathObj)Compute()->makeDynamic(),false);
        ReplaceVar ( &newVar);
        /*_Matrix * modelMatrix = (_Matrix*)LocateVar(modelMatrixIndices.lData[1])->GetValue();
        for (long k=0; k<4; k++)
            for (long k2 = 0; k2<4; k2++)
                if (k!=k2)
                {
                    StringToConsole (*(_String*)modelMatrix->GetFormula(k,k2)->toStr());
                    BufferToConsole ("\n");
                }
        */
    } else {
        if (!IsIndependent()) {
            SetValue ((_PMathObj)Compute()->makeDynamic(),false);
        }
        SetBounds (DEFAULTLOWERBOUND,DEFAULTUPPERBOUND);
    }
}
コード例 #7
0
// see: https://twiki.cern.ch/twiki/bin/view/CMS/SWGuideMuonIdRun2
bool Muon::PassUserID_MuonHighPt_TrkRelIso03 ( bool verbose ){

  double trkRelIsoR03 = (TrkIsoR03SumPt) / Pt();
  
  bool pass_isGlobal      = bool ( IsGlobal()                   == 1   );
  bool pass_muonHits      = bool ( GlobalTrkValidHits()          > 0   );
  bool pass_stations      = bool ( StationMatches()              > 1   );
  // PtErr ?
  //The pT relative error of the muon best track is less than 30%
  // recoMu.muonBestTrack()->ptError()/recoMu.muonBestTrack()->pt() < 0.3
  // - we can use either the inner track or the global track pt error for the moment
  // use global for now
  bool pass_ptErr         = bool ( PtError()/Pt()                < 0.3 );
  bool pass_dxy           = bool ( fabs(BestTrackVtxDistXY())    < 0.2 );
  // [1] The most accurate way of computing this value is by using IPTools (example).
  // The dB() method of the pat::Muon uses the version in IPTools, so there are tiny differences
  //   between the values returned by dxy(vertex->position()) and dB(). 
  bool pass_dz            = bool ( fabs(BestTrackVtxDistZ ())    < 0.5 );
  bool pass_pixelHits     = bool ( TrkPixelHits()                > 0   );
  bool pass_trkLayers     = bool ( TrackLayersWithMeasurement()  > 5   );
  // tight
  bool pass_trkRelIsoR03_tight = bool ( trkRelIsoR03             < 0.05);
  // loose
  bool pass_trkRelIsoR03_loose = bool ( trkRelIsoR03             < 0.10);
  
  bool decision = (
      pass_isGlobal  && 
      pass_muonHits  && 
      pass_stations  && 
      pass_ptErr     &&
      pass_dxy       && 
      pass_dz        && 
      pass_pixelHits && 
      pass_trkLayers && 
      pass_trkRelIsoR03_tight
      );
  
  return decision;
}
コード例 #8
0
ファイル: Modules.cpp プロジェクト: stevestreza/ZNC-Node
ModHandle CModules::OpenModule(const CString& sModule, const CString& sModPath, bool &bVersionMismatch,
		bool &bIsGlobal, CString& sDesc, CString& sRetMsg) {
	// Some sane defaults in case anything errors out below
	bVersionMismatch = false;
	bIsGlobal = false;
	sDesc.clear();
	sRetMsg.clear();

	for (unsigned int a = 0; a < sModule.length(); a++) {
		if (((sModule[a] < '0') || (sModule[a] > '9')) && ((sModule[a] < 'a') || (sModule[a] > 'z')) && ((sModule[a] < 'A') || (sModule[a] > 'Z')) && (sModule[a] != '_')) {
			sRetMsg = "Module names can only contain letters, numbers and underscores, [" + sModule + "] is invalid.";
			return NULL;
		}
	}

	// The second argument to dlopen() has a long history. It seems clear
	// that (despite what the man page says) we must include either of
	// RTLD_NOW and RTLD_LAZY and either of RTLD_GLOBAL and RTLD_LOCAL.
	//
	// RTLD_NOW vs. RTLD_LAZY: We use RTLD_NOW to avoid znc dying due to
	// failed symbol lookups later on. Doesn't really seem to have much of a
	// performance impact.
	//
	// RTLD_GLOBAL vs. RTLD_LOCAL: If perl is loaded with RTLD_LOCAL and later on
	// loads own modules (which it apparently does with RTLD_LAZY), we will die in a
	// name lookup since one of perl's symbols isn't found. That's worse
	// than any theoretical issue with RTLD_GLOBAL.
	ModHandle p = dlopen((sModPath).c_str(), RTLD_NOW | RTLD_GLOBAL);

	if (!p) {
		sRetMsg = "Unable to open module [" + sModule + "] [" + dlerror() + "]";
		return NULL;
	}

	typedef double (*dFP)();
	dFP Version = (dFP) dlsym(p, "ZNCModVersion");

	if (!Version) {
		dlclose(p);
		sRetMsg = "Could not find ZNCModVersion() in module [" + sModule + "]";
		return NULL;
	}

	typedef bool (*bFP)();
	bFP IsGlobal = (bFP) dlsym(p, "ZNCModGlobal");

	if (!IsGlobal) {
		dlclose(p);
		sRetMsg = "Could not find ZNCModGlobal() in module [" + sModule + "]";
		return NULL;
	}

	typedef const char *(*sFP)();
	sFP GetDesc = (sFP) dlsym(p, "ZNCModDescription");

	if (!GetDesc) {
		dlclose(p);
		sRetMsg = "Could not find ZNCModDescription() in module [" + sModule + "]";
		return false;
	}

	if (CModule::GetCoreVersion() != Version()) {
		bVersionMismatch = true;
		sRetMsg = "Version mismatch, recompile this module.";
	} else {
		sRetMsg = "";
		bVersionMismatch = false;
		bIsGlobal = IsGlobal();
		sDesc = GetDesc();
	}

	return p;
}
コード例 #9
0
ファイル: WebParser.cpp プロジェクト: ksujaym/rainmeter
		bool IsInvalid() { return (m_Ref <= 0 && !IsGlobal()); }