Main Page   Alphabetical List   Compound List   File List   Compound Members   File Members  

lh.c File Reference

#include "lclintMacros.nf"
#include "llbasic.h"
#include "osd.h"
#include "herald.h"
#include "lh.h"
#include "llmain.h"

Go to the source code of this file.

Compounds

struct  outFile

Defines

#define TABCH   '\1'
#define TABINCH   '\2'
#define TABOUTCH   '\3'
#define LHTMP_SUFFIX   ".lh_tmp"

Functions

cstring lhFunction (lclTypeSpecNode lclTypeSpec, declaratorNode declarator)
void lhForwardStruct (ltoken t)
void lhForwardUnion (ltoken t)
cstring lhType (typeNode t)
cstring lhVarDecl (lclTypeSpecNode lclTypeSpec, initDeclNodeList initDecls, qualifierKind qualifier)
void lhCleanup (void)
void lhIncludeBool (void)
void lhInit (tsource * f)
void lhOutLine ( cstring s)
void lhExternals (interfaceNodeList x)


Define Documentation

#define LHTMP_SUFFIX   ".lh_tmp"
 

Definition at line 59 of file lh.c.

#define TABCH   '\1'
 

Definition at line 50 of file lh.c.

#define TABINCH   '\2'
 

Definition at line 53 of file lh.c.

#define TABOUTCH   '\3'
 

Definition at line 56 of file lh.c.


Function Documentation

void lhCleanup ( void )
 

Definition at line 291 of file lh.c.

00293 {
00294   if (!genLh)
00295     {
00296       return;
00297     }
00298   else
00299     {
00300       FILE *f;
00301       int c, col = 0, tabcol = 0;
00302       char *fullname;
00303 
00304       
00305       fullname = mstring_create 
00306         (size_toInt (strlen (LhFile.name) + strlen (LHTMP_SUFFIX)));
00307 
00308       f = out_open (LhFile.name, LH_SUFFIX);
00309       llassert (LhFile.f != NULL);
00310 
00311       strcpy (fullname, LhFile.name);
00312       strcat (fullname, LHTMP_SUFFIX);
00313 
00314       if (f == NULL)
00315         {
00316           lldiagmsg (message ("Cannot open lh file for output: %s", 
00317                               cstring_fromChars (fullname)));
00318         }
00319       else
00320         {
00321           fprintf (f, "/* Output from %s */\n", LCL_PARSE_VERSION);
00322 
00323           rewind (LhFile.f);
00324 
00325           while (EOF != (c = getc (LhFile.f)))
00326             {
00327               switch (c)
00328                 {
00329                 case TABCH:
00330                   if (col == 0)
00331                     {
00332                       if (tabcol > 0)
00333                         fprintf (f, "%*s", tabcol, "");
00334                     }
00335                   else
00336                     {
00337                       check (fputc (' ', f) == (int) ' ');
00338                     }
00339                   /*@switchbreak@*/ break;
00340                   
00341                 case TABINCH:
00342                   tabcol += 4;
00343                   /*@switchbreak@*/ break;
00344                   
00345                 case TABOUTCH:
00346                   tabcol -= 4;
00347                   /*@switchbreak@*/ break;
00348                   
00349                 case '\n':
00350                   col = 0;
00351                   check (fputc (c, f) == (int) c);
00352                   /*@switchbreak@*/ break;
00353                   
00354                 default:
00355                   col++;
00356                   check (fputc (c, f) == (int) c);
00357                   /*@switchbreak@*/ break;
00358                 }
00359             }
00360 
00361           check (fclose (f) == 0);
00362           check (fclose (LhFile.f) == 0);
00363 
00364           (void) osd_unlink (fullname);
00365           LhFile.f = NULL;
00366         }
00367       
00368       sfree (fullname);
00369     }
00370 }

void lhExternals ( interfaceNodeList x )
 

Definition at line 448 of file lh.c.

00449 {
00450   if (genLh)
00451     {
00452       llassert (LhFile.f != NULL);
00453 
00454       /*
00455       ** Need to make sure all standard library includes come first.
00456       */
00457 
00458       interfaceNodeList_elements (x, el)
00459         {
00460           if (el->kind == INF_IMPORTS)
00461             {
00462               importNodeList imps = el->content.imports;
00463 
00464               importNodeList_elements (imps, il)
00465                 {
00466                   if (il->kind == IMPBRACKET)
00467                     {
00468                       lhOutLine (message ("# include <%s.h>", 
00469                                           ltoken_getRawString (il->val)));
00470                     }
00471                 } end_importNodeList_elements ;
00472             }
00473         } end_interfaceNodeList_elements;
00474 
00475       lhOutLine (cstring_makeLiteral ("# include \"bool.h\""));
00476       
00477       interfaceNodeList_elements (x, el)
00478         {
00479           if (el->kind == INF_IMPORTS)
00480             {
00481               importNodeList imps = el->content.imports;
00482 
00483               importNodeList_elements (imps, il)
00484                 {
00485                   if (il->kind != IMPBRACKET)
00486                     {
00487                       lhOutLine (message ("# include \"%s.h\"", 
00488                                           ltoken_getRawString (il->val)));
00489                     }
00490                 } end_importNodeList_elements ;
00491             }
00492         } end_interfaceNodeList_elements;
00493 
00494       lhOutLine (cstring_undefined);
00495     }
00496 }

void lhForwardStruct ( ltoken t )
 

Definition at line 176 of file lh.c.

