LCOV - code coverage report
Current view: top level - src/interfaces/ecpg/preproc - c_keywords.c (source / functions) Coverage Total Hit
Test: PostgreSQL 20devel Lines: 100.0 % 11 11
Test Date: 2026-07-12 23:15:38 Functions: 100.0 % 1 1
Legend: Lines:     hit not hit
Branches: + taken - not taken # not executed
Branches: 100.0 % 8 8

             Branch data     Line data    Source code
       1                 :             : /*-------------------------------------------------------------------------
       2                 :             :  *
       3                 :             :  * c_keywords.c
       4                 :             :  *    lexical token lookup for reserved words in postgres embedded SQL
       5                 :             :  *
       6                 :             :  * src/interfaces/ecpg/preproc/c_keywords.c
       7                 :             :  *
       8                 :             :  *-------------------------------------------------------------------------
       9                 :             :  */
      10                 :             : #include "postgres_fe.h"
      11                 :             : 
      12                 :             : /* ScanKeywordList lookup data for C keywords */
      13                 :             : #include "c_kwlist_d.h"
      14                 :             : #include "preproc_extern.h"
      15                 :             : #include "preproc.h"
      16                 :             : 
      17                 :             : /* Token codes for C keywords */
      18                 :             : #define PG_KEYWORD(kwname, value) value,
      19                 :             : 
      20                 :             : static const uint16 ScanCKeywordTokens[] = {
      21                 :             : #include "c_kwlist.h"
      22                 :             : };
      23                 :             : 
      24                 :             : #undef PG_KEYWORD
      25                 :             : 
      26                 :             : 
      27                 :             : /*
      28                 :             :  * ScanCKeywordLookup - see if a given word is a keyword
      29                 :             :  *
      30                 :             :  * Returns the token value of the keyword, or -1 if no match.
      31                 :             :  *
      32                 :             :  * Do a hash search using plain strcmp() comparison.  This is much like
      33                 :             :  * ScanKeywordLookup(), except we want case-sensitive matching.
      34                 :             :  */
      35                 :             : int
      36                 :       10412 : ScanCKeywordLookup(const char *text)
      37                 :             : {
      38                 :             :     size_t      len;
      39                 :             :     int         h;
      40                 :             :     const char *kw;
      41                 :             : 
      42                 :             :     /*
      43                 :             :      * Reject immediately if too long to be any keyword.  This saves useless
      44                 :             :      * hashing work on long strings.
      45                 :             :      */
      46                 :       10412 :     len = strlen(text);
      47         [ +  + ]:       10412 :     if (len > ScanCKeywords.max_kw_len)
      48                 :        1445 :         return -1;
      49                 :             : 
      50                 :             :     /*
      51                 :             :      * Compute the hash function.  Since it's a perfect hash, we need only
      52                 :             :      * match to the specific keyword it identifies.
      53                 :             :      */
      54                 :        8967 :     h = ScanCKeywords_hash_func(text, len);
      55                 :             : 
      56                 :             :     /* An out-of-range result implies no match */
      57   [ +  +  +  + ]:        8967 :     if (h < 0 || h >= ScanCKeywords.num_keywords)
      58                 :        5071 :         return -1;
      59                 :             : 
      60                 :        3896 :     kw = GetScanKeyword(h, &ScanCKeywords);
      61                 :             : 
      62         [ +  + ]:        3896 :     if (strcmp(kw, text) == 0)
      63                 :         953 :         return ScanCKeywordTokens[h];
      64                 :             : 
      65                 :        2943 :     return -1;
      66                 :             : }
        

Generated by: LCOV version 2.0-1