Skip to content
This repository has been archived by the owner on Nov 3, 2023. It is now read-only.

Commit

Permalink
Fix dependent property evaluation over projected properties.
Browse files Browse the repository at this point in the history
  • Loading branch information
someone-with-default-username committed Jul 19, 2016
1 parent 9d749de commit cf5ca79
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ namespace Nitra.Compiler
}));
}

protected DefineDependentPropertiesSealedEvaluation(tb : TypeBuilder, symbol : PropertyContainerSymbol, dependentProperties : SCG.Dictionary[DependentPropertySymbol, BitField], structuralProperties : SCG.Dictionary[StructuralPropertySymbol, FixedType]) : void
protected DefineDependentPropertiesSealedEvaluation(tb : TypeBuilder, symbol : PropertyContainerSymbol, dependentProperties : SCG.Dictionary[DependentPropertySymbol, BitField], structuralProperties : SCG.Dictionary[PropertySymbol, FixedType]) : void
{
Util.locate(symbol.FirstLocation.NLocation(), tb.Manager.MacroColors.InGlobalColor(fun()
{
Expand All @@ -59,6 +59,17 @@ namespace Nitra.Compiler
}));
}

protected IsEvaluatableProjectedProperty(propertySymbol : ProjectedPropertySymbol) : bool
{
match (propertySymbol.AstType)
{
| Option
| OptionList
| List => true
| _ => false
}
}

private CompileStatements(tb : TypeBuilder, symbol : PropertyContainerSymbol, methodHeader : ClassMember.Function) : MethodBuilder
{
def mb = tb.DefineAndReturn(methodHeader) :> MethodBuilder;
Expand Down Expand Up @@ -533,7 +544,7 @@ namespace Nitra.Compiler
}
}

private GenerateCode(tb : TypeBuilder, symbol : PropertyContainerSymbol, dependencyGraph : PropertyDependencyGraph, dependentProperties : SCG.Dictionary[DependentPropertySymbol, BitField], structuralProperties : SCG.Dictionary[StructuralPropertySymbol, FixedType]) : PExpr
private GenerateCode(tb : TypeBuilder, symbol : PropertyContainerSymbol, dependencyGraph : PropertyDependencyGraph, dependentProperties : SCG.Dictionary[DependentPropertySymbol, BitField], structuralProperties : SCG.Dictionary[PropertySymbol, FixedType]) : PExpr
{
def compileCode(symbol : PropertyContainerSymbol, code : PropertyDependencyCode) : PExpr
{
Expand Down Expand Up @@ -599,7 +610,7 @@ namespace Nitra.Compiler
result.Add(<[ _ = context ]>);

def evaluatedStructuralProperties = SCG.HashSet();
def evalStructuralProperty(propertySymbol : StructuralPropertySymbol, propertyType : FixedType) : void
def evalStructuralProperty(propertySymbol : PropertySymbol, propertyType : FixedType) : void
{
when (evaluatedStructuralProperties.Add(propertySymbol))
when (propertyType.TryRequire(Environment.AstTypeVar))
Expand Down Expand Up @@ -647,8 +658,16 @@ namespace Nitra.Compiler
result.Add(expr4);

| Use =>
when (node.Path is DeclaredProperty(This, StructuralPropertySymbol as propertySymbol, _))
evalStructuralProperty(propertySymbol, structuralProperties[propertySymbol]);
match (node.Path)
{
| DeclaredProperty(This, StructuralPropertySymbol as propertySymbol, _) =>
evalStructuralProperty(propertySymbol, structuralProperties[propertySymbol])

| DeclaredProperty(This, ProjectedPropertySymbol as propertySymbol, _) when IsEvaluatableProjectedProperty(propertySymbol) =>
evalStructuralProperty(propertySymbol, structuralProperties[propertySymbol])

| _ => ()
}
}

foreach (call in dependencyGraph.Calls)
Expand Down
4 changes: 3 additions & 1 deletion Boot2/Nitra.Compiler/Generation/Ast/SimpleAstEmitter.n
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ namespace Nitra.Compiler
}

private _dependentPropBits : SCG.Dictionary[DependentPropertySymbol, BitField] = SCG.Dictionary();
private _structuralPropTypes : SCG.Dictionary[StructuralPropertySymbol, FixedType] = SCG.Dictionary();
private _structuralPropTypes : SCG.Dictionary[PropertySymbol, FixedType] = SCG.Dictionary();

public override DefineMembers() : void
{
Expand Down Expand Up @@ -131,6 +131,8 @@ namespace Nitra.Compiler
{
def name = propertySymbol.Name;
def propertyType = TypeCompiler.CompileProjectedPropertyType(propertySymbol);
when (IsEvaluatableProjectedProperty(propertySymbol))
_structuralPropTypes.Add(propertySymbol, propertyType);
DefineStructuralProperty(propertySymbol, propertyType, _tb, _ambiguousTb);
projectedProps.Add(propertySymbol);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ namespace Nitra.Compiler
}));
}