Referenced by makeForwardstrOrUnionNode().

00177 {
00178   if (!genLh)
00179     return;
00180 
00181   lhOutLine (message ("struct %s;", ltoken_unparse (t)));
00182 }

void lhForwardUnion ( ltoken t )
 

Definition at line 186 of file lh.c.

Referenced by makeForwardstrOrUnionNode().

00187 {
00188   if (!genLh)
00189     return;
00190 
00191   lhOutLine (message ("union %s;", ltoken_unparse (t)));
00192 }

cstring lhFunction ( lclTypeSpecNode lclTypeSpec,
declaratorNode declarator )
 

Definition at line 103 of file lh.c.

00104 {
00105   cstring s;
00106 
00107   if (!genLh)
00108     return cstring_undefined;
00109   
00110   s = message ("extern %q\1%q;", lhTypeSpecNode (lclTypeSpec),
00111                lhDeclaratorNode (declarator));
00112   
00113   return s;
00114 }

void lhIncludeBool ( void )
 

Definition at line 374 of file lh.c.

Referenced by makeTypeSpecifier().

00375 {
00376   needIncludeBool = TRUE;
00377 }

void lhInit ( tsource * f )
 

Definition at line 404 of file lh.c.

00405 {
00406   static bool lherror = FALSE;
00407   
00408   genLh = context_msgLh ();
00409   needIncludeBool = FALSE;
00410 
00411   if (!genLh)
00412     {
00413       return;
00414     }
00415   
00416   LhFile.name = LSLRootName (tsource_fileName (f));
00417   LhFile.f = out_open (LhFile.name, LHTMP_SUFFIX);
00418 
00419   if (LhFile.f == NULL)
00420     {
00421       genLh = FALSE;
00422       if (!lherror)
00423         {
00424           lclplainerror (message ("Cannot write .lh file: %s.lh", 
00425                                   cstring_fromChars (LhFile.name)));
00426           lherror = TRUE;
00427         }
00428     } 
00429 }

void lhOutLine ( cstring s )
 

Definition at line 431 of file lh.c.

Referenced by interfaceNode_makeFcn(), interfaceNode_makeType(), interfaceNode_makeVar(), lhExternals(), lhForwardStruct(), lhForwardUnion(), and makeInterfaceNodeImports().

00432 {
00433   if (genLh)
00434     {
00435       llassert (LhFile.f != NULL);
00436 
00437       if (cstring_length (s) > 0) 
00438         {
00439           check (fputs (cstring_toCharsSafe (s), LhFile.f) != EOF); 
00440         }
00441 
00442       check (fputc ('\n', LhFile.f) == (int) '\n'); 
00443     }
00444 
00445   cstring_free (s);
00446 }

cstring lhType ( typeNode t )
 

Definition at line 195 of file lh.c.

00196 {
00197   if (!genLh)
00198     return cstring_undefined;
00199 
00200   if (t->kind == TK_EXPOSED)
00201     {
00202       exposedNode n = t->content.exposed;
00203 
00204       if (n != (exposedNode) 0)
00205         {
00206           if (declaratorInvNodeList_size (n->decls) == 0)
00207             {
00208               /* 
00209               ** Forward struct or union declaration
00210               */
00211 
00212               return (cstring_appendChar (lhTypeSpecNode (n->type), ';'));
00213             }
00214           else
00215             {
00216               cstring s = cstring_undefined;
00217 
00218               declaratorInvNodeList_elements (n->decls, d)
00219                 {
00220                   cstring name = declaratorNode_unparse (d->declarator);
00221                   cstring pname = declaratorNode_unparseCode (d->declarator); 
00222                   
00223                   s = message ("%q\n# ifndef EXPOSED_TYPE_%q\ntypedef %q %q;\n# endif\n", 
00224                                s, pname, lhTypeSpecNode (n->type), name);
00225                 } end_declaratorInvNodeList_elements;
00226               
00227               return s;
00228             }
00229         }
00230     }
00231 
00232   return cstring_undefined;
00233 }

cstring lhVarDecl ( lclTypeSpecNode lclTypeSpec,
initDeclNodeList initDecls,
qualifierKind qualifier )
 

Definition at line 247 of file lh.c.

00249 {
00250   bool first = TRUE;
00251   cstring s;
00252 
00253   if (!genLh)
00254     return cstring_undefined;
00255 
00256   s = cstring_makeLiteral ("extern");
00257 
00258   switch (qualifier)
00259     {
00260     case QLF_NONE:
00261       break;
00262     case QLF_CONST:
00263       s = message ("%q const", s);
00264       break;
00265     case QLF_VOLATILE:
00266       s = message ("%q volatile", s);
00267       break;
00268     default:                    /* ignore it */
00269       break;
00270     }
00271   
00272   s = message ("%q %q\1", s, lhTypeSpecNode (lclTypeSpec));
00273 
00274   initDeclNodeList_elements (initDecls, i)
00275   {
00276     if (first)
00277       {
00278         s = message ("%q %q", s, declaratorNode_unparse (i->declarator));
00279         first = FALSE;
00280       }
00281     else
00282       {
00283         s = message ("%q, %q", s, declaratorNode_unparse (i->declarator));
00284       }
00285   } end_initDeclNodeList_elements;
00286   
00287   return (message ("%q;", s));
00288 }


Generated at Fri Nov 3 18:58:00 2000 for LCLint by doxygen1.2.3 written by Dimitri van Heesch, © 1997-2000