inline CG<Base>& CG<Base>::operator*=(const CG<Base> &right) { if (isParameter() && right.isParameter()) { *value_ *= *right.value_; } else { CodeHandler<Base>* handler; if (isParameter()) { if (isIdenticalZero()) { return *this; // nothing to do (does not consider that right might be infinity) } else if (isIdenticalOne()) { *this = right; return *this; } handler = right.getCodeHandler(); } else if (right.isParameter()) { if (right.isIdenticalZero()) { makeParameter(Base(0.0)); // does not consider that left might be infinity return *this; } else if (right.isIdenticalOne()) { return *this; // nothing to do } handler = getCodeHandler(); } else { CPPADCG_ASSERT_UNKNOWN(getCodeHandler() == right.getCodeHandler()); handler = getCodeHandler(); } std::unique_ptr<Base> value; if (isValueDefined() && right.isValueDefined()) { value.reset(new Base(getValue() * right.getValue())); } makeVariable(*handler, new OperationNode<Base>(CGOpCode::Mul,{argument(), right.argument()}), value); } return *this; }
CharacterValueTy CharacterExprEmitter::VisitVarExpr(const VarExpr *E) { auto VD = E->getVarDecl(); if(CGF.IsInlinedArgument(VD)) return CGF.GetInlinedArgumentValue(VD).asCharacter(); if(VD->isArgument()) return CGF.GetCharacterArg(VD); else if(VD->isParameter()) return EmitExpr(VD->getInit()); else if(VD->isFunctionResult()) return CGF.ExtractCharacterValue(CGF.GetRetVarPtr()); return CGF.GetCharacterValueFromPtr(CGF.GetVarPtr(VD), VD->getType()); }
Qt::ItemFlags ParameterFileModel::flags(const QModelIndex& ind) const { if (!prefixValid() || ind.row() < 0 || ind.row() >= _keys.size()) { return Qt::NoItemFlags; } Q_ASSERT(ind.row() >= 0); Q_ASSERT(ind.row() < _keys.size()); Qt::ItemFlags res = Qt::NoItemFlags; QString paramType; QVariant::Type dataType; switch (ind.column()) { case 0: // parameter names editable, if _onlyParams is not selected res = Qt::ItemIsSelectable | Qt::ItemIsEnabled; if (!_onlyParams) { res = res | Qt::ItemIsEditable; } break; case 1: res = Qt::ItemIsSelectable | Qt::ItemIsEnabled; paramType = getType(_keys[ind.row()]); dataType = data(ind).type(); if (_useMetaInfo && isParameter(_keys[ind.row()]) && paramType == "bool") { // bool parameters are user checkable res = res | Qt::ItemIsUserCheckable; } else { // all non-bool parameters allow editing (delegate) res = res | Qt::ItemIsEditable; if (dataType == QVariant::String && !paramType.contains(QRegExp("^\\{\\s*\\w.*\\}\\s*$"))) { // string entries that do not represent a selection // may be entered by dropping some values res = res | Qt::ItemIsDropEnabled; } } break; case 2: res = Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsEditable; break; default: break; } return res; }
int ParameterModel::rowCount(const QModelIndex & parent) const { if( m_effect != NULL ) { if( !parent.isValid() ) { return m_effect->parameterCount(); } else if( isParameter(parent) ) { return parameter(parent)->componentCount(); } } return 0; }
static Token makeToken(const std::string& token_str) { Type type; if (token_str == "\n") { type = DELIMITER; } else if (isParameter(token_str) != -1) { type = PARAMETER; } else if (isSpecification(token_str)) { type = SPECIFICATION; } else if (isFunction(token_str) != -1) { type = FUNCTION; } else { throw Exception("Interpreter: invalid token"); } Token token( type, isParameter(token_str), isSpecification(token_str), isFunction(token_str) ); return token; }
inline CG<Base>& CG<Base>::operator+=(const CG<Base> &right) { if (isParameter() && right.isParameter()) { *value_ += *right.value_; } else { CodeHandler<Base>* handler; if (isParameter()) { if (isIdenticalZero()) { *this = right; return *this; } handler = right.getCodeHandler(); } else if (right.isParameter()) { if (right.isIdenticalZero()) { return *this; // nothing to do } handler = getCodeHandler(); } else { CPPADCG_ASSERT_UNKNOWN(getCodeHandler() == right.getCodeHandler()); handler = getCodeHandler(); } std::unique_ptr<Base> value; if (isValueDefined() && right.isValueDefined()) { value.reset(new Base(getValue() + right.getValue())); } makeVariable(*handler, new OperationNode<Base>(CGOpCode::Add,{argument(), right.argument()}), value); } return *this; }
ATerm getTermSort(ATerm term){ ATerm sort; if(isVariable(term)){ sort = ATtableGet(var_tab, term); } else if(isParameter(term)){ sort = ATtableGet(par_tab, term); } else { sort = (ATerm) ATmake("<str>",ATgetName(MCRLgetSort(term))); } if(!strcmp("\"<int>\"", ATwriteToString(sort))){ PP("ERROR: "); PP(ATgetName(MCRLgetSort(term))); fprintf(stderr, " %d ", nSum); pTerm(term); exit(0); } return sort; }
bool Sema::CheckEquivalenceObject(SourceLocation Loc, Expr *E, VarDecl *& Object) { if(auto Var = dyn_cast<VarExpr>(E)) { auto VD = Var->getVarDecl(); if(VD->isArgument() || VD->isParameter()) { Diags.Report(Loc, diag::err_spec_requires_local_var) << E->getSourceRange(); Diags.Report(VD->getLocation(), diag::note_previous_definition_kind) << VD->getIdentifier() << (VD->isArgument()? 0 : 1) << getTokenRange(VD->getLocation()); return true; } if(VD->isUnusedSymbol()) const_cast<VarDecl*>(VD)->MarkUsedAsVariable(E->getLocation()); Object = const_cast<VarDecl*>(VD); } else { Diags.Report(Loc, diag::err_spec_requires_var_or_arr_el) << E->getSourceRange(); return true; } return false; }
ATerm termAbstraction(ATerm term, ATerm dstSort){ ATerm newCons; AFun singTag; ATerm termSort, parSort; if(!(isVariable(term) || isParameter(term) || isConstant(term))){ term = funcAbstraction(term, dstSort); } termSort = getTermSort(term); if(isLifted(dstSort)){ if(isAbstracted(dstSort)){ if(!isAbstracted(termSort)){ if(!isLifted(termSort)){ termSort = liftSort(termSort); term = createSingTerm(term, termSort); } term = createAlphaTerm(term, termSort); } else{ if(!isLifted(termSort)){ termSort = liftSort(abstractSort(termSort)); term = createSingTerm(term, termSort); } } } else{ if(!isLifted(termSort)){ termSort = liftSort(termSort); term = createSingTerm(term, termSort); } } } return term; }
int GUICtrlTemplate::AddComboItem( QString& _title, HKParameter& _value ) { if ( _value.getType() != getType() ) return -1; if ( isParameter( INT_PROP_NAME__VALUE ) ) { HKParameter& v = getParameter( INT_PROP_NAME__VALUE ); if( v.getType() != HKParameterType_Array || v.m_array == 0 || v.m_array->size() % 2 ) return -1; v.m_array->push_back( HKParameter(_title) ); v.m_array->push_back( _value ); } else { HKParameterArray *m_array = new HKParameterArray; m_array->push_back( HKParameter(_title) ); m_array->push_back( _value ); HKParameter p( *m_array ); setParameter( INT_PROP_NAME__VALUE, p ); delete m_array; } return 0; }
Symbol *VarDeclaration::toSymbol() { //printf("VarDeclaration::toSymbol(%s)\n", toChars()); //if (needThis()) *(char*)0=0; assert(!needThis()); if (!csym) { TYPE *t; const char *id; if (isDataseg()) id = mangle(); else id = ident->toChars(); Symbol *s = symbol_calloc(id); s->Salignment = alignment; if (storage_class & (STCout | STCref)) { // should be TYref, but problems in back end t = type_pointer(type->toCtype()); } else if (storage_class & STClazy) { if (config.exe == EX_WIN64 && isParameter()) t = type_fake(TYnptr); else t = type_fake(TYdelegate); // Tdelegate as C type t->Tcount++; } else if (isParameter()) { if (config.exe == EX_WIN64 && type->size(Loc()) > REGSIZE) { // should be TYref, but problems in back end t = type_pointer(type->toCtype()); } else { t = type->toCParamtype(); t->Tcount++; } } else { t = type->toCtype(); t->Tcount++; } if (isDataseg()) { if (isThreadlocal()) { /* Thread local storage */ TYPE *ts = t; ts->Tcount++; // make sure a different t is allocated type_setty(&t, t->Tty | mTYthread); ts->Tcount--; if (global.params.vtls) { char *p = loc.toChars(); fprintf(stderr, "%s: %s is thread local\n", p ? p : "", toChars()); if (p) mem.free(p); } } s->Sclass = SCextern; s->Sfl = FLextern; slist_add(s); /* if it's global or static, then it needs to have a qualified but unmangled name. * This gives some explanation of the separation in treating name mangling. * It applies to PDB format, but should apply to CV as PDB derives from CV. * http://msdn.microsoft.com/en-us/library/ff553493(VS.85).aspx */ s->prettyIdent = toPrettyChars(); } else { s->Sclass = SCauto; s->Sfl = FLauto; if (nestedrefs.dim) { /* Symbol is accessed by a nested function. Make sure * it is not put in a register, and that the optimizer * assumes it is modified across function calls and pointer * dereferences. */ //printf("\tnested ref, not register\n"); type_setcv(&t, t->Tty | mTYvolatile); } } if (ident == Id::va_argsave) /* __va_argsave is set outside of the realm of the optimizer, * so we tell the optimizer to leave it alone */ type_setcv(&t, t->Tty | mTYvolatile); mangle_t m = 0; switch (linkage) { case LINKwindows: m = mTYman_std; break; case LINKpascal: m = mTYman_pas; break; case LINKc: m = mTYman_c; break; case LINKd: m = mTYman_d; break; case LINKcpp: { m = mTYman_cpp; s->Sflags = SFLpublic; Dsymbol *parent = toParent(); ClassDeclaration *cd = parent->isClassDeclaration(); if (cd) { ::type *tc = cd->type->toCtype(); s->Sscope = tc->Tnext->Ttag; } StructDeclaration *sd = parent->isStructDeclaration(); if (sd) { ::type *ts = sd->type->toCtype(); s->Sscope = ts->Ttag; } break; } default: printf("linkage = %d\n", linkage); assert(0); } type_setmangle(&t, m); s->Stype = t; csym = s; } return csym; }
void Declaration::checkModify(Loc loc, Scope *sc, Type *t) { if (sc->incontract && isParameter()) error(loc, "cannot modify parameter '%s' in contract", toChars()); if (sc->incontract && isResult()) error(loc, "cannot modify result '%s' in contract", toChars()); if (isCtorinit() && !t->isMutable()) { // It's only modifiable if inside the right constructor Dsymbol *s = sc->func; while (1) { FuncDeclaration *fd = NULL; if (s) fd = s->isFuncDeclaration(); if (fd && ((fd->isCtorDeclaration() && storage_class & STCfield) || (fd->isStaticCtorDeclaration() && !(storage_class & STCfield))) && fd->toParent() == toParent() ) { VarDeclaration *v = isVarDeclaration(); assert(v); v->ctorinit = 1; //printf("setting ctorinit\n"); } else { if (s) { s = s->toParent2(); continue; } else { const char *p = isStatic() ? "static " : ""; error(loc, "can only initialize %sconst %s inside %sconstructor", p, toChars(), p); } } break; } } else { VarDeclaration *v = isVarDeclaration(); if (v && v->canassign == 0) { const char *p = NULL; if (isConst()) p = "const"; else if (isImmutable()) p = "immutable"; else if (storage_class & STCmanifest) p = "enum"; else if (!t->isAssignable()) p = "struct with immutable members"; if (p) { error(loc, "cannot modify %s", p); } } } }
Expression *semanticTraits(TraitsExp *e, Scope *sc) { #if LOGSEMANTIC printf("TraitsExp::semantic() %s\n", e->toChars()); #endif if (e->ident != Id::compiles && e->ident != Id::isSame && e->ident != Id::identifier && e->ident != Id::getProtection) { if (!TemplateInstance::semanticTiargs(e->loc, sc, e->args, 1)) return new ErrorExp(); } size_t dim = e->args ? e->args->dim : 0; if (e->ident == Id::isArithmetic) { return isTypeX(e, &isTypeArithmetic); } else if (e->ident == Id::isFloating) { return isTypeX(e, &isTypeFloating); } else if (e->ident == Id::isIntegral) { return isTypeX(e, &isTypeIntegral); } else if (e->ident == Id::isScalar) { return isTypeX(e, &isTypeScalar); } else if (e->ident == Id::isUnsigned) { return isTypeX(e, &isTypeUnsigned); } else if (e->ident == Id::isAssociativeArray) { return isTypeX(e, &isTypeAssociativeArray); } else if (e->ident == Id::isStaticArray) { return isTypeX(e, &isTypeStaticArray); } else if (e->ident == Id::isAbstractClass) { return isTypeX(e, &isTypeAbstractClass); } else if (e->ident == Id::isFinalClass) { return isTypeX(e, &isTypeFinalClass); } else if (e->ident == Id::isPOD) { if (dim != 1) goto Ldimerror; RootObject *o = (*e->args)[0]; Type *t = isType(o); StructDeclaration *sd; if (!t) { e->error("type expected as second argument of __traits %s instead of %s", e->ident->toChars(), o->toChars()); goto Lfalse; } Type *tb = t->baseElemOf(); if (tb->ty == Tstruct && ((sd = (StructDeclaration *)(((TypeStruct *)tb)->sym)) != NULL)) { if (sd->isPOD()) goto Ltrue; else goto Lfalse; } goto Ltrue; } else if (e->ident == Id::isNested) { if (dim != 1) goto Ldimerror; RootObject *o = (*e->args)[0]; Dsymbol *s = getDsymbol(o); AggregateDeclaration *a; FuncDeclaration *f; if (!s) { } else if ((a = s->isAggregateDeclaration()) != NULL) { if (a->isNested()) goto Ltrue; else goto Lfalse; } else if ((f = s->isFuncDeclaration()) != NULL) { if (f->isNested()) goto Ltrue; else goto Lfalse; } e->error("aggregate or function expected instead of '%s'", o->toChars()); goto Lfalse; } else if (e->ident == Id::isAbstractFunction) { return isFuncX(e, &isFuncAbstractFunction); } else if (e->ident == Id::isVirtualFunction) { return isFuncX(e, &isFuncVirtualFunction); } else if (e->ident == Id::isVirtualMethod) { return isFuncX(e, &isFuncVirtualMethod); } else if (e->ident == Id::isFinalFunction) { return isFuncX(e, &isFuncFinalFunction); } else if (e->ident == Id::isOverrideFunction) { return isFuncX(e, &isFuncOverrideFunction); } else if (e->ident == Id::isStaticFunction) { return isFuncX(e, &isFuncStaticFunction); } else if (e->ident == Id::isRef) { return isDeclX(e, &isDeclRef); } else if (e->ident == Id::isOut) { return isDeclX(e, &isDeclOut); } else if (e->ident == Id::isLazy) { return isDeclX(e, &isDeclLazy); } else if (e->ident == Id::identifier) { // Get identifier for symbol as a string literal /* Specify 0 for bit 0 of the flags argument to semanticTiargs() so that * a symbol should not be folded to a constant. * Bit 1 means don't convert Parameter to Type if Parameter has an identifier */ if (!TemplateInstance::semanticTiargs(e->loc, sc, e->args, 2)) return new ErrorExp(); if (dim != 1) goto Ldimerror; RootObject *o = (*e->args)[0]; Parameter *po = isParameter(o); Identifier *id; if (po) { id = po->ident; assert(id); } else { Dsymbol *s = getDsymbol(o); if (!s || !s->ident) { e->error("argument %s has no identifier", o->toChars()); goto Lfalse; } id = s->ident; } StringExp *se = new StringExp(e->loc, id->toChars()); return se->semantic(sc); } else if (e->ident == Id::getProtection) { if (dim != 1) goto Ldimerror; Scope *sc2 = sc->push(); sc2->flags = sc->flags | SCOPEnoaccesscheck; bool ok = TemplateInstance::semanticTiargs(e->loc, sc2, e->args, 1); sc2->pop(); if (!ok) return new ErrorExp(); RootObject *o = (*e->args)[0]; Dsymbol *s = getDsymbol(o); if (!s) { if (!isError(o)) e->error("argument %s has no protection", o->toChars()); goto Lfalse; } if (s->scope) s->semantic(s->scope); PROT protection = s->prot(); const char *protName = Pprotectionnames[protection]; assert(protName); StringExp *se = new StringExp(e->loc, (char *) protName); return se->semantic(sc); } else if (e->ident == Id::parent) { if (dim != 1) goto Ldimerror; RootObject *o = (*e->args)[0]; Dsymbol *s = getDsymbol(o); if (s) { if (FuncDeclaration *fd = s->isFuncDeclaration()) // Bugzilla 8943 s = fd->toAliasFunc(); if (!s->isImport()) // Bugzilla 8922 s = s->toParent(); } if (!s || s->isImport()) { e->error("argument %s has no parent", o->toChars()); goto Lfalse; } if (FuncDeclaration *f = s->isFuncDeclaration()) { if (TemplateDeclaration *td = getFuncTemplateDecl(f)) { if (td->overroot) // if not start of overloaded list of TemplateDeclaration's td = td->overroot; // then get the start Expression *ex = new TemplateExp(e->loc, td, f); ex = ex->semantic(sc); return ex; } if (FuncLiteralDeclaration *fld = f->isFuncLiteralDeclaration()) { // Directly translate to VarExp instead of FuncExp Expression *ex = new VarExp(e->loc, fld, 1); return ex->semantic(sc); } } return (new DsymbolExp(e->loc, s))->semantic(sc); } else if (e->ident == Id::hasMember || e->ident == Id::getMember || e->ident == Id::getOverloads || e->ident == Id::getVirtualMethods || e->ident == Id::getVirtualFunctions) { if (dim != 2) goto Ldimerror; RootObject *o = (*e->args)[0]; Expression *ex = isExpression((*e->args)[1]); if (!ex) { e->error("expression expected as second argument of __traits %s", e->ident->toChars()); goto Lfalse; } ex = ex->ctfeInterpret(); StringExp *se = ex->toStringExp(); if (!se || se->length() == 0) { e->error("string expected as second argument of __traits %s instead of %s", e->ident->toChars(), ex->toChars()); goto Lfalse; } se = se->toUTF8(sc); if (se->sz != 1) { e->error("string must be chars"); goto Lfalse; } Identifier *id = Lexer::idPool((char *)se->string); /* Prefer dsymbol, because it might need some runtime contexts. */ Dsymbol *sym = getDsymbol(o); if (sym) { ex = new DsymbolExp(e->loc, sym); ex = new DotIdExp(e->loc, ex, id); } else if (Type *t = isType(o)) ex = typeDotIdExp(e->loc, t, id); else if (Expression *ex2 = isExpression(o)) ex = new DotIdExp(e->loc, ex2, id); else { e->error("invalid first argument"); goto Lfalse; } if (e->ident == Id::hasMember) { if (sym) { Dsymbol *sm = sym->search(e->loc, id); if (sm) goto Ltrue; } /* Take any errors as meaning it wasn't found */ Scope *sc2 = sc->push(); ex = ex->trySemantic(sc2); sc2->pop(); if (!ex) goto Lfalse; else goto Ltrue; } else if (e->ident == Id::getMember) { ex = ex->semantic(sc); return ex; } else if (e->ident == Id::getVirtualFunctions || e->ident == Id::getVirtualMethods || e->ident == Id::getOverloads) { unsigned errors = global.errors; Expression *eorig = ex; ex = ex->semantic(sc); if (errors < global.errors) e->error("%s cannot be resolved", eorig->toChars()); /* Create tuple of functions of ex */ //ex->print(); Expressions *exps = new Expressions(); FuncDeclaration *f; if (ex->op == TOKvar) { VarExp *ve = (VarExp *)ex; f = ve->var->isFuncDeclaration(); ex = NULL; } else if (ex->op == TOKdotvar) { DotVarExp *dve = (DotVarExp *)ex; f = dve->var->isFuncDeclaration(); if (dve->e1->op == TOKdottype || dve->e1->op == TOKthis) ex = NULL; else ex = dve->e1; } else f = NULL; Ptrait p; p.exps = exps; p.e1 = ex; p.ident = e->ident; overloadApply(f, &p, &fptraits); TupleExp *tup = new TupleExp(e->loc, exps); return tup->semantic(sc); } else assert(0); } else if (e->ident == Id::classInstanceSize) { if (dim != 1) goto Ldimerror; RootObject *o = (*e->args)[0]; Dsymbol *s = getDsymbol(o); ClassDeclaration *cd; if (!s || (cd = s->isClassDeclaration()) == NULL) { e->error("first argument is not a class"); goto Lfalse; } if (cd->sizeok == SIZEOKnone) { if (cd->scope) cd->semantic(cd->scope); } if (cd->sizeok != SIZEOKdone) { e->error("%s %s is forward referenced", cd->kind(), cd->toChars()); goto Lfalse; } return new IntegerExp(e->loc, cd->structsize, Type::tsize_t); } else if (e->ident == Id::getAliasThis) { if (dim != 1) goto Ldimerror; RootObject *o = (*e->args)[0]; Dsymbol *s = getDsymbol(o); AggregateDeclaration *ad; if (!s || (ad = s->isAggregateDeclaration()) == NULL) { e->error("argument is not an aggregate type"); goto Lfalse; } Expressions *exps = new Expressions(); if (ad->aliasthis) exps->push(new StringExp(e->loc, ad->aliasthis->ident->toChars())); Expression *ex = new TupleExp(e->loc, exps); ex = ex->semantic(sc); return ex; } else if (e->ident == Id::getAttributes) { if (dim != 1) goto Ldimerror; RootObject *o = (*e->args)[0]; Dsymbol *s = getDsymbol(o); if (!s) { #if 0 Expression *x = isExpression(o); Type *t = isType(o); if (x) printf("e = %s %s\n", Token::toChars(x->op), x->toChars()); if (t) printf("t = %d %s\n", t->ty, t->toChars()); #endif e->error("first argument is not a symbol"); goto Lfalse; } //printf("getAttributes %s, attrs = %p, scope = %p\n", s->toChars(), s->userAttributes, s->userAttributesScope); UserAttributeDeclaration *udad = s->userAttribDecl; TupleExp *tup = new TupleExp(e->loc, udad ? udad->getAttributes() : new Expressions()); return tup->semantic(sc); } else if (e->ident == Id::getFunctionAttributes) { /// extract all function attributes as a tuple (const/shared/inout/pure/nothrow/etc) except UDAs. if (dim != 1) goto Ldimerror; RootObject *o = (*e->args)[0]; Dsymbol *s = getDsymbol(o); Type *t = isType(o); TypeFunction *tf = NULL; if (s) { if (FuncDeclaration *f = s->isFuncDeclaration()) t = f->type; else if (VarDeclaration *v = s->isVarDeclaration()) t = v->type; } if (t) { if (t->ty == Tfunction) tf = (TypeFunction *)t; else if (t->ty == Tdelegate) tf = (TypeFunction *)t->nextOf(); else if (t->ty == Tpointer && t->nextOf()->ty == Tfunction) tf = (TypeFunction *)t->nextOf(); } if (!tf) { e->error("first argument is not a function"); goto Lfalse; } Expressions *mods = new Expressions(); PushAttributes pa; pa.mods = mods; tf->modifiersApply(&pa, &PushAttributes::fp); tf->attributesApply(&pa, &PushAttributes::fp, TRUSTformatSystem); TupleExp *tup = new TupleExp(e->loc, mods); return tup->semantic(sc); } else if (e->ident == Id::allMembers || e->ident == Id::derivedMembers) { if (dim != 1) goto Ldimerror; RootObject *o = (*e->args)[0]; Dsymbol *s = getDsymbol(o); ScopeDsymbol *sds; if (!s) { e->error("argument has no members"); goto Lfalse; } Import *import; if ((import = s->isImport()) != NULL) { // Bugzilla 9692 sds = import->mod; } else if ((sds = s->isScopeDsymbol()) == NULL) { e->error("%s %s has no members", s->kind(), s->toChars()); goto Lfalse; } // use a struct as local function struct PushIdentsDg { static int dg(void *ctx, size_t n, Dsymbol *sm) { if (!sm) return 1; //printf("\t[%i] %s %s\n", i, sm->kind(), sm->toChars()); if (sm->ident) { if (sm->ident != Id::ctor && sm->ident != Id::dtor && sm->ident != Id::_postblit && memcmp(sm->ident->string, "__", 2) == 0) { return 0; } //printf("\t%s\n", sm->ident->toChars()); Identifiers *idents = (Identifiers *)ctx; /* Skip if already present in idents[] */ for (size_t j = 0; j < idents->dim; j++) { Identifier *id = (*idents)[j]; if (id == sm->ident) return 0; #ifdef DEBUG // Avoid using strcmp in the first place due to the performance impact in an O(N^2) loop. assert(strcmp(id->toChars(), sm->ident->toChars()) != 0); #endif } idents->push(sm->ident); } else { EnumDeclaration *ed = sm->isEnumDeclaration(); if (ed) { ScopeDsymbol::foreach(NULL, ed->members, &PushIdentsDg::dg, (Identifiers *)ctx); } } return 0; } }; Identifiers *idents = new Identifiers; ScopeDsymbol::foreach(sc, sds->members, &PushIdentsDg::dg, idents); ClassDeclaration *cd = sds->isClassDeclaration(); if (cd && e->ident == Id::allMembers) { struct PushBaseMembers { static void dg(ClassDeclaration *cd, Identifiers *idents) { for (size_t i = 0; i < cd->baseclasses->dim; i++) { ClassDeclaration *cb = (*cd->baseclasses)[i]->base; ScopeDsymbol::foreach(NULL, cb->members, &PushIdentsDg::dg, idents); if (cb->baseclasses->dim) dg(cb, idents); } } }; PushBaseMembers::dg(cd, idents); } // Turn Identifiers into StringExps reusing the allocated array assert(sizeof(Expressions) == sizeof(Identifiers)); Expressions *exps = (Expressions *)idents; for (size_t i = 0; i < idents->dim; i++) { Identifier *id = (*idents)[i]; StringExp *se = new StringExp(e->loc, id->toChars()); (*exps)[i] = se; } /* Making this a tuple is more flexible, as it can be statically unrolled. * To make an array literal, enclose __traits in [ ]: * [ __traits(allMembers, ...) ] */ Expression *ex = new TupleExp(e->loc, exps); ex = ex->semantic(sc); return ex; } else if (e->ident == Id::compiles) { /* Determine if all the objects - types, expressions, or symbols - * compile without error */ if (!dim) goto Lfalse; for (size_t i = 0; i < dim; i++) { unsigned errors = global.startGagging(); unsigned oldspec = global.speculativeGag; global.speculativeGag = global.gag; Scope *sc2 = sc->push(); sc2->speculative = true; sc2->flags = sc->flags & ~SCOPEctfe | SCOPEcompile; bool err = false; RootObject *o = (*e->args)[i]; Type *t = isType(o); Expression *ex = t ? t->toExpression() : isExpression(o); if (!ex && t) { Dsymbol *s; t->resolve(e->loc, sc2, &ex, &t, &s); if (t) { t->semantic(e->loc, sc2); if (t->ty == Terror) err = true; } else if (s && s->errors) err = true; } if (ex) { ex = ex->semantic(sc2); ex = resolvePropertiesOnly(sc2, ex); ex = ex->optimize(WANTvalue); ex = checkGC(sc2, ex); if (ex->op == TOKerror) err = true; } sc2->pop(); global.speculativeGag = oldspec; if (global.endGagging(errors) || err) { goto Lfalse; } } goto Ltrue; } else if (e->ident == Id::isSame) { /* Determine if two symbols are the same */ if (dim != 2) goto Ldimerror; if (!TemplateInstance::semanticTiargs(e->loc, sc, e->args, 0)) return new ErrorExp(); RootObject *o1 = (*e->args)[0]; RootObject *o2 = (*e->args)[1]; Dsymbol *s1 = getDsymbol(o1); Dsymbol *s2 = getDsymbol(o2); //printf("isSame: %s, %s\n", o1->toChars(), o2->toChars()); #if 0 printf("o1: %p\n", o1); printf("o2: %p\n", o2); if (!s1) { Expression *ea = isExpression(o1); if (ea) printf("%s\n", ea->toChars()); Type *ta = isType(o1); if (ta) printf("%s\n", ta->toChars()); goto Lfalse; } else printf("%s %s\n", s1->kind(), s1->toChars()); #endif if (!s1 && !s2) { Expression *ea1 = isExpression(o1); Expression *ea2 = isExpression(o2); if (ea1 && ea2) { if (ea1->equals(ea2)) goto Ltrue; } } if (!s1 || !s2) goto Lfalse; s1 = s1->toAlias(); s2 = s2->toAlias(); if (s1->isFuncAliasDeclaration()) s1 = ((FuncAliasDeclaration *)s1)->toAliasFunc(); if (s2->isFuncAliasDeclaration()) s2 = ((FuncAliasDeclaration *)s2)->toAliasFunc(); if (s1 == s2) goto Ltrue; else goto Lfalse; } else if (e->ident == Id::getUnitTests) { if (dim != 1) goto Ldimerror; RootObject *o = (*e->args)[0]; Dsymbol *s = getDsymbol(o); if (!s) { e->error("argument %s to __traits(getUnitTests) must be a module or aggregate", o->toChars()); goto Lfalse; } Import *imp = s->isImport(); if (imp) // Bugzilla 10990 s = imp->mod; ScopeDsymbol* scope = s->isScopeDsymbol(); if (!scope) { e->error("argument %s to __traits(getUnitTests) must be a module or aggregate, not a %s", s->toChars(), s->kind()); goto Lfalse; } Expressions* unitTests = new Expressions(); Dsymbols* symbols = scope->members; if (global.params.useUnitTests && symbols) { // Should actually be a set AA* uniqueUnitTests = NULL; collectUnitTests(symbols, uniqueUnitTests, unitTests); } TupleExp *tup = new TupleExp(e->loc, unitTests); return tup->semantic(sc); } else if(e->ident == Id::getVirtualIndex) { if (dim != 1) goto Ldimerror; RootObject *o = (*e->args)[0]; Dsymbol *s = getDsymbol(o); FuncDeclaration *fd; if (!s || (fd = s->isFuncDeclaration()) == NULL) { e->error("first argument to __traits(getVirtualIndex) must be a function"); goto Lfalse; } fd = fd->toAliasFunc(); // Neccessary to support multiple overloads. return new IntegerExp(e->loc, fd->vtblIndex, Type::tptrdiff_t); } else { if (const char *sub = (const char *)speller(e->ident->toChars(), &trait_search_fp, NULL, idchars)) e->error("unrecognized trait '%s', did you mean '%s'?", e->ident->toChars(), sub); else e->error("unrecognized trait '%s'", e->ident->toChars()); goto Lfalse; } return NULL; Ldimerror: e->error("wrong number of arguments %d", (int)dim); goto Lfalse; Lfalse: return new IntegerExp(e->loc, 0, Type::tbool); Ltrue: return new IntegerExp(e->loc, 1, Type::tbool); }
Symbol *VarDeclaration::toSymbol() { //printf("VarDeclaration::toSymbol(%s)\n", toChars()); //if (needThis()) *(char*)0=0; assert(!needThis()); if (!csym) { Symbol *s; TYPE *t; const char *id; if (isDataseg()) id = mangle(); else id = ident->toChars(); s = symbol_calloc(id); if (storage_class & (STCout | STCref)) { if (global.params.symdebug && storage_class & STCparameter) { t = type_alloc(TYnptr); // should be TYref, but problems in back end t->Tnext = type->toCtype(); t->Tnext->Tcount++; } else t = type_fake(TYnptr); } else if (storage_class & STClazy) t = type_fake(TYdelegate); // Tdelegate as C type else if (isParameter()) t = type->toCParamtype(); else t = type->toCtype(); t->Tcount++; if (isDataseg()) { if (isThreadlocal()) { /* Thread local storage */ TYPE *ts = t; ts->Tcount++; // make sure a different t is allocated type_setty(&t, t->Tty | mTYthread); ts->Tcount--; if (global.params.vtls) { char *p = loc.toChars(); fprintf(stdmsg, "%s: %s is thread local\n", p ? p : "", toChars()); if (p) mem.free(p); } } s->Sclass = SCextern; s->Sfl = FLextern; slist_add(s); } else { s->Sclass = SCauto; s->Sfl = FLauto; if (nestedrefs.dim) { /* Symbol is accessed by a nested function. Make sure * it is not put in a register, and that the optimizer * assumes it is modified across function calls and pointer * dereferences. */ //printf("\tnested ref, not register\n"); type_setcv(&t, t->Tty | mTYvolatile); } } if (ident == Id::va_argsave) /* __va_argsave is set outside of the realm of the optimizer, * so we tell the optimizer to leave it alone */ type_setcv(&t, t->Tty | mTYvolatile); mangle_t m = 0; switch (linkage) { case LINKwindows: m = mTYman_std; break; case LINKpascal: m = mTYman_pas; break; case LINKc: m = mTYman_c; break; case LINKd: m = mTYman_d; break; case LINKcpp: m = mTYman_cpp; break; default: printf("linkage = %d\n", linkage); assert(0); } type_setmangle(&t, m); s->Stype = t; csym = s; } return csym; }
QVariant ParameterFileModel::data(const QModelIndex& ind, int role) const { // mapper to convert parameter.type into QVariant::Type const VarTypeMap& mapper = VarTypeMap::instance(); int row = ind.row(); int col = ind.column(); QString key = _keys[row]; QString val; QVariant res; switch (role) { case Qt::EditRole: case Qt::DisplayRole: if ((row >= 0) && (row < _keys.size())) { switch (col) { case 0: // parameter name (without prefix) if (!_prefix.isEmpty()) key.remove(0, _prefix.length()); // remove dot after valid prefix if (key[0] == '.') key.remove(0, 1); return key; case 1: if (_parameterFile->isSet(_keys[row])) { val = _parameterFile->get(_keys[row]); } else if (_onlyParams) { val = getDefault(_keys[row]); } // handle parameter links if (val.startsWith('@')) { QString ref = val.mid(1); if(_parameterFile->isSet(ref)) { val = _parameterFile->get(ref); } else if(role == Qt::DisplayRole) { val = tr("[invalid reference to %1]").arg(ref); } } // handle QVariant type res = val; if (_useMetaInfo && isParameter(key)) { QString typestring = getType(key); QVariant::Type type = mapper[typestring]; Q_ASSERT(res.canConvert(type)); res.convert(type); } return res; case 2: if (role == Qt::DisplayRole) { return QVariant(); } return getValue(key + ".editorpriority").toUInt(); } } break; case Qt::ToolTipRole: if (_useMetaInfo) { QString ret = _metaInfos->getDocString(key, getClass(key)); return ret.isEmpty() ? QVariant() : ret; } break; case Qt::ForegroundRole: if (_onlyParams && !isSet(key)) { return QColor(Qt::lightGray); } break; case Qt::BackgroundRole: switch (getValue(key+".editorpriority").toInt()) { case 1: return QColor("#8f8"); case 2: return QColor("#ff8"); case 3: return QColor("#f80"); default: break; } break; case Qt::CheckStateRole: if (_useMetaInfo && col == 1 && isParameter(key) && getType(key) == "bool") { const bool& checked = isSet(key) ? QVariant(getValue(key)).toBool() : QVariant(getDefault(key)).toBool(); return checked ? Qt::Checked : Qt::Unchecked; } break; case Qt::StatusTipRole: if(col == 1) { if (isSet(key)) { QString ret = getValue(key); if(ret.startsWith('@')) { return tr("link to: %1").arg(ret.mid(1)); } } } break; case Qt::DecorationRole: if(col == 1) { if (isSet(key)) { QString ret = getValue(key); if(ret.startsWith('@')) { return QIcon(":/icons/symlink.png"); } } } break; } // role switch return QVariant(); }
void GUICtrlTemplate::InitAdditionalProperty_EDIT_BOX( AST_TXML_Compound *comp ) { if( isParameter( INT_PROP_NAME__TYPE ) ) { HKParameter& prop = getParameter( INT_PROP_NAME__TYPE ); if ( prop == HKParameter( QString( HKParameterTypeName_Long ) ) ) { AST_TXML_Attribute *_min_attr = 0, *_max_attr = 0; AST_TXML_Node *node; for( long j = 0; j < comp->getChildNumber(); j++ ) { node = comp->getChild( j ); if( node->getNodeType() != ASTT_TXML_Attribute ) continue; if( ((AST_TXML_Attribute*)node)->isAttribute( FBL_ATTR_min ) ) _min_attr = (AST_TXML_Attribute*)node; else if( ((AST_TXML_Attribute*)node)->isAttribute( FBL_ATTR_max ) ) _max_attr = (AST_TXML_Attribute*)node; } if( _min_attr ) { _min_attr->convert2Integer(); if( _min_attr->getValueType() == ASTVALT_TXML_Int ) { setParameter( INT_PROP_NAME__MIN, HKParameter(_min_attr->getIntValue()) ); } } if( _max_attr ) { _max_attr->convert2Integer(); if( _max_attr->getValueType() == ASTVALT_TXML_Int ) { setParameter( INT_PROP_NAME__MAX, HKParameter(_max_attr->getIntValue()) ); } } } else if ( prop == HKParameter( QString( HKParameterTypeName_Double ) ) ) { AST_TXML_Attribute *_min_attr = 0, *_max_attr = 0; AST_TXML_Node *node; for( long j = 0; j < comp->getChildNumber(); j++ ) { node = comp->getChild( j ); if( node->getNodeType() != ASTT_TXML_Attribute ) continue; if( ((AST_TXML_Attribute*)node)->isAttribute( FBL_ATTR_min ) ) _min_attr = (AST_TXML_Attribute*)node; else if( ((AST_TXML_Attribute*)node)->isAttribute( FBL_ATTR_max ) ) _max_attr = (AST_TXML_Attribute*)node; } if( _min_attr ) { _min_attr->convert2Integer(); if( _min_attr->getValueType() == ASTVALT_TXML_Real ) { setParameter( INT_PROP_NAME__MIN, HKParameter(_min_attr->getFloatValue()) ); } } if( _max_attr ) { _max_attr->convert2Integer(); if( _max_attr->getValueType() == ASTVALT_TXML_Real ) { setParameter( INT_PROP_NAME__MAX, HKParameter(_max_attr->getFloatValue()) ); } } } } }
Symbol *VarDeclaration::toSymbol() { //printf("VarDeclaration::toSymbol(%s)\n", toChars()); //if (needThis()) *(char*)0=0; assert(!needThis()); if (!csym) { Symbol *s; TYPE *t; const char *id; mangle_t m = 0; if (isDataseg()) id = mangle(); else id = ident->toChars(); s = symbol_calloc(id); if (storage_class & STCout) t = type_fake(TYnptr); else if (isParameter()) t = type->toCParamtype(); else t = type->toCtype(); t->Tcount++; if (isDataseg()) { s->Sclass = SCextern; s->Sfl = FLextern; slist_add(s); } else { s->Sclass = SCauto; s->Sfl = FLauto; if (nestedref) { /* Symbol is accessed by a nested function. Make sure * it is not put in a register, and that the optimizer * assumes it is modified across function calls and pointer * dereferences. */ //printf("\tnested ref, not register\n"); type_setcv(&t, t->Tty | mTYvolatile); } } if (storage_class & STCconst) { // Insert const modifiers tym_t tym = 0; if (storage_class & STCconst) tym |= mTYconst; type_setcv(&t, tym); } switch (linkage) { case LINKwindows: m = mTYman_std; break; case LINKpascal: m = mTYman_pas; break; case LINKc: m = mTYman_c; break; case LINKd: m = mTYman_d; break; case LINKcpp: m = mTYman_cpp; break; default: printf("linkage = %d\n", linkage); assert(0); } type_setmangle(&t, m); s->Stype = t; csym = s; } return csym; }
bool ParameterFileModel::setData( const QModelIndex& ind, const QVariant& value, int role) { if (!prefixValid()) return false; switch (role) { case Qt::EditRole: case Qt::DisplayRole: if ((ind.row() >= 0) && (ind.row() < _keys.size())) { switch (ind.column()) { case 0: if (_onlyParams) return false; if (value.canConvert(QVariant::String)) { QString oldName = _keys[ind.row()]; QString newName; // do not forget the prefix at the beginning of the name if (!_prefix.isEmpty()) newName = _prefix + "."; newName += value.toString(); if (oldName == newName) return true; // nothing to do if (_parameterFile->isSet(newName)) return false; // don't overwrite existing value // save value QString val = getValue(oldName); erase(oldName); setValue(newName, val); emit dataChanged(ind, ind); return true; } break; case 1: if (value.canConvert(QVariant::String)) { QString valueStr = value.toString(); QString keyStr = _keys[ind.row()]; if (valueStr == getValue(keyStr)) return true; // nothing to do setValue(keyStr, valueStr); if (_onlyParams && _metaInfos->isDynamic(getClass(keyStr))) { save(); _updateDynamics(); QTimer::singleShot(0, this, SLOT(_update())); emit dynamicUpdate(); } emit dataChanged(index(ind.row(), 0), ind); return true; } break; case 2: if (value.canConvert(QVariant::Int)) { // check if value is allowed int valueInt = value.toInt(); QString valueStr = QVariant(valueInt).toString(); if (valueInt < 0 || valueInt > 3) { return false; } if (valueInt == 0) { // 0 is default value -> no entry needed if (isSet(_keys[ind.row()] + ".editorpriority")) { // check if value exists to prevent exceptions erase(_keys[ind.row()] + ".editorpriority"); emit dataChanged(index(ind.row(), 0), ind); } return true; } if (valueStr == getValue(_keys[ind.row()] + ".editorpriority")) { return true; // nothing to do } setValue(_keys[ind.row()] + ".editorpriority", valueStr); emit dataChanged(index(ind.row(), 0), ind); return true; } break; } } break; case Qt::CheckStateRole: if (_useMetaInfo && ind.column()==1 && isParameter(_keys[ind.row()])) { Q_ASSERT(getType(_keys[ind.row()]) == "bool"); bool checked (value.toBool()); setValue (_keys[ind.row()], checked ? "true" : "false"); emit dataChanged(index(ind.row(),0),ind); if (_keys[ind.row()].contains("active") && checked == true){ reactivatePreviousPlugins(); } // additional check whether the changed Parameter is the ActiveInactive if (_keys[ind.row()].contains("active") && checked == false){ deactivate(); } } break; } return false; }