LCOV - code coverage report
Current view: top level - src/interfaces/ecpg/preproc - c_keywords.c (source / functions) Hit Total Coverage
Test: PostgreSQL 12beta2 Lines: 11 11 100.0 %
Date: 2019-06-19 16:07:09 Functions: 1 1 100.0 %
Legend: Lines: hit not hit

          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             : #include "preproc_extern.h"
      13             : #include "preproc.h"
      14             : 
      15             : /* ScanKeywordList lookup data for C keywords */
      16             : #include "c_kwlist_d.h"
      17             : 
      18             : /* Token codes for C keywords */
      19             : #define PG_KEYWORD(kwname, value) value,
      20             : 
      21             : static const uint16 ScanCKeywordTokens[] = {
      22             : #include "c_kwlist.h"
      23             : };
      24             : 
      25             : #undef PG_KEYWORD
      26             : 
      27             : 
      28             : /*
      29             :  * ScanCKeywordLookup - see if a given word is a keyword
      30             :  *
      31             :  * Returns the token value of the keyword, or -1 if no match.
      32             :  *
      33             :  * Do a hash search using plain strcmp() comparison.  This is much like
      34             :  * ScanKeywordLookup(), except we want case-sensitive matching.
      35             :  */
      36             : int
      37       19164 : ScanCKeywordLookup(const char *str)
      38             : {
      39             :     size_t      len;
      40             :     int         h;
      41             :     const char *kw;
      42             : 
      43             :     /*
      44             :      * Reject immediately if too long to be any keyword.  This saves useless
      45             :      * hashing work on long strings.
      46             :      */
      47       19164 :     len = strlen(str);
      48       19164 :     if (len > ScanCKeywords.max_kw_len)
      49        2646 :         return -1;
      50             : 
      51             :     /*
      52             :      * Compute the hash function.  Since it's a perfect hash, we need only
      53             :      * match to the specific keyword it identifies.
      54             :      */
      55       16518 :     h = ScanCKeywords_hash_func(str, len);
      56             : 
      57             :     /* An out-of-range result implies no match */
      58       16518 :     if (h < 0 || h >= ScanCKeywords.num_keywords)
      59       10008 :         return -1;
      60             : 
      61        6510 :     kw = GetScanKeyword(h, &ScanCKeywords);
      62             : 
      63        6510 :     if (strcmp(kw, str) == 0)
      64        1792 :         return ScanCKeywordTokens[h];
      65             : 
      66        4718 :     return -1;
      67             : }

Generated by: LCOV version 1.13