[cfe-dev] Suggestion for Scope class
Argiris Kirtzidis
akyrtzi at gmail.com
Fri May 9 18:25:22 PDT 2008
Hi,
The Parser is passing the current scope to many of Sema's methods,
while, at the same time, Sema is managing the current decl context state
through the CurFunctionDecl, CurMethodDecl, and CurContext variables.
I suggest adding a decl context member to the Scope class like this:
+ /// ParentDecl - The declaration that this scope is created for.
+ /// It is up to the current Action implementation to implement the
semantics.
+ Action::DeclTy *ParentDecl;
[...]
+ /// getParentDecl - Return the decl that this scope is created for.
+ /// It is for use by the Action implementation.
+ ///
+ Action::DeclTy *getParentDecl() const { return ParentDecl; }
+
+ /// setParentDecl - Set the decl that this scope is created for.
+ /// It is for use by the Action implementation.
+ ///
+ void setParentDecl(Action::DeclTy *D) { ParentDecl = D; }
That way the code gets simplified a bit in a few places:
-CurFunctionDecl, CurMethodDecl, and CurContext will be removed, they
will be retrieved from the scope passed by the parser
-Calls to IdentifierResolver::isDeclInScope will pass only a scope, not
a scope and a decl context
-Sema::LookupDecl will actually take into account the scope passed to
it, and not assume doing a name lookup from the current decl context
-The code in Sema::ImplicitlyDefineFunction will change from:
> // Insert this function into translation-unit scope.
>
> DeclContext *PrevDC = CurContext;
> CurContext = Context.getTranslationUnitDecl();
>
> FunctionDecl *FD =
> dyn_cast<FunctionDecl>(static_cast<Decl*>(ActOnDeclarator(TUScope,
> D, 0)));
> FD->setImplicit();
>
> CurContext = PrevDC;
to
> // Insert this function into translation-unit scope.
>
> FunctionDecl *FD =
> dyn_cast<FunctionDecl>(static_cast<Decl*>(ActOnDeclarator(TUScope,
> D, 0)));
> FD->setImplicit();
Any thoughts ?
-Argiris
More information about the cfe-dev
mailing list