protected DefineDependentPropertiesSealedEvaluation(tb : TypeBuilder, symbol : PropertyContainerSymbol, dependentProperties : SCG.Dictionary[DependentPropertySymbol, BitField], structuralProperties : SCG.Dictionary[StructuralPropertySymbol, FixedType]) : void
protected DefineDependentPropertiesSealedEvaluation(tb : TypeBuilder, symbol : PropertyContainerSymbol, dependentProperties : SCG.Dictionary[DependentPropertySymbol, BitField], structuralProperties : SCG.Dictionary[PropertySymbol, FixedType]) : void
{
Util.locate(symbol.FirstLocation.NLocation(), tb.Manager.MacroColors.InGlobalColor(fun()
{
Expand All @@ -59,6 +59,17 @@ namespace Nitra.Compiler
}));
}

protected IsEvaluatableProjectedProperty(propertySymbol : ProjectedPropertySymbol) : bool
{
match (propertySymbol.AstType)
{
| Option
| OptionList
| List => true
| _ => false
}
}

private CompileStatements(tb : TypeBuilder, symbol : PropertyContainerSymbol, methodHeader : ClassMember.Function) : MethodBuilder
{
def mb = tb.DefineAndReturn(methodHeader) :> MethodBuilder;
Expand Down Expand Up @@ -533,7 +544,7 @@ namespace Nitra.Compiler
}
}

private GenerateCode(tb : TypeBuilder, symbol : PropertyContainerSymbol, dependencyGraph : PropertyDependencyGraph, dependentProperties : SCG.Dictionary[DependentPropertySymbol, BitField], structuralProperties : SCG.Dictionary[StructuralPropertySymbol, FixedType]) : PExpr
private GenerateCode(tb : TypeBuilder, symbol : PropertyContainerSymbol, dependencyGraph : PropertyDependencyGraph, dependentProperties : SCG.Dictionary[DependentPropertySymbol, BitField], structuralProperties : SCG.Dictionary[PropertySymbol, FixedType]) : PExpr
{
def compileCode(symbol : PropertyContainerSymbol, code : PropertyDependencyCode) : PExpr
{
Expand Down Expand Up @@ -599,7 +610,7 @@ namespace Nitra.Compiler
result.Add(<[ _ = context ]>);

def evaluatedStructuralProperties = SCG.HashSet();
def evalStructuralProperty(propertySymbol : StructuralPropertySymbol, propertyType : FixedType) : void
def evalStructuralProperty(propertySymbol : PropertySymbol, propertyType : FixedType) : void
{
when (evaluatedStructuralProperties.Add(propertySymbol))
when (propertyType.TryRequire(Environment.AstTypeVar))
Expand Down Expand Up @@ -647,8 +658,16 @@ namespace Nitra.Compiler
result.Add(expr4);

| Use =>
when (node.Path is DeclaredProperty(This, StructuralPropertySymbol as propertySymbol, _))
evalStructuralProperty(propertySymbol, structuralProperties[propertySymbol]);
match (node.Path)
{
| DeclaredProperty(This, StructuralPropertySymbol as propertySymbol, _) =>
evalStructuralProperty(propertySymbol, structuralProperties[propertySymbol])

| DeclaredProperty(This, ProjectedPropertySymbol as propertySymbol, _) when IsEvaluatableProjectedProperty(propertySymbol) =>
evalStructuralProperty(propertySymbol, structuralProperties[propertySymbol])

| _ => ()
}
}

foreach (call in dependencyGraph.Calls)
Expand Down
4 changes: 3 additions & 1 deletion Nitra/Nitra.Compiler/Generation/Ast/SimpleAstEmitter.n
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ namespace Nitra.Compiler
}

private _dependentPropBits : SCG.Dictionary[DependentPropertySymbol, BitField] = SCG.Dictionary();
private _structuralPropTypes : SCG.Dictionary[StructuralPropertySymbol, FixedType] = SCG.Dictionary();
private _structuralPropTypes : SCG.Dictionary[PropertySymbol, FixedType] = SCG.Dictionary();

public override DefineMembers() : void
{
Expand Down Expand Up @@ -131,6 +131,8 @@ namespace Nitra.Compiler
{
def name = propertySymbol.Name;
def propertyType = TypeCompiler.CompileProjectedPropertyType(propertySymbol);
when (IsEvaluatableProjectedProperty(propertySymbol))
_structuralPropTypes.Add(propertySymbol, propertyType);
DefineStructuralProperty(propertySymbol, propertyType, _tb, _ambiguousTb);
projectedProps.Add(propertySymbol);

Expand Down

0 comments on commit cf5ca79

Please sign in to comment.