📄 idl.ll
字号:
++tp;
}
else
{
*tp = *sp;
++tp;
}
++sp;
}
// The '\n' is still <crunched> spaces too far away, with
// garbage characters in between.
sp -= crunched;
*sp = '\0';
if (ACE_OS::strstr (buf + 8, "import") != 0)
{
idl_global->set_import (I_TRUE);
return;
}
if (ACE_OS::strstr (buf + 8, "include") != 0)
{
idl_global->set_import (I_FALSE);
return;
}
if (ACE_OS::strncmp (buf + 8, "prefix", 6) == 0)
{
char *new_prefix = idl_get_pragma_string (buf);
if (new_prefix != 0)
{
unsigned long depth = idl_global->scopes ().depth ();
// At global scope, we always replace the prefix. For all
// other scopes, we replace only if there is a prefix already
// associated with that scope, otherwise we add the prefix.
if (depth == 1 || idl_global->scopes ().top ()->has_prefix ())
{
char *trash = 0;
idl_global->pragma_prefixes ().pop (trash);
delete [] trash;
}
UTL_Scope *top_scope = idl_global->scopes ().top ();
if (depth > 1)
{
top_scope->has_prefix (I_TRUE);
ScopeAsDecl (top_scope)->prefix_scope (top_scope);
}
idl_global->pragma_prefixes ().push (new_prefix);
if (idl_global->in_main_file ())
{
idl_global->root ()->prefix (new_prefix);
idl_global->root ()->set_imported (I_FALSE);
top_scope->has_prefix (I_TRUE);
}
ACE_CString ext_id;
ext_id.set (idl_global->filename ()->get_string (),
0);
char *int_id = ACE::strnew (new_prefix);
(void) idl_global->file_prefixes ().rebind (ext_id,
int_id);
}
}
else if (ACE_OS::strncmp (buf + 8, "version", 7) == 0)
{
char *tmp = buf + 16;
while (*tmp == ' ' || *tmp == '\t')
{
++tmp;
}
char *number = ACE_OS::strchr (tmp, ' ');
if (number == 0)
{
number = ACE_OS::strchr (tmp, '\t');
}
while (*number == ' ' || *number == '\t')
{
++number;
}
size_t len = ACE_OS::strlen (number);
// For some reason, the SunCC preprocessor adds a trailing space, which
// messes with idl_valid_version() below, so we check and remove.
while (number[len - 1] == ' ')
{
number[len - 1] = '\0';
len = ACE_OS::strlen (number);
}
// This call adds a proper null terminator to tmp, so no need to
// do it here.
AST_Decl *d = idl_find_node (tmp);
if (d == 0)
{
return;
}
if (!idl_valid_version (number))
{
idl_global->err ()->version_number_error (number);
return;
}
d->version (ACE::strnew (number));
}
else if (ACE_OS::strncmp (buf + 8, "ident", 5) == 0)
{
idl_global->ident_string (buf + 8);
}
else if (ACE_OS::strncmp (buf + 8, "ID", 2) == 0)
{
char *tmp = buf + 11;
while (*tmp == ' ')
{
++tmp;
}
AST_Decl *d = idl_find_node (tmp);
if (d == 0)
{
return;
}
char *new_id = idl_get_pragma_string (buf);
if (new_id != 0)
{
d->repoID (new_id);
d->typeid_set (1);
}
}
}
/*
* idl_atoi - Convert a string of digits into a negative integer according to base b
*/
static long
idl_atoi(char *s, long b)
{
long r = 0;
s++;
if (b == 8 && *s == '0')
{
s++;
}
else if (b == 16 && *s == '0' && (*(s + 1) == 'x' || *(s + 1) == 'X'))
{
s += 2;
}
for (; *s; ++s)
{
if (*s <= '9' && *s >= '0')
{
r = (r * b) + (*s - '0');
}
else if (b > 10 && *s <= 'f' && *s >= 'a')
{
r = (r * b) + (*s - 'a' + 10);
}
else if (b > 10 && *s <= 'F' && *s >= 'A')
{
r = (r * b) + (*s - 'A' + 10);
}
else
{
break;
}
}
return -r;
}
/*
* idl_atoui - Convert a string of digits into an unsigned integer according to base b
*/
static ACE_UINT64
idl_atoui(char *s, long b)
{
ACE_UINT64 r = 0;
if (b == 8 && *s == '0')
{
s++;
}
else if (b == 16 && *s == '0' && (*(s + 1) == 'x' || *(s + 1) == 'X'))
{
s += 2;
}
for (; *s; ++s)
{
if (*s <= '9' && *s >= '0')
{
r = (r * b) + (*s - '0');
}
else if (b > 10 && *s <= 'f' && *s >= 'a')
{
r = (r * b) + (*s - 'a' + 10);
}
else if (b > 10 && *s <= 'F' && *s >= 'A')
{
r = (r * b) + (*s - 'A' + 10);
}
else
{
break;
}
}
return r;
}
/*
* Convert a string to a float; atof doesn't seem to work, always.
*/
static double
idl_atof (char *s)
{
double d = 0.0;
double e, k;
long neg = 0, negexp = 0;
if (*s == '-')
{
neg = 1;
s++;
}
while (*s >= '0' && *s <= '9')
{
d = (d * 10) + *s - '0';
s++;
}
if (*s == '.')
{
s++;
e = 10;
while (*s >= '0' && *s <= '9')
{
d += (*s - '0') / (e * 1.0);
e *= 10;
s++;
}
}
if (*s == 'e' || *s == 'E')
{
s++;
if (*s == '-')
{
negexp = 1;
s++;
}
else if (*s == '+')
{
s++;
}
e = 0;
while (*s >= '0' && *s <= '9')
{
e = (e * 10) + *s - '0';
s++;
}
if (e > 0)
{
for (k = 1; e > 0; k *= 10, e--);
if (negexp)
{
d /= k;
}
else
{
d *= k;
}
}
}
if (neg)
{
d *= -1.0;
}
return d;
}
/*
* Convert (some) escaped characters into their ascii values
*/
static char
idl_escape_reader(
char *str
)
{
if (str[0] != '\\')
{
return str[0];
}
switch (str[1])
{
case 'n':
return '\n';
case 't':
return '\t';
case 'v':
return '\v';
case 'b':
return '\b';
case 'r':
return '\r';
case 'f':
return '\f';
case 'a':
return '\a';
case '\\':
return '\\';
case '\?':
return '?';
case '\'':
return '\'';
case '"':
return '"';
case 'x':
{
int i;
// hex value
for (i = 2; str[i] != '\0' && isxdigit (str[i]); ++i)
{
continue;
}
char save = str[i];
str[i] = '\0';
char out = (char)idl_atoui(&str[2], 16);
str[i] = save;
return out;
}
ACE_NOTREACHED (break;)
default:
// check for octal value
if (str[1] >= '0' && str[1] <= '7')
{
int i;
for (i = 1; str[i] >= '0' && str[i] <= '7'; ++i)
{
continue;
}
char save = str[i];
str[i] = '\0';
char out = (char)idl_atoui(&str[1], 8);
str[i] = save;
return out;
}
else
{
return str[1] - 'a';
}
ACE_NOTREACHED (break;)
}
}
/*
* Convert escaped hex digits into a wchar
*/
static ACE_CDR::WChar
idl_wchar_escape_reader (char *str)
{
if (str[0] != '\\' || str[1] != 'u')
{
return 0;
}
int i;
// get the hex digits
for (i = 2; str[i] != '\0' && isxdigit (str[i]); i++)
{
continue;
}
char save = str[i];
str[i] = '\0';
ACE_CDR::WChar out = (ACE_CDR::WChar) idl_atoui (&str[2], 16);
str[i] = save;
return out;
}
/*
* Checks wstring for validity
*/
static char *
idl_wstring_escape_reader (char *str)
{
return str;
}
static char *
idl_get_pragma_string (char *pragma)
{
// Get pointers to each end of the substring between the quotes.
const char *start = ACE_OS::strchr (pragma, '"') + 1;
const char *end = ACE_OS::strchr (start, '"');
if (end == 0)
{
idl_global->err ()->syntax_error (
IDL_GlobalData::PS_PragmaPrefixSyntax
);
return 0;
}
int len = end - start;
char *retval = 0;
ACE_NEW_RETURN (retval,
char[len + 1],
0);
ACE_OS::strncpy (retval,
start,
len);
retval[len] = '\0';
return retval;
}
static idl_bool
idl_valid_version (char *s)
{
// Nothing preceding decimal point.
if (*s == '.')
{
return 0;
}
char *minor = ACE_OS::strchr (s, '.');
int i;
if (minor == 0)
{
// No decimal point.
return 0;
}
if (*(minor + 1) == '\0')
{
// Nothing following decimal point.
return 0;
}
char *tmp = minor + 1;
for (i = 0; tmp[i] != '\0'; ++i)
{
if (!isdigit (tmp[i]))
{
return 0;
}
}
int len = minor - s;
for (i = 0; i < len; ++i)
{
if (!isdigit (s[i]))
{
return 0;
}
}
// Major and minor version numbers must be unsigned shorts.
if (ACE_OS::atoi (minor + 1) > ACE_UINT16_MAX
|| ACE_OS::atoi (s) > ACE_UINT16_MAX)
{
return 0;
}
return 1;
}
static AST_Decl *
idl_find_node (char *s)
{
UTL_ScopedName *node = idl_global->string_to_scoped_name (s);
AST_Decl *d = 0;
if (node != 0)
{
d = idl_global->scopes ().top_non_null ()->lookup_by_name (node,
I_TRUE);
}
if (d == 0)
{
idl_global->err ()->lookup_error (node);
node->destroy ();
delete node;
node = 0;
}
return d;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -