Skip to content

Commit

Permalink
Tools.Standalone.precompile: Add support for unqualified class names
Browse files Browse the repository at this point in the history
A PIKECLASS defined in a cmod can now be referenced by its unqualified
name while in scope.  Only backwards references are supported.
  • Loading branch information
zeldin committed Nov 4, 2018
1 parent dbbb402 commit 2194f96
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 64 deletions.
46 changes: 33 additions & 13 deletions lib/modules/Tools.pmod/Standalone.pmod/precompile.pike
Original file line number Diff line number Diff line change
Expand Up @@ -537,6 +537,21 @@ class PikeType
return a;
}

protected void replace_names(array tok, mapping(string:string) names)
{
int scoped = 0;
foreach(tok; int i; object(PC.Token)|array t)
if (arrayp(t)) {
replace_names(t, names);
scoped = 0;
} else if (((string)t) == "::" || ((string)t) == ".")
scoped = 1;
else if (scoped)
scoped = 0;
else if (names[(string)t])
t->text = names[(string)t];
}

/*
* return the 'one-word' description of this type
*/
Expand Down Expand Up @@ -1065,7 +1080,7 @@ class PikeType
* PikeType( PC.Token("array"), ({ PikeType("int") }) )
*/
void create(string|array(PC.Token)|PC.Token|array(array) tok,
void|array(PikeType) a)
void|array(PikeType)|mapping(string:string) a)
{
switch(sprintf("%t",tok))
{
Expand All @@ -1083,6 +1098,9 @@ class PikeType
while(sizeof(tok) == 1 && arrayp(tok[0]))
tok=tok[0][1..sizeof(tok[0])-2];

if (a)
replace_names(tok, a);

array(array(PC.Token|array(PC.Token|array))) tmp;
tmp=tok/({"|"});

Expand Down Expand Up @@ -1378,7 +1396,7 @@ class Argument
type()->copy_and_strip_type_assignments (1)->output_pike_type(0);
}

void create(array x)
void create(array x, void|mapping(string:string) names)
{
PC.Token t;
if( arrayp(x[-1]) )
Expand All @@ -1393,7 +1411,7 @@ class Argument
}
_file=t->file;
_line=t->line;
_type=PikeType(x[..sizeof(x)-2]);
_type=PikeType(x[..sizeof(x)-2], names);
}

string _sprintf(int how)
Expand Down Expand Up @@ -1888,7 +1906,8 @@ class ParseBlock
array declarations=({});
int local_id = ++gid;

void create(array(array|PC.Token) x, string base, string class_name)
void create(array(array|PC.Token) x, string base, string class_name,
mapping(string:string) names)
{
array(array|PC.Token) ret=({});
array thestruct=({});
Expand Down Expand Up @@ -1916,7 +1935,7 @@ class ParseBlock
if ((e+2 < sizeof(x)) && (((string)x[e+1])[0] == '\"') &&
arrayp(x[e+2])) {
// C++ syntax support...
create(x[e+2], base, class_name);
create(x[e+2], base, class_name, names);
ret += ({ x[e+1], code });
code = ({});
e += 2;
Expand Down Expand Up @@ -2013,7 +2032,7 @@ sprintf(" } else {\n"
name->file, name->line);
}
} else if (name) {
p = mkname((string)name, "program");
p = mkname(names[(string)name]||(string)name, "program");
}
addfuncs +=
IFDEF(define,
Expand Down Expand Up @@ -2064,9 +2083,10 @@ sprintf(" } else {\n"
string name=(string)proto[0];
string lname = mkname(base, name);
mapping attributes=parse_attributes(proto[1..]);

names[name] = lname;
ParseBlock subclass = ParseBlock(body[1..sizeof(body)-2],
mkname(base, name), name);
mkname(base, name), name,
copy_value(names));
string program_var = mkname(base, name, "program");

string define = make_unique_name("class", base, name, "defined");
Expand Down Expand Up @@ -2151,7 +2171,7 @@ sprintf(" } else {\n"
int pos = search(x, PC.Token(";",0), e);
int pos2 = parse_type(x, e+1);
mixed name = x[pos2];
PikeType type = PikeType(x[e+1..pos2-1]);
PikeType type = PikeType(x[e+1..pos2-1], names);
string define = make_unique_name("var",name,base,"defined");
while( x[pos2+1] == "." )
{
Expand Down Expand Up @@ -2405,7 +2425,7 @@ static struct %s *%s_gdb_dummy_ptr;
};

p=parse_type(proto,0);
PikeType rettype=PikeType(proto[..p-1]);
PikeType rettype=PikeType(proto[..p-1], names);

if(arrayp(proto[p]))
{
Expand Down Expand Up @@ -2485,7 +2505,7 @@ static struct %s *%s_gdb_dummy_ptr;
warn("%s:%s Failed to parse types\n", location,name);
}
}
array(Argument) args=map(args_tmp,Argument);
array(Argument) args=map(args_tmp,Argument,names);
// werror("%O %O\n",proto,args);
// werror("parsed args: %O\n", args);

Expand All @@ -2510,7 +2530,7 @@ static struct %s *%s_gdb_dummy_ptr;
else if(attributes->type)
{
mixed err=catch {
type=PikeType(attributes->type);
type=PikeType(attributes->type, names);
};
if(err)
{
Expand Down Expand Up @@ -3302,7 +3322,7 @@ int main(int argc, array(string) argv)

x = recursive(allocate_strings, x);

ParseBlock tmp=ParseBlock(x, base, "");
ParseBlock tmp=ParseBlock(x, base, "", ([]));

tmp->declarations += ({
"\n\n"
Expand Down
2 changes: 1 addition & 1 deletion src/post_modules/Nettle/aead.H
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ PIKECLASS PIKE_NAME
{
DOCSTART() @decl inherit AEAD
DOCEND()
INHERIT Nettle_AEAD;
INHERIT AEAD;

static const struct pike_aead cmod_CONCAT_EVAL(pike_, NETTLE_NAME) =
_PIKE_AEAD(NETTLE_NAME, PIKE_NAME);
Expand Down
2 changes: 1 addition & 1 deletion src/post_modules/Nettle/cipher.H
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ PIKECLASS PIKE_NAME
{
DOCSTART() @decl inherit BASE_CIPHER
DOCEND()
INHERIT cmod_CONCAT_EVAL(Nettle_, BASE_CIPHER);
INHERIT BASE_CIPHER;

static const struct pike_cipher cmod_CONCAT_EVAL(pike_, NETTLE_NAME) =
_PIKE_CIPHER(NETTLE_NAME, PIKE_NAME);
Expand Down
Loading

0 comments on commit 2194f96

Please sign in to comment.