Skip to content

Commit

Permalink
[Compiler] Fix "decl" quasi-quotation.
Browse files Browse the repository at this point in the history
  • Loading branch information
VladD2 committed Sep 11, 2011
1 parent 94555e4 commit eb7ae35
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 24 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Expand Up @@ -29,3 +29,5 @@ VsIntegration/Nemerle.VisualStudio/Templates/Projects/Web/WSWebSite/Nemerle.dll
misc/packages/wix/net-?.?/bin/*.*
misc/packages/wix/net-?.?/dist/*.*
misc/packages/wix/net-?.?/obj/*.*

snippets/peg-parser/Nemerle.Peg/_N_GeneratedSource_PegTest.n
2 changes: 1 addition & 1 deletion ncc/parsing/MainParser.n
Expand Up @@ -1043,7 +1043,7 @@ namespace Nemerle.Compiler
| "class" | "struct" | "module" | "interface" | "enum" | "variant" => processType(key)
| "delegate" =>
def h = parse_fun_header (null);
def td = TopDeclaration.Delegate (startLocation + h.Location, h.ParsedSplicableName, mods, h.ParsedTypeParameters, h);
def td = TopDeclaration.Delegate(startLocation + h.Location, h.ParsedSplicableName, mods, h.ParsedTypeParameters, h);
expect_empty ("delegate declaraion");
td

Expand Down
9 changes: 8 additions & 1 deletion ncc/parsing/ParseTree.n
Expand Up @@ -233,7 +233,14 @@ namespace Nemerle.Compiler.Parsetree
[Record (Exclude = [_env, _tokens, _bodyLocation, _definedIn, _builder, _userData])]
public variant ClassMember : MemberBase
{
| TypeDeclaration { td : TopDeclaration; }
| TypeDeclaration
{
td : TopDeclaration;

public this(name : Splicable, td : TopDeclaration) { this(td.Location, name, td.modifiers, td) }
public this(td : TopDeclaration) { this(td.Location, td.name, td.modifiers, td) }
}

| Field
{
mutable ty : PExpr;
Expand Down
85 changes: 63 additions & 22 deletions ncc/typing/Macros.n
Expand Up @@ -316,8 +316,56 @@ public module Macros
]>

| ([], _) =>
<[ Modifiers (($((attrs.mods :> int) : int) :> NemerleAttributes),
$(Lift (attrs.custom_attrs, quoted_expr))) ]>
def quoted_modifiers(modifiers : NemerleAttributes) : PExpr
{
mutable result = [];

when (modifiers %&& NemerleAttributes.Public)
result ::= <[ Nemerle.Compiler.NemerleAttributes.Public ]>;
when (modifiers %&& NemerleAttributes.Private)
result ::= <[ Nemerle.Compiler.NemerleAttributes.Private ]>;
when (modifiers %&& NemerleAttributes.New)
result ::= <[ Nemerle.Compiler.NemerleAttributes.New ]>;
when (modifiers %&& NemerleAttributes.Protected)
result ::= <[ Nemerle.Compiler.NemerleAttributes.Protected ]>;
when (modifiers %&& NemerleAttributes.Abstract)
result ::= <[ Nemerle.Compiler.NemerleAttributes.Abstract ]>;
when (modifiers %&& NemerleAttributes.Virtual)
result ::= <[ Nemerle.Compiler.NemerleAttributes.Virtual ]>;
when (modifiers %&& NemerleAttributes.Sealed)
result ::= <[ Nemerle.Compiler.NemerleAttributes.Sealed ]>;
when (modifiers %&& NemerleAttributes.Static)
result ::= <[ Nemerle.Compiler.NemerleAttributes.Static ]>;
when (modifiers %&& NemerleAttributes.Mutable)
result ::= <[ Nemerle.Compiler.NemerleAttributes.Mutable ]>;
when (modifiers %&& NemerleAttributes.Internal)
result ::= <[ Nemerle.Compiler.NemerleAttributes.Internal ]>;
when (modifiers %&& NemerleAttributes.Override)
result ::= <[ Nemerle.Compiler.NemerleAttributes.Override ]>;
when (modifiers %&& NemerleAttributes.Struct)
result ::= <[ Nemerle.Compiler.NemerleAttributes.Struct ]>;
when (modifiers %&& NemerleAttributes.Macro)
result ::= <[ Nemerle.Compiler.NemerleAttributes.Macro ]>;
when (modifiers %&& NemerleAttributes.Volatile)
result ::= <[ Nemerle.Compiler.NemerleAttributes.Volatile ]>;
when (modifiers %&& NemerleAttributes.SpecialName)
result ::= <[ Nemerle.Compiler.NemerleAttributes.SpecialName ]>;
when (modifiers %&& NemerleAttributes.Partial)
result ::= <[ Nemerle.Compiler.NemerleAttributes.Partial ]>;
when (modifiers %&& NemerleAttributes.Extern)
result ::= <[ Nemerle.Compiler.NemerleAttributes.Extern ]>;
when (modifiers %&& NemerleAttributes.CompilerMutable)
result ::= <[ Nemerle.Compiler.NemerleAttributes.CompilerMutable ]>;

match (result)
{
| [] => <[ Nemerle.Compiler.NemerleAttributes.None ]>
| [x] => x
| xs => xs.Tail.FoldLeft(xs.Head, (x, acc) => <[ $x | $acc ]>)
}
}

<[ Modifiers($(quoted_modifiers(attrs.mods)), $(Lift(attrs.custom_attrs, quoted_expr))) ]>

| ((first :: _) as attrs, _) =>
Message.Error(first.Location, $"more than one splice for custom attributes and modifiers defined (..$attrs)");
Expand All @@ -332,19 +380,11 @@ public module Macros

match (mem)
{
| ClassMember.TypeDeclaration (td) =>
<[ ClassMember.TypeDeclaration (name = $qnm, modifiers = $qattrs,
td = $(quoted_tydecl (td))) ]>

| ClassMember.Field (t) =>
// | <[ decl: ..$_ $_ : $t; ]> => // field
<[ ClassMember.Field (name = $qnm, modifiers = $qattrs,
ty = $(quoted_expr (t))) ]>

// Example
// <[ decl: ..$attrs $n < ..$tparms> (..$fparms) : $t where ..$cts
// implements ..$impl $body ]>
| ClassMember.Function ( header = PFunHeader where (TypeParameters =
| ClassMember.TypeDeclaration(td) => <[ ClassMember.TypeDeclaration(td = $(quoted_tydecl(td))) ]>
// | <[ decl: ..$_ $_ : $t; ]> => // field
| ClassMember.Field(t) => <[ ClassMember.Field(name = $qnm, modifiers = $qattrs, ty = $(quoted_expr(t))) ]>
// Example: <[ decl: ..$attrs $name [..$typeParameters] (..$parameters) : $returnType where ..$constrants implements ..$impl $body ]>
| ClassMember.Function( header = PFunHeader where (TypeParameters =
Typarms where (tparms, cts), ReturnType = t, Parameters = fparms), implemented = implemented, body = bd) =>
def qtparms = quoted_tparms (tparms, cts);
def qhd = make_quoted_funheader (fparms, qtparms, t, qnm);
Expand All @@ -355,11 +395,11 @@ public module Macros
implemented = $(lift_with_ellipsis (implemented)),
body = $(quoted_funbody (bd))) ]>

| ClassMember.EnumOption (val) =>
| ClassMember.EnumOption(val) =>
def qval = Lift (val, quoted_expr);
<[ ClassMember.EnumOption (name = $qnm, modifiers = $qattrs, value = $qval) ]>

| ClassMember.Event ( ty = t, add = a, remove = r, field = f) =>
| ClassMember.Event(ty = t, add = a, remove = r, field = f) =>
<[ ClassMember.Event (name = $qnm, modifiers = $qattrs, ty = $(quoted_expr (t)),
add = $(quoted_member (a)),
remove = $(quoted_member (r)),
Expand Down Expand Up @@ -780,8 +820,10 @@ public module Macros
| <[ Literal.$_ ($v, $n, $_) . $_ () ]> =>
<[ Literal.Integer ($v, $n, _) ]>

| <[ $constr (.. $pars) ]> =>
def (con, name) = Option.UnSome (Util.QidOfExpr (constr));
| <[ $a | $b ]> => <[ $(patternize_quotation(a)) | $(patternize_quotation(b)) ]>
| <[ @|(..$pars) ]> => <[ @|(..$(pars.Map(patternize_quotation))) ]>
| <[ $constr(..$pars) ]> =>
def (con, name) = Option.UnSome (Util.QidOfExpr(constr));
def last = con.Last;
match (name.context.LookupType (con))
{
Expand Down Expand Up @@ -829,10 +871,9 @@ public module Macros
// compiler internal computation we can ignore it
def name_expr = Util.ExprOfQid (tcon.FullName);
if (last.EndsWith ("Name"))
<[ $name_expr where ( idl = $(patternize_quotation (NList.Head (pars))) ) ]>
<[ $name_expr where(idl = $(patternize_quotation(pars.Head))) ]>
else
PExpr.Where (name_expr,
PExpr.Tuple.Create (convert_params (pars, flds, [])))
PExpr.Where(name_expr, PExpr.Tuple.Create(convert_params(pars, flds, [])))

| Typedtree.TypeDeclaration.Alias (FixedType.Class (tc, _)) => unalias (tc)
| _ => Util.ice ("expression generated from quotation has neither variant nor class constructor")
Expand Down

0 comments on commit eb7ae35

Please sign in to comment.