Skip to content

Commit

Permalink
Syntax Tree Walkers (microsoft#233)
Browse files Browse the repository at this point in the history
  • Loading branch information
Alan Geller authored and bettinaheim committed Nov 15, 2019
1 parent 8f69348 commit add8a07
Show file tree
Hide file tree
Showing 11 changed files with 1,046 additions and 19 deletions.
15 changes: 9 additions & 6 deletions src/QsCompiler/CompilationManager/CompilationUnit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -395,8 +395,9 @@ internal void UpdateCallables(IEnumerable<QsCallable> updates)
if (header.Kind.IsTypeConstructor)
{
var specLocation = new QsLocation(header.Position, header.SymbolRange);
var defaultSpec = new QsSpecialization(QsSpecializationKind.QsBody, header.QualifiedName, header.Attributes, header.SourceFile, specLocation,
QsNullable<ImmutableArray<ResolvedType>>.Null, header.Signature, SpecializationImplementation.Intrinsic, ImmutableArray<string>.Empty, QsComments.Empty);
var defaultSpec = new QsSpecialization(QsSpecializationKind.QsBody, header.QualifiedName, header.Attributes,
header.SourceFile, specLocation, QsNullable<ImmutableArray<ResolvedType>>.Null, header.Signature, SpecializationImplementation.Intrinsic,
ImmutableArray<string>.Empty, QsComments.Empty);
this.CompiledCallables[fullName] = new QsCallable(header.Kind, header.QualifiedName, header.Attributes, header.SourceFile, specLocation,
header.Signature, header.ArgumentTuple, ImmutableArray.Create<QsSpecialization>(defaultSpec), header.Documentation, QsComments.Empty);
continue;
Expand All @@ -418,8 +419,9 @@ internal void UpdateCallables(IEnumerable<QsCallable> updates)
var compiledSpec = compiledSpecs.Single();
var specLocation = new QsLocation(specHeader.Position, specHeader.HeaderRange);
return new QsSpecialization(compiledSpec.Kind, compiledSpec.Parent, compiledSpec.Attributes, compiledSpec.SourceFile, specLocation,
compiledSpec.TypeArguments, compiledSpec.Signature, compiledSpec.Implementation, compiledSpec.Documentation, compiledSpec.Comments);
return new QsSpecialization(compiledSpec.Kind, compiledSpec.Parent, compiledSpec.Attributes,
compiledSpec.SourceFile, specLocation, compiledSpec.TypeArguments, compiledSpec.Signature, compiledSpec.Implementation,
compiledSpec.Documentation, compiledSpec.Comments);
})
.Where(spec => spec != null).ToImmutableArray();

Expand Down Expand Up @@ -452,8 +454,9 @@ private QsCallable GetImportedCallable(CallableDeclarationHeader header)
var specSignature = specHeader.Kind.IsQsControlled || specHeader.Kind.IsQsControlledAdjoint
? SyntaxGenerator.BuildControlled(header.Signature)
: header.Signature;
return new QsSpecialization(specHeader.Kind, header.QualifiedName, specHeader.Attributes, specHeader.SourceFile, specLocation,
specHeader.TypeArguments, specSignature, implementation, specHeader.Documentation, QsComments.Empty);
return new QsSpecialization(specHeader.Kind, header.QualifiedName, specHeader.Attributes,
specHeader.SourceFile, specLocation, specHeader.TypeArguments, specSignature,
implementation, specHeader.Documentation, QsComments.Empty);
})
.ToImmutableArray();
var location = new QsLocation(header.Position, header.SymbolRange);
Expand Down
4 changes: 2 additions & 2 deletions src/QsCompiler/CompilationManager/TypeChecking.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1226,8 +1226,8 @@ private static ImmutableArray<QsSpecialization> BuildSpecializations

QsSpecialization GetSpecialization(SpecializationDeclarationHeader spec, ResolvedSignature signature,
SpecializationImplementation implementation, QsComments comments = null) =>
new QsSpecialization(spec.Kind, spec.Parent, spec.Attributes, spec.SourceFile, null,
spec.TypeArguments, SyntaxGenerator.WithoutRangeInfo(signature), implementation, spec.Documentation, comments ?? QsComments.Empty);
new QsSpecialization(spec.Kind, spec.Parent, spec.Attributes, spec.SourceFile, null,
spec.TypeArguments, SyntaxGenerator.WithoutRangeInfo(signature), implementation, spec.Documentation, comments ?? QsComments.Empty);

QsSpecialization BuildSpecialization(QsSpecializationKind kind, ResolvedSignature signature, QsSpecializationGeneratorKind<QsSymbol> gen, FragmentTree.TreeNode root,
Func<QsSymbol, Tuple<QsTuple<LocalVariableDeclaration<QsLocalSymbol>>, QsCompilerDiagnostic[]>> buildArg, QsComments comments = null)
Expand Down
3 changes: 3 additions & 0 deletions src/QsCompiler/Core/Core.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
<Compile Include="ExpressionTransformation.fs" />
<Compile Include="StatementTransformation.fs" />
<Compile Include="TreeTransformation.fs" />
<Compile Include="ExpressionWalker.fs" />
<Compile Include="StatementWalker.fs" />
<Compile Include="TreeWalker.fs" />
<Compile Include="Dependencies.fs" />
<Compile Include="SyntaxGenerator.fs" />
<Compile Include="DeclarationHeaders.fs" />
Expand Down
3 changes: 2 additions & 1 deletion src/QsCompiler/Core/ExpressionTransformation.fs
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,8 @@ type ExpressionKindTransformation(?enable) =
| ExpressionType.Operation _ -> this.onOperationCall (method, arg)
| _ -> this.onFunctionCall (method, arg)

member this.Transform kind =
abstract member Transform : ExpressionKind -> ExpressionKind
default this.Transform kind =
if not enable then kind else
match kind with
| Identifier (sym, tArgs) -> this.onIdentifier (sym, tArgs)
Expand Down
Loading

0 comments on commit add8a07

Please sign in to comment.