📄 key_list.cpp
字号:
ACE_OS::printf (" }\n %s\n}\n", option[OPTIMIZE] ? "" : "}\n return 0;");
}
// Prints out a table of keyword lengths, for use with the comparison
// code in generated function ``in_word_set.''
void
Key_List::output_keylength_table (void)
{
const int max_column = 15;
int slot = 0;
int column = 0;
const char *indent = option[GLOBAL] ? "" : " ";
List_Node *temp;
if (!option[DUP] && !option[SWITCH])
{
ACE_OS::printf ("\n%sstatic %sunsigned %s lengthtable[] =\n%s%s{\n ",
indent,
option[CONSTANT] ? "const " : "",
max_key_len <= ((int) UCHAR_MAX) ? "char" : (max_key_len <= ((int) USHRT_MAX) ? "short" : "long"),
indent,
indent);
for (temp = head; temp; temp = temp->next, slot++)
{
if (slot < temp->hash_value)
for ( ; slot < temp->hash_value; slot++)
ACE_OS::printf ("%3d,%s", 0, ++column % (max_column - 1) ? "" : "\n ");
ACE_OS::printf ("%3d,%s", temp->length, ++column % (max_column - 1 ) ? "" : "\n ");
}
ACE_OS::printf ("\n%s%s};\n",
indent,
indent);
}
}
// Prints out the array containing the key words for the Gen_Perf hash
// function.
void
Key_List::output_keyword_table (void)
{
const char *l_brace = *head->rest ? "{" : "";
const char *r_brace = *head->rest ? "}," : "";
const char *indent = option[GLOBAL] ? "" : " ";
int slot = 0;
List_Node *temp;
int pointer_and_type_enabled = option[POINTER] && option[TYPE];
ACE_OS::printf ("%sstatic %s%swordlist[] =\n%s%s{\n",
indent,
option[CONSTANT] || pointer_and_type_enabled == 0 ? "const " : "",
struct_tag,
indent,
indent);
// Skip over leading blank entries if there are no duplicates.
if (0 < head->hash_value)
ACE_OS::printf (" ");
int column;
for (column = 1; slot < head->hash_value; column++)
{
ACE_OS::printf ("%s\"\",%s%s%s",
l_brace,
option.fill_default (),
r_brace,
column % 9 ? "" : "\n ");
slot++;
}
if (0 < head->hash_value && column % 10)
ACE_OS::printf ("\n");
// Generate an array of reserved words at appropriate locations.
for (temp = head ; temp; temp = temp->next, slot++)
{
temp->slot = slot;
if (!option[SWITCH] && (total_duplicates == 0 || !option[DUP]) && slot < temp->hash_value)
{
int column;
ACE_OS::printf (" ");
for (column = 1; slot < temp->hash_value; slot++, column++)
ACE_OS::printf ("%s\"\",%s%s%s",
l_brace,
option.fill_default (),
r_brace,
column % 9 ? "" : "\n ");
if (column % 10)
ACE_OS::printf ("\n");
else
{
ACE_OS::printf ("%s\"%s\", %s%s", l_brace, temp->key, temp->rest, r_brace);
if (option[DEBUGGING])
ACE_OS::printf (" /* hash value = %d, slot = %d */",
temp->hash_value,
temp->slot);
putchar ('\n');
continue;
}
}
ACE_OS::printf (" %s\"%s\", %s%s", l_brace, temp->key, temp->rest, r_brace);
if (option[DEBUGGING])
ACE_OS::printf (" /* hash value = %d, slot = %d */",
temp->hash_value,
temp->slot);
putchar ('\n');
// Deal with links specially.
if (temp->link)
for (List_Node *links = temp->link; links; links = links->link)
{
links->slot = ++slot;
ACE_OS::printf (" %s\"%s\", %s%s", l_brace, links->key, links->rest, r_brace);
if (option[DEBUGGING])
ACE_OS::printf (" /* hash value = %d, slot = %d */",
links->hash_value,
links->slot);
putchar ('\n');
}
}
ACE_OS::printf ("%s%s};\n\n", indent, indent);
}
// Generates C code for the binary search algorithm that returns
// the proper encoding for each key word
int
Key_List::output_binary_search_function (void)
{
ACE_OS::printf ("%s\n", include_src);
// Get prototype for strncmp() and strcmp().
if (!option[SKIPSTRINGH])
ACE_OS::printf ("#include <string.h>\n");
// Output type declaration now, reference it later on....
if (option[TYPE] && !option[NOTYPE])
ACE_OS::printf ("%s;\n",
array_type_);
output_min_max ();
if (option[STRCASECMP])
output_strcasecmp ();
// Class definition if -M is *not* enabled.
if (option[CPLUSPLUS] && !option[SKIPCLASS])
ACE_OS::printf ("class %s {\npublic:\n"
" static %s%s%s (const char *str);\n};\n\n",
option.class_name (),
option[CONSTANT] ? "const " : "",
return_type,
option.function_name ());
// Use the inline keyword to remove function overhead.
if (option[INLINE])
ACE_OS::printf ("inline\n");
ACE_OS::printf ("%s%s\n", option[CONSTANT] ? "const " : "", return_type);
if (option[CPLUSPLUS])
ACE_OS::printf ("%s::", option.class_name ());
ACE_OS::printf (option[ANSI]
? "%s (const char *str)\n{\n"
: "%s (str)\n char *str;\n{\n",
option.function_name ());
// Use the switch in place of lookup table.
if (option[SWITCH])
output_switch ();
// Use the lookup table, in place of switch.
else
{
if (!option[GLOBAL])
{
if (option[LENTABLE])
output_keylength_table ();
output_keyword_table ();
}
}
// Logic to handle the Binary Search.
ACE_OS::printf ("int first = 0, last = 0, middle;\n");
ACE_OS::printf ("%s*base;\n",struct_tag);
ACE_OS::printf ("\nlast = %d;\n",total_keys - 1);
ACE_OS::printf ("while (last >= first)\n");
ACE_OS::printf ("\t{\n");
ACE_OS::printf ("\t middle = (last + first) / 2;\n");
ACE_OS::printf ("\t if (strcmp (wordlist[middle].opname_, str) == 0)\n break;\n");
ACE_OS::printf ("\t if (strcmp (wordlist[middle].opname_, str) < 0)\n first = middle + 1;\n");
ACE_OS::printf ("\t else last = middle - 1;\n");
ACE_OS::printf ("\t}\n");
ACE_OS::printf ("if (last < first)\n return 0;\n");
ACE_OS::printf ("else\n return (&wordlist[middle]);\n}\n");
if (additional_code)
{
for (;;)
{
int c = getchar ();
if (c == EOF)
break;
else
putchar (c);
}
}
fflush(stdout);
return 0;
}
// Generates C code for the linear search algorithm that returns
// the proper encoding for each key word
int
Key_List::output_linear_search_function (void)
{
ACE_OS::printf ("%s\n", include_src);
// Get prototype for strncmp() and strcmp().
if (!option[SKIPSTRINGH])
ACE_OS::printf ("#include <string.h>\n");
// Output type declaration now, reference it later on....
if (option[TYPE] && !option[NOTYPE])
ACE_OS::printf ("%s;\n",
array_type_);
output_min_max ();
if (option[STRCASECMP])
output_strcasecmp ();
// Class definition if -M is *not* enabled.
if (option[CPLUSPLUS] && !option[SKIPCLASS])
ACE_OS::printf ("class %s {\npublic:\n"
" static %s%s%s (const char *str);\n};\n\n",
option.class_name (),
option[CONSTANT] ? "const " : "",
return_type,
option.function_name ());
// Use the inline keyword to remove function overhead.
if (option[INLINE])
ACE_OS::printf ("inline\n");
ACE_OS::printf ("%s%s\n",
option[CONSTANT] ? "const " : "",
return_type);
if (option[CPLUSPLUS])
ACE_OS::printf ("%s::", option.class_name ());
ACE_OS::printf (option[ANSI]
? "%s (const char *str)\n{\n"
: "%s (str)\n char *str;\n{\n",
option.function_name ());
// Use the switch in place of lookup table.
if (option[SWITCH])
output_switch ();
// Use the lookup table, in place of switch.
else
{
if (!option[GLOBAL])
{
if (option[LENTABLE])
output_keylength_table ();
output_keyword_table ();
}
}
// Logic to handle the Linear Search.
ACE_OS::printf ("for (int i=0; i<=%d; i++)",total_keys-1);
ACE_OS::printf ("\t{\n");
ACE_OS::printf ("\t if (strcmp (wordlist[i].opname_, str) == 0)\n");
ACE_OS::printf ("\t return &wordlist[i];\n");
ACE_OS::printf ("\t}\n");
ACE_OS::printf ("return 0;\n}\n");
if (additional_code)
{
for (;;)
{
int c = getchar ();
if (c == EOF)
break;
else
putchar (c);
}
}
ACE_OS::fflush (stdout);
return 0;
}
// Generates C code for the hash function that returns the proper
// encoding for each key word.
void
Key_List::output_hash_function (void)
{
const int max_column = 10;
int count = max_hash_value;
// Lookup table for converting ASCII to EBCDIC.
static const int ascii_to_ebcdic[ACE_ASCII_SIZE] =
{
0x00, 0x01, 0x02, 0x03, 0x37, 0x2D, 0x2E, 0x2F,
0x16, 0x05, 0x15, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
0x10, 0x11, 0x12, 0x13, 0x3C, 0x3D, 0x32, 0x26,
0x18, 0x19, 0x3F, 0x27, 0x22, 0x1D, 0x1E, 0x1F,
0x40, 0x5A, 0x7F, 0x7B, 0x5B, 0x6C, 0x50, 0x7D,
0x4D, 0x5D, 0x5C, 0x4E, 0x6B, 0x60, 0x4B, 0x61,
0xF0, 0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7,
0xF8, 0xF9, 0x7A, 0x5E, 0x4C, 0x7E, 0x6E, 0x6F,
0x7C, 0xC1, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7,
0xC8, 0xC9, 0xD1, 0xD2, 0xD3, 0xD4, 0xD5, 0xD6,
0xD7, 0xD8, 0xD9, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6,
0xE7, 0xE8, 0xE9, 0xAD, 0xE0, 0xBD, 0x5F, 0x6D,
0x79, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,
0x88, 0x89, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96,
0x97, 0x98, 0x99, 0xA2, 0xA3, 0xA4, 0xA5, 0xA6,
0xA7, 0xA8, 0xA9, 0xC0, 0x6A, 0xD0, 0xA1, 0x07};
int ebcdic_to_ascii[ACE_EBCDIC_SIZE];
int target;
// Calculate maximum number of digits required for MAX_HASH_VALUE.
for (Key_List::field_width = 2;
(count /= 10) > 0;
Key_List::field_width++)
continue;
if (option[INLINE])
ACE_OS::printf ("inline\n");
if (option[C])
ACE_OS::printf ("static ");
ACE_OS::printf ("unsigned int\n");
if (option[CPLUSPLUS])
ACE_OS::printf ("%s::", option.class_name ());
ACE_OS::printf (option[ANSI]
? "%s (const char *str, unsigned int len)\n{\n"
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -