[cfe-dev] extern "C" support

Bjørn Roald bjorn at 4roald.org
Thu Jan 3 13:10:00 PST 2008


Mike Stump wrote:
> On Dec 22, 2007, at 5:28 PM, Chris Lattner wrote:
>> Please attach patches as attachments, not inline.  If you're using 
>> 'mail', just name the file "whatever.patch" and this will happen.  
>> Until this happens, I can't properly review the patch as it's all 
>> wrapped and nastified :(
>
> Odd, you must be using an old mail viewer...  In modern viewers, it 
> should come out just fine.  I pretested cutting and pasting and 
> ensured there were no problems with it.  Oh well...  What mail viewer 
> do you use?

I think the line-breaks may be caused by oter tools than the mail 
viewer.  At least the source my viewer received had additional 
linebreaks in it.

Nevertheless, the new patch you provided as attachment was ok as far as 
line-breaks.  I did have other problems using it with my diff/patch 
tools, but I managed to apply it with some manual hacking.  Problems may 
have been cased  by  us not  being in sync with svn revisions.  I am not 
that hot on svn, but svn-diff and friends may be a better choice in .  I 
attached the output of running

 svn diff > cxx-extern-linkage-spec.patch

in my tools/clang directory after I applied Mike's patches the best I could.

It seems Mike are done with most of what I set out to do :-).   I 
reviewed  the patch for the sake of learning, and applied it to my 
source.  It now work fine with my test code for  C++ extern keword.  
Extern template instanciation stuff is of scale and no tests is written 
for that.

I also attach my test source which run nicely with Mike's patch  :-)  
Good work Mike.

>> +/// LinkageSpecDecl - This represents a linkage specification.
>
>> +class LinkageSpecDecl : public Decl {
>>
>> Please give an example of what a linkage spec is in the header.  At 
>> some point, we probably want to make a DeclCXX.h file, but deferring 
>> this for now is fine.
>>
>> +private:
>> +  /// Language - The language for this linkage specification.
>> +  Language language;
>> +  bool inside_braces;
>> +  Decl *D;
>>
>> inside_braces is good for "remembering" the original source,
>
> I did that merely because we're calling them ASTs and because we form 
> ParenExprs.  If we didn't want ASTs, we could get rid of ParenExprs?
>> but unless there is a client,
>
> -ast-print uses that information to print the ast. Absent that 
> information we can't faithfully reproduce the syntax tree.  Do we care 
> that the printed ast is wrong?  Do we care if the ast isn't actually 
> an ast?
>
Does this support nested linkage specifiers as well?  There is a test 
case in my test file.

Should we not let support for linkage be a backend issue (e.g. llvm 
CodeGen), not frontend, as it is now, the AST is unusable for backends 
supporting linking to other languages.

 This would mean a change of Sema::ActOnLinkageSpec to support more 
lang_xxx enums and/or  pass the language string to the AST consumer.  
Something like:

Sema::DeclTy* Sema::ActOnLinkageSpec(SourceLocation Loc,
                     const char *Lang,
                     bool inside_brace,
                     DeclTy *D) {
  LinkageSpecDecl::Language language;
  Decl *dcl = static_cast<Decl *>(D);
  if (strcmp (Lang, "\"C\"") == 0)
    language = LinkageSpecDecl::lang_c;
  else if (strcmp (Lang, "\"C++\"") == 0)
    language = LinkageSpecDecl::lang_cxx;
  // could include enum support for other typical, but not required 
languages also
  else
    language = LinkageSpecDecl::lang_other;
  return new LinkageSpecDecl(Loc, language, inside_brace, dcl);
}

And let the backend codegen emit diagnostics, something similar to 
pseudocode:

    switch ( laguage )
    {
       case lang::lang_cxx:
         DoCXXLinkageCodeGen(...);
         break; 
      case lang::lang_c:
         DoCLinkageCodeGen(...);
         break; 
      case lang::lang_other:
         if ( (strcmp (language_str, "\"FORTRAN\"") == 0) &&
              (strcmp (language_str, "\"Fortran\"") == 0) )
            DoFortranLinkageCodeGen(...);
         else if (strcmp (language_str, "\"Ada\"") == 0)
            DoAdaLinkageCodeGen(...);
         Diag(Loc, diag::err_bad_language);
         break; 
     }
-------------

any thoughts ?


-- 
Bjørn
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: cxx-extern-linkage-spec.patch
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20080103/00c963ed/attachment.ksh>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: cxx-extern.cpp
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20080103/00c963ed/attachment-0001.ksh>


More information about the cfe-dev mailing list