LCOV - code coverage report
Current view: top level - soltools/cpp - _nlist.c (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 37 37 100.0 %
Date: 2015-06-13 12:38:46 Functions: 2 2 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #include <stdio.h>
      21             : #include <stdlib.h>
      22             : #include <string.h>
      23             : #include "cpp.h"
      24             : 
      25             : extern int Cplusplus;
      26             : Nlist *kwdefined;
      27             : char wd[128];
      28             : 
      29             : /*
      30             :     ER: Tabelle extra gross gemacht, da es anscheinend ein Problem mit der
      31             :     der Verkettung gibt, irgendwann irgendwo wird mal ein nlist->next
      32             :     ueberschrieben, was in eineme SIGSEGV resultiert.
      33             :     Den GDB mit watchpoint hab ich aber nach 2 Tagen abgebrochen..
      34             :     so loeppt's jedenfalls erstmal..
      35             :  */
      36             : #define NLSIZE 15000
      37             : 
      38             : static Nlist *nlist[NLSIZE];
      39             : 
      40             : struct kwtab
      41             : {
      42             :     char *kw;
      43             :     int val;
      44             :     int flag;
      45             : }   kwtab[] =
      46             : 
      47             : {
      48             :         {"if", KIF, ISKW},
      49             :         {"ifdef", KIFDEF, ISKW},
      50             :         {"ifndef", KIFNDEF, ISKW},
      51             :         {"elif", KELIF, ISKW},
      52             :         {"else", KELSE, ISKW},
      53             :         {"endif", KENDIF, ISKW},
      54             :         {"include", KINCLUDE, ISKW},
      55             :         {"include_next", KINCLUDENEXT, ISKW},
      56             :         {"import", KIMPORT, ISKW},
      57             :         {"define", KDEFINE, ISKW},
      58             :         {"undef", KUNDEF, ISKW},
      59             :         {"line", KLINE, ISKW},
      60             :         {"error", KERROR, ISKW},
      61             :         {"pragma", KPRAGMA, ISKW},
      62             :         {"ident", KIDENT, ISKW},
      63             :         {"eval", KEVAL, ISKW},
      64             :         {"defined", KDEFINED, ISDEFINED + ISUNCHANGE},
      65             :         {"machine", KMACHINE, ISDEFINED + ISUNCHANGE},
      66             :         {"__LINE__", KLINENO, ISMAC + ISUNCHANGE},
      67             :         {"__FILE__", KFILE, ISMAC + ISUNCHANGE},
      68             :         {"__DATE__", KDATE, ISMAC + ISUNCHANGE},
      69             :         {"__TIME__", KTIME, ISMAC + ISUNCHANGE},
      70             :         {"__STDC__", KSTDC, ISUNCHANGE},
      71             :         {NULL, 0, 0}
      72             : };
      73             : 
      74             : unsigned long namebit[077 + 1];
      75             : 
      76             : void
      77          53 :     setup_kwtab(void)
      78             : {
      79             :     struct kwtab *kp;
      80             :     Nlist *np;
      81             :     Token t;
      82             :     static Token deftoken[1] = {{NAME, 0, 0, 7, (uchar *) "defined", 0}};
      83             :     static Tokenrow deftr = {deftoken, deftoken, deftoken + 1, 1};
      84             : 
      85        1272 :     for (kp = kwtab; kp->kw; kp++)
      86             :     {
      87        1219 :         t.t = (uchar *) kp->kw;
      88        1219 :         t.len = strlen(kp->kw);
      89        1219 :         np = lookup(&t, 1);
      90        1219 :         np->flag = (char) kp->flag;
      91        1219 :         np->val = (char) kp->val;
      92        1219 :         if (np->val == KDEFINED)
      93             :         {
      94          53 :             kwdefined = np;
      95          53 :             np->val = NAME;
      96          53 :             np->vp = &deftr;
      97          53 :             np->ap = 0;
      98             :         }
      99             :     }
     100          53 : }
     101             : 
     102             : Nlist *
     103      227035 :     lookup(Token * tp, int install)
     104             : {
     105             :     unsigned int h;
     106             :     Nlist *np;
     107             :     uchar *cp, *cpe;
     108             : 
     109      227035 :     h = 0;
     110     5214168 :     for (cp = tp->t, cpe = cp + tp->len; cp < cpe;)
     111     4760098 :         h += *cp++;
     112      227035 :     h %= NLSIZE;
     113      227035 :     np = nlist[h];
     114      466842 :     while (np)
     115             :     {
     116       73040 :         if (*tp->t == *np->name && tp->len == (unsigned int)np->len
     117       60494 :             && strncmp((char *)tp->t, (char *)np->name, tp->len) == 0)
     118       60268 :             return np;
     119       12772 :         np = np->next;
     120             :     }
     121      166767 :     if (install)
     122             :     {
     123        7936 :         np = new(Nlist);
     124        7936 :         np->vp = NULL;
     125        7936 :         np->ap = NULL;
     126        7936 :         np->flag = 0;
     127        7936 :         np->val = 0;
     128        7936 :         np->len = tp->len;
     129        7936 :         np->name = newstring(tp->t, tp->len, 0);
     130        7936 :         np->next = nlist[h];
     131        7936 :         nlist[h] = np;
     132        7936 :         quickset(tp->t[0], tp->len > 1 ? tp->t[1] : 0);
     133        7936 :         return np;
     134             :     }
     135      158831 :     return NULL;
     136             : }
     137             : 
     138             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11