Ejemplo n.º 1
0
static const type* analyzerDeclIdentLiteral (analyzerCtx* ctx, ast* Node, type* base, bool module, storageTag storage) {
    bool fn = typeIsFunction(base);
    /*The storage tag defaults to:
        - extern if the symbol is a function,
        - static if a module level variable,
        - auto otherwise,
     But an explicit storage specifier overrides all.*/
    Node->storage =   storage ? storage
                    : fn ? storageExtern
                    : module ? storageStatic : storageAuto;

    if (Node->symbol) {
        if (Node->symbol->tag == symId && !Node->symbol->storage) {
            /*Assign the storage tag*/
            Node->symbol->storage = Node->storage;
        }

        if (   Node->symbol->tag == symId
            || Node->symbol->tag == symParam
            || Node->symbol->tag == symEnumConstant
            || Node->symbol->tag == symTypedef) {
            /*Assign the type*/
            if (!Node->symbol->dt)
                Node->symbol->dt = base;

            /*Don't bother checking types if param
              Any conflicts will be reported by the function itself*/
            else if (Node->symbol->tag == symParam)
                ;

            /*Not the first declaration of this symbol, check type matches*/
            else if (!typeIsEqual(Node->symbol->dt, base))
                errorConflictingDeclarations(ctx, Node, Node->symbol, base);

            /*Even if types match, not allowed to be redeclared if a variable*/
            else if (   Node->symbol->tag == symId && !fn
                     && Node->symbol->parent->tag != symStruct
                     && Node->symbol->parent->tag != symUnion
                     && Node->symbol->storage != storageExtern)
                errorRedeclared(ctx, Node, Node->symbol);

            reportSymbol(Node->symbol);
        }

    } else
        reportType(base);

    /*Take ownership of the base if unable to give it to a symbol*/
    if (!Node->symbol || Node->symbol->dt != base)
        Node->dt = base;

    return base;
}
Ejemplo n.º 2
0
/**** Global functions definitions.   ****/
TA_RetCode TA_Report( TA_UDBase *unifiedDatabase,
                      FILE *out,
                      TA_ReportFlag flags )
{
   TA_StringTable *table;
   TA_RetCode retCode;
   unsigned int i;

   unsigned int nbCategoryTotal;
   unsigned int nbSymbolTotal;

   nbCategoryTotal = 0;
   nbSymbolTotal   = 0;

   if( out == NULL )
      return TA_BAD_PARAM;

   /* Output an header */
   fprintf( out, "\nTA-LIB: Content of unified database\n" );

   /* Get all the category to iterate. */
   retCode = TA_CategoryTableAlloc( unifiedDatabase, &table );

   if( retCode == TA_SUCCESS )
   {
      for( i=0; i < table->size; i++ )
      {
         if( !flags || (flags & TA_REPORT_CATEGORY) )
            fprintf( out, "\nCategory [%s]\n", table->string[i] );

         if( !flags || (flags & TA_REPORT_SYMBOL) )
         {
            retCode = reportSymbol( unifiedDatabase, out, flags, table->string[i], &nbSymbolTotal );
            if( retCode != TA_SUCCESS )
            {
               TA_CategoryTableFree( table );
               return retCode;
            }
         }
      }

      nbCategoryTotal = table->size;

      TA_CategoryTableFree( table );
   }
   else
      return retCode;

   if( !flags || (flags & TA_REPORT_TOTAL) )
   {
      fprintf( out, "\n==============================================");
      fprintf( out, "\nTotal nb symbols   : %d", nbSymbolTotal );
      fprintf( out, "\nTotal nb categories: %d", nbCategoryTotal );
      fprintf( out, "\n==============================================");
   }

   /* Output a trailer. */
   fprintf( out, "\nTA-LIB: End of report\n" );

   return TA_SUCCESS;
}