AggregateDeclaration::AggregateDeclaration(Loc loc, Identifier *id) : ScopeDsymbol(id) { this->loc = loc; storage_class = 0; protection = Prot(PROTpublic); type = NULL; structsize = 0; // size of struct alignsize = 0; // size of struct for alignment purposes sizeok = SIZEOKnone; // size not determined yet deferred = NULL; isdeprecated = false; mutedeprecation = false; inv = NULL; aggNew = NULL; aggDelete = NULL; #if IN_DMD stag = NULL; sinit = NULL; #endif enclosing = NULL; vthis = NULL; ctor = NULL; defaultCtor = NULL; aliasthis = NULL; noDefaultCtor = false; dtor = NULL; getRTInfo = NULL; }
FuncDeclaration *buildArrayOp(Identifier *ident, BinExp *exp, Scope *sc) { Parameters *fparams = new Parameters(); Expression *loopbody = buildArrayLoop(exp, fparams); /* Construct the function body: * foreach (i; 0 .. p.length) for (size_t i = 0; i < p.length; i++) * loopbody; * return p; */ Parameter *p = (*fparams)[0]; // foreach (i; 0 .. p.length) Statement *s1 = new ForeachRangeStatement(Loc(), TOKforeach, new Parameter(0, NULL, Id::p, NULL), new IntegerExp(Loc(), 0, Type::tsize_t), new ArrayLengthExp(Loc(), new IdentifierExp(Loc(), p->ident)), new ExpStatement(Loc(), loopbody), Loc()); //printf("%s\n", s1->toChars()); Statement *s2 = new ReturnStatement(Loc(), new IdentifierExp(Loc(), p->ident)); //printf("s2: %s\n", s2->toChars()); Statement *fbody = new CompoundStatement(Loc(), s1, s2); // Built-in array ops should be @trusted, pure, nothrow and nogc StorageClass stc = STCtrusted | STCpure | STCnothrow | STCnogc; /* Construct the function */ TypeFunction *ftype = new TypeFunction(fparams, exp->e1->type, 0, LINKc, stc); //printf("fd: %s %s\n", ident->toChars(), ftype->toChars()); FuncDeclaration *fd = new FuncDeclaration(Loc(), Loc(), ident, STCundefined, ftype); fd->fbody = fbody; fd->protection = Prot(PROTpublic); fd->linkage = LINKc; fd->isArrayOp = 1; sc->_module->importedFrom->members->push(fd); sc = sc->push(); sc->parent = sc->_module->importedFrom; sc->stc = 0; sc->linkage = LINKc; fd->semantic(sc); fd->semantic2(sc); unsigned errors = global.startGagging(); fd->semantic3(sc); if (global.endGagging(errors)) { fd->type = Type::terror; fd->errors = true; fd->fbody = NULL; } sc->pop(); return fd; }
EnumDeclaration::EnumDeclaration(Loc loc, Identifier *id, Type *memtype) : ScopeDsymbol(id) { //printf("EnumDeclaration() %s\n", toChars()); this->loc = loc; type = new TypeEnum(this); this->memtype = memtype; maxval = NULL; minval = NULL; defaultval = NULL; sinit = NULL; isdeprecated = false; protection = Prot(PROTundefined); parent = NULL; added = false; inuse = 0; }
Scope::Scope() { // Create root scope //printf("Scope::Scope() %p\n", this); this->module = NULL; this->scopesym = NULL; this->sds = NULL; this->enclosing = NULL; this->parent = NULL; this->sw = NULL; this->tf = NULL; this->os = NULL; this->tinst = NULL; this->minst = NULL; this->sbreak = NULL; this->scontinue = NULL; this->fes = NULL; this->callsc = NULL; this->structalign = STRUCTALIGN_DEFAULT; this->func = NULL; this->slabel = NULL; this->linkage = LINKd; this->protection = Prot(PROTpublic); this->explicitProtection = 0; this->stc = 0; this->depmsg = NULL; this->inunion = 0; this->nofree = 0; this->noctor = 0; this->intypeof = 0; this->lastVar = NULL; this->callSuper = 0; this->fieldinit = NULL; this->fieldinit_dim = 0; this->flags = 0; this->lastdc = NULL; this->lastoffset = 0; this->docbuf = NULL; this->anchorCounts = NULL; this->prevAnchor = NULL; this->userAttribDecl = NULL; }
Scope::Scope() { // Create root scope //printf("Scope::Scope() %p\n", this); this->_module = NULL; this->scopesym = NULL; this->sds = NULL; this->enclosing = NULL; this->parent = NULL; this->sw = NULL; this->tf = NULL; this->os = NULL; this->tinst = NULL; this->minst = NULL; this->sbreak = NULL; this->scontinue = NULL; this->fes = NULL; this->callsc = NULL; this->aligndecl = NULL; this->func = NULL; this->slabel = NULL; this->linkage = LINKd; this->cppmangle = CPPMANGLEdefault; this->inlining = PINLINEdefault; this->protection = Prot(PROTpublic); this->explicitProtection = 0; this->stc = 0; this->depdecl = NULL; this->inunion = 0; this->nofree = 0; this->noctor = 0; this->intypeof = 0; this->lastVar = NULL; this->callSuper = 0; this->fieldinit = NULL; this->fieldinit_dim = 0; this->flags = 0; this->lastdc = NULL; this->anchorCounts = NULL; this->prevAnchor = NULL; this->userAttribDecl = NULL; }
Expression *EnumMember::getVarExp(Loc loc, Scope *sc) { semantic(sc); if (errors) return new ErrorExp(); if (!vd) { assert(value); vd = new VarDeclaration(loc, type, ident, new ExpInitializer(loc, value->copy())); vd->storage_class = STCmanifest; vd->semantic(sc); vd->protection = ed->isAnonymous() ? ed->protection : Prot(PROTpublic); vd->parent = ed->isAnonymous() ? ed->parent : ed; vd->userAttribDecl = ed->isAnonymous() ? ed->userAttribDecl : NULL; } checkAccess(loc, sc, NULL, vd); Expression *e = new VarExp(loc, vd); return e->semantic(sc); }
Prot Dsymbol::prot() { return Prot(PROTpublic); }
void Execution::OnBtnRunClick(wxCommandEvent& /*event*/) { ToggleControls(false); ProjectsArray* Projects = Manager::Get()->GetProjectManager()->GetProjects(); if ( !Projects->GetCount() ) { cbMessageBox(_("No active project(s) to process."),_T("Header Fixup")); ToggleControls(true); return; } // Generating list of files to process wxArrayString FilesToProcess; if ( m_Scope->GetSelection()==0 ) // project scope { cbProject* Project = Manager::Get()->GetProjectManager()->GetActiveProject(); AddFilesFromProject(FilesToProcess,Project); } else // workspace scope { ProjectsArray* Projects2 = Manager::Get()->GetProjectManager()->GetProjects(); for ( size_t i = 0; i < Projects2->GetCount(); ++i ) AddFilesFromProject(FilesToProcess,(*Projects2)[i]); } if ( FilesToProcess.IsEmpty() ) { cbMessageBox(_("No files to process."),_T("Header Fixup")); ToggleControls(true); return; } // Generating list of header groups to use wxArrayString Groups; for ( size_t i = 0; i < m_Sets->GetCount(); i++ ) { if ( m_Sets->IsChecked(i) ) { Groups.Add(m_Sets->GetString(i)); } } if ( Groups.IsEmpty() ) { cbMessageBox(_("Please select at least one header group."),_T("Header Fixup")); ToggleControls(true); return; } // Running the scan int HeadersAdded = 0; if ( m_FileType->GetSelection()==0 ) { Manager::Get()->GetLogManager()->DebugLog(F(_T("[HeaderFixup]: Processing header files..."))); m_Log.Add( _T("[header files]\n")); m_Processor = ProcessHeaderFiles; HeadersAdded += RunScan(FilesToProcess,Groups); } else if ( m_FileType->GetSelection()==1 ) { Manager::Get()->GetLogManager()->DebugLog(F(_T("[HeaderFixup]: Processing source files..."))); m_Log.Add(_T("[source files]\n")); m_Processor = ProcessSourceFiles; HeadersAdded += RunScan(FilesToProcess,Groups); } else { Manager::Get()->GetLogManager()->DebugLog(F(_T("[HeaderFixup]: Processing header files..."))); m_Log.Add( _T("[header files]\n")); m_Processor = ProcessHeaderFiles; HeadersAdded += RunScan(FilesToProcess,Groups); Manager::Get()->GetLogManager()->DebugLog(F(_T("[HeaderFixup]: Processing source files..."))); m_Log.Add( _T("\n[source files]\n")); m_Processor = ProcessSourceFiles; HeadersAdded += RunScan(FilesToProcess,Groups); } if ( HeadersAdded ) { wxString log; log.Printf(_("Added %d extra includes.\n"),HeadersAdded); if ( !m_Protocol->IsChecked() ) cbMessageBox(log); m_Log.Add( _T("\n--> ") + log); } else { if ( !m_Protocol->IsChecked() ) cbMessageBox(_("All files were OK. Nothing to be done."),_T("Header Fixup")); m_Log.Add( _("\n--> All files were OK. Nothing to be done.\n")); } if ( m_Protocol->IsChecked() ) { this->Show(false); Protocol Prot(NULL); Prot.SetProtocol(m_Log); Prot.ShowModal(); } SaveSettings(); EndModal(wxID_OK); }// OnBtnRunClick
void Nspace::semantic(Scope *sc) { if (semanticRun >= PASSsemantic) return; semanticRun = PASSsemantic; #if LOG printf("+Nspace::semantic('%s')\n", toChars()); #endif if (scope) { sc = scope; scope = NULL; } parent = sc->parent; if (members) { if (!symtab) symtab = new DsymbolTable(); // The namespace becomes 'imported' into the enclosing scope for (Scope *sce = sc; 1; sce = sce->enclosing) { ScopeDsymbol *sds = (ScopeDsymbol *)sce->scopesym; if (sds) { sds->importScope(this, Prot(PROTpublic)); break; } } assert(sc); sc = sc->push(this); sc->linkage = LINKcpp; // note that namespaces imply C++ linkage sc->parent = this; for (size_t i = 0; i < members->dim; i++) { Dsymbol *s = (*members)[i]; //printf("add %s to scope %s\n", s->toChars(), toChars()); s->addMember(sc, this); } for (size_t i = 0; i < members->dim; i++) { Dsymbol *s = (*members)[i]; s->setScope(sc); } for (size_t i = 0; i < members->dim; i++) { Dsymbol *s = (*members)[i]; s->importAll(sc); } for (size_t i = 0; i < members->dim; i++) { Dsymbol *s = (*members)[i]; #if LOG printf("\tmember '%s', kind = '%s'\n", s->toChars(), s->kind()); #endif s->semantic(sc); } sc->pop(); } #if LOG printf("-Nspace::semantic('%s')\n", toChars()); #endif }
void StructDeclaration::semantic(Scope *sc) { //printf("+StructDeclaration::semantic(this=%p, %s '%s', sizeok = %d)\n", this, parent->toChars(), toChars(), sizeok); //static int count; if (++count == 20) halt(); if (semanticRun >= PASSsemanticdone) return; unsigned dprogress_save = Module::dprogress; int errors = global.errors; Scope *scx = NULL; if (scope) { sc = scope; scx = scope; // save so we don't make redundant copies scope = NULL; } if (!parent) { assert(sc->parent && sc->func); parent = sc->parent; } assert(parent && !isAnonymous()); type = type->semantic(loc, sc); if (type->ty == Tstruct && ((TypeStruct *)type)->sym != this) { TemplateInstance *ti = ((TypeStruct *)type)->sym->isInstantiated(); if (ti && isError(ti)) ((TypeStruct *)type)->sym = this; } // Ungag errors when not speculative Ungag ungag = ungagSpeculative(); if (semanticRun == PASSinit) { protection = sc->protection; alignment = sc->structalign; storage_class |= sc->stc; if (storage_class & STCdeprecated) isdeprecated = true; if (storage_class & STCabstract) error("structs, unions cannot be abstract"); userAttribDecl = sc->userAttribDecl; } else if (symtab) { if (sizeok == SIZEOKdone || !scx) { semanticRun = PASSsemanticdone; return; } } semanticRun = PASSsemantic; if (!members) // if opaque declaration { semanticRun = PASSsemanticdone; return; } if (!symtab) symtab = new DsymbolTable(); if (sizeok == SIZEOKnone) // if not already done the addMember step { for (size_t i = 0; i < members->dim; i++) { Dsymbol *s = (*members)[i]; //printf("adding member '%s' to '%s'\n", s->toChars(), this->toChars()); s->addMember(sc, this, 1); } } sizeok = SIZEOKnone; Scope *sc2 = sc->push(this); sc2->stc &= STCsafe | STCtrusted | STCsystem; sc2->parent = this; if (isUnionDeclaration()) sc2->inunion = 1; sc2->protection = Prot(PROTpublic); sc2->explicitProtection = 0; sc2->structalign = STRUCTALIGN_DEFAULT; sc2->userAttribDecl = NULL; /* Set scope so if there are forward references, we still might be able to * resolve individual members like enums. */ for (size_t i = 0; i < members->dim; i++) { Dsymbol *s = (*members)[i]; //printf("struct: setScope %s %s\n", s->kind(), s->toChars()); s->setScope(sc2); } for (size_t i = 0; i < members->dim; i++) { Dsymbol *s = (*members)[i]; s->importAll(sc2); } for (size_t i = 0; i < members->dim; i++) { Dsymbol *s = (*members)[i]; /* If this is the last member, see if we can finish setting the size. * This could be much better - finish setting the size after the last * field was processed. The problem is the chicken-and-egg determination * of when that is. See Bugzilla 7426 for more info. */ if (i + 1 == members->dim) { if (sizeok == SIZEOKnone && s->isAliasDeclaration()) finalizeSize(sc2); } s->semantic(sc2); } finalizeSize(sc2); if (sizeok == SIZEOKfwd) { // semantic() failed because of forward references. // Unwind what we did, and defer it for later for (size_t i = 0; i < fields.dim; i++) { VarDeclaration *vd = fields[i]; vd->offset = 0; } fields.setDim(0); structsize = 0; alignsize = 0; scope = scx ? scx : sc->copy(); scope->setNoFree(); scope->module->addDeferredSemantic(this); Module::dprogress = dprogress_save; //printf("\tdeferring %s\n", toChars()); return; } Module::dprogress++; semanticRun = PASSsemanticdone; //printf("-StructDeclaration::semantic(this=%p, '%s')\n", this, toChars()); // Determine if struct is all zeros or not zeroInit = 1; for (size_t i = 0; i < fields.dim; i++) { VarDeclaration *vd = fields[i]; if (!vd->isDataseg()) { if (vd->init) { // Should examine init to see if it is really all 0's zeroInit = 0; break; } else { if (!vd->type->isZeroInit(loc)) { zeroInit = 0; break; } } } } dtor = buildDtor(this, sc2); postblit = buildPostBlit(this, sc2); cpctor = buildCpCtor(this, sc2); buildOpAssign(this, sc2); buildOpEquals(this, sc2); xeq = buildXopEquals(this, sc2); xcmp = buildXopCmp(this, sc2); xhash = buildXtoHash(this, sc2); /* Even if the struct is merely imported and its semantic3 is not run, * the TypeInfo object would be speculatively stored in each object * files. To set correct function pointer, run semantic3 for xeq and xcmp. */ //if ((xeq && xeq != xerreq || xcmp && xcmp != xerrcmp) && isImportedSym(this)) // Module::addDeferredSemantic3(this); /* Defer requesting semantic3 until TypeInfo generation is actually invoked. * See semanticTypeInfo(). */ inv = buildInv(this, sc2); sc2->pop(); /* Look for special member functions. */ ctor = searchCtor(); aggNew = (NewDeclaration *)search(Loc(), Id::classNew); aggDelete = (DeleteDeclaration *)search(Loc(), Id::classDelete); if (ctor) { Dsymbol *scall = search(Loc(), Id::call); if (scall) { unsigned xerrors = global.startGagging(); sc = sc->push(); sc->speculative = true; FuncDeclaration *fcall = resolveFuncCall(loc, sc, scall, NULL, NULL, NULL, 1); sc = sc->pop(); global.endGagging(xerrors); if (fcall && fcall->isStatic()) { error(fcall->loc, "static opCall is hidden by constructors and can never be called"); errorSupplemental(fcall->loc, "Please use a factory method instead, or replace all constructors with static opCall."); } } } TypeTuple *tup = toArgTypes(type); size_t dim = tup->arguments->dim; if (dim >= 1) { assert(dim <= 2); arg1type = (*tup->arguments)[0]->type; if (dim == 2) arg2type = (*tup->arguments)[1]->type; } if (sc->func) semantic2(sc); if (global.errors != errors) { // The type is no good. type = Type::terror; this->errors = true; if (deferred) deferred->errors = true; } if (deferred && !global.gag) { deferred->semantic2(sc); deferred->semantic3(sc); } #if 0 if (type->ty == Tstruct && ((TypeStruct *)type)->sym != this) { printf("this = %p %s\n", this, this->toChars()); printf("type = %d sym = %p\n", type->ty, ((TypeStruct *)type)->sym); } #endif assert(type->ty != Tstruct || ((TypeStruct *)type)->sym == this); }
void AggregateDeclaration::semantic3(Scope *sc) { //printf("AggregateDeclaration::semantic3(%s) type = %s, errors = %d\n", toChars(), type->toChars(), errors); if (!members) return; StructDeclaration *sd = isStructDeclaration(); if (!sc) // from runDeferredSemantic3 for TypeInfo generation { assert(sd); sd->semanticTypeInfoMembers(); return; } Scope *sc2 = sc->push(this); sc2->stc &= STCsafe | STCtrusted | STCsystem; sc2->parent = this; if (isUnionDeclaration()) sc2->inunion = 1; sc2->protection = Prot(PROTpublic); sc2->explicitProtection = 0; sc2->structalign = STRUCTALIGN_DEFAULT; sc2->userAttribDecl = NULL; for (size_t i = 0; i < members->dim; i++) { Dsymbol *s = (*members)[i]; s->semantic3(sc2); } sc2->pop(); // don't do it for unused deprecated types // or error types if (!getRTInfo && Type::rtinfo && (!isDeprecated() || global.params.useDeprecated) && (type && type->ty != Terror)) { // we do not want to report deprecated uses of this type during RTInfo // generation, so we disable reporting deprecation temporarily // WARNING: Muting messages during analysis of RTInfo might silently instantiate // templates that use (other) deprecated types. If these template instances // are used in other parts of the program later, they will be reused without // ever producing the deprecation message. The implementation here restricts // muting to the types that RTInfo is currently generated for. bool wasmuted = mutedeprecation; mutedeprecation = true; // Evaluate: RTinfo!type Objects *tiargs = new Objects(); tiargs->push(type); TemplateInstance *ti = new TemplateInstance(loc, Type::rtinfo, tiargs); ti->semantic(sc); ti->semantic2(sc); ti->semantic3(sc); Dsymbol *s = ti->toAlias(); Expression *e = new DsymbolExp(Loc(), s, 0); Scope *sc3 = ti->tempdecl->scope->startCTFE(); sc3->tinst = sc->tinst; e = e->semantic(sc3); sc3->endCTFE(); e = e->ctfeInterpret(); getRTInfo = e; mutedeprecation = wasmuted; } if (sd) sd->semanticTypeInfoMembers(); }