public override Node CompileParseTree(Node node, Scope scope, Module targetModule, ErrorNodeList errorNodes){ TrivialHashtable ambiguousTypes = new TrivialHashtable(); TrivialHashtable referencedLabels = new TrivialHashtable(); TrivialHashtable scopeFor = new TrivialHashtable(); ErrorHandler errorHandler = new ErrorHandler(errorNodes); SpecSharpCompilation ssCompilation = new SpecSharpCompilation(); // Setting the state TypeNode thisType = null; Method currentMethod = null; BlockScope blockScope = scope as BlockScope; if (blockScope != null){ Class baseScope = blockScope; MethodScope methodScope = null; while (baseScope != null){ methodScope = baseScope.BaseClass as MethodScope; if (methodScope != null) break; baseScope = baseScope.BaseClass; } if (methodScope != null){ thisType = methodScope.ThisType; if (thisType == null && methodScope.BaseClass is TypeScope){ thisType = ((TypeScope) methodScope.BaseClass).Type; } currentMethod = methodScope.DeclaringMethod; } } //Attach scope to namespaces and types scopeFor[node.UniqueKey] = scope; Scoper scoper = new Scoper(scopeFor); scoper.currentScope = scope; node = scoper.Visit(node); //Walk IR looking up names Looker looker = new Looker(scope, errorHandler, scopeFor, ambiguousTypes, referencedLabels); // begin change by drunje (this is called from debugger only) looker.AllowPointersToManagedStructures = true; // end change by drunje if (blockScope != null) { looker.currentType = thisType; looker.currentMethod = currentMethod; } looker.currentAssembly = targetModule as AssemblyNode; looker.currentModule = targetModule; node = looker.Visit(node); //Walk IR inferring types and resolving overloads TypeSystem typeSystem = new TypeSystem(errorHandler); Resolver resolver = new Resolver(errorHandler, typeSystem); if (blockScope != null){ resolver.currentType = thisType; resolver.currentMethod = currentMethod; } resolver.currentAssembly = targetModule as AssemblyNode; resolver.currentModule = targetModule; node = resolver.Visit(node); //TODO: Need to set the state of the checker for compiling Expression, STOP using this method when the shift is complete //Walk IR checking for semantic errors and repairing it so that the next walk will work Checker checker = new Checker(ssCompilation, errorHandler, typeSystem, scopeFor, ambiguousTypes, referencedLabels); if (blockScope != null){ checker.currentType = thisType; checker.currentMethod = currentMethod; } checker.currentAssembly = targetModule as AssemblyNode; checker.currentModule = targetModule; node = checker.Visit(node); //Walk IR reducing it to nodes that have predefined mappings to MD+IL Normalizer normalizer = new Normalizer(typeSystem); if (blockScope != null){ normalizer.currentType = thisType; normalizer.currentMethod = currentMethod; normalizer.WrapToBlockExpression = false; } normalizer.currentModule = targetModule; node = normalizer.Visit(node); return node; }
public override void Resolve(Member unresolvedMember, Member resolvedMember){ if (unresolvedMember == null || resolvedMember == null) return; if (this.scopeFor == null) return; ErrorHandler errorHandler = new ErrorHandler(new ErrorNodeList(0)); TrivialHashtable ambiguousTypes = new TrivialHashtable(); TrivialHashtable referencedLabels = new TrivialHashtable(); Looker looker = new Looker(null, errorHandler, this.scopeFor, ambiguousTypes, referencedLabels); looker.currentAssembly = (looker.currentModule = this.currentSymbolTable) as AssemblyNode; TypeNode currentType = resolvedMember.DeclaringType; if (resolvedMember is TypeNode && unresolvedMember.DeclaringType != null && ((TypeNode)resolvedMember).FullName == unresolvedMember.DeclaringType.FullName){ unresolvedMember.DeclaringType = (TypeNode)resolvedMember; currentType = (TypeNode)resolvedMember; looker.scope = this.scopeFor[resolvedMember.UniqueKey] as Scope; }else if (unresolvedMember is TypeNode && resolvedMember.DeclaringType != null){ if (((TypeNode)unresolvedMember).FullName != resolvedMember.DeclaringType.FullName) return; //Too many changes since last time entire file was compiled resolvedMember = resolvedMember.DeclaringType; currentType = resolvedMember.DeclaringType; Scope scope = this.scopeFor[resolvedMember.UniqueKey] as Scope; if (scope != null) this.scopeFor[unresolvedMember.UniqueKey] = scope; looker.scope = scope; }else if (resolvedMember.DeclaringType != null){ unresolvedMember.DeclaringType = resolvedMember.DeclaringType; looker.scope = this.scopeFor[resolvedMember.DeclaringType.UniqueKey] as Scope; if (looker.scope == null && resolvedMember.DeclaringType.IsDefinedBy != null && resolvedMember.DeclaringType.IsDefinedBy.Count > 0) looker.scope = this.GetScopeFromPartialType(resolvedMember.DeclaringType, resolvedMember); Scope scope = this.scopeFor[resolvedMember.UniqueKey] as Scope; if (scope != null) this.scopeFor[unresolvedMember.UniqueKey] = scope; }else if (resolvedMember.DeclaringNamespace != null){ unresolvedMember.DeclaringNamespace = resolvedMember.DeclaringNamespace; looker.scope = this.scopeFor[resolvedMember.DeclaringNamespace.UniqueKey] as Scope; Scope scope = this.scopeFor[resolvedMember.UniqueKey] as Scope; if (scope != null) this.scopeFor[unresolvedMember.UniqueKey] = scope; } if (looker.scope == null) return; looker.currentType = currentType; looker.identifierInfos = this.identifierInfos = new NodeList(); looker.identifierPositions = this.identifierPositions = new Int32List(); looker.identifierLengths = this.identifierLengths = new Int32List(); looker.identifierContexts = this.identifierContexts = new Int32List(); looker.identifierScopes = this.identifierScopes = new ScopeList(); looker.allScopes = this.allScopes = new ScopeList(); looker.Visit(unresolvedMember); //Walk IR inferring types and resolving overloads Resolver resolver = new Resolver(errorHandler, new TypeSystem(errorHandler)); resolver.currentAssembly = (resolver.currentModule = this.currentSymbolTable) as AssemblyNode; resolver.currentType = currentType; if (currentType != null){ if (resolver.currentType.Template == null && resolver.currentType.ConsolidatedTemplateParameters != null && resolver.currentType.ConsolidatedTemplateParameters.Count > 0) resolver.currentTypeInstance = resolver.GetDummyInstance(resolver.currentType); else resolver.currentTypeInstance = resolver.currentType; } resolver.Visit(unresolvedMember); }
public override void Resolve(CompilationUnit partialCompilationUnit){ if (partialCompilationUnit == null){Debug.Assert(false); return;} TrivialHashtable scopeFor = new TrivialHashtable(); Scoper scoper = new Scoper(scopeFor); scoper.currentModule = this.currentSymbolTable; scoper.VisitCompilationUnit(partialCompilationUnit); ErrorHandler errorHandler = new ErrorHandler(new ErrorNodeList(0)); TrivialHashtable ambiguousTypes = new TrivialHashtable(); TrivialHashtable referencedLabels = new TrivialHashtable(); Looker looker = new Looker(null, errorHandler, scopeFor, ambiguousTypes, referencedLabels); looker.currentAssembly = (looker.currentModule = this.currentSymbolTable) as AssemblyNode; looker.identifierInfos = this.identifierInfos = new NodeList(); looker.identifierPositions = this.identifierPositions = new Int32List(); looker.identifierLengths = this.identifierLengths = new Int32List(); looker.identifierContexts = this.identifierContexts = new Int32List(); looker.identifierScopes = this.identifierScopes = new ScopeList(); looker.allScopes = this.allScopes = new ScopeList(); looker.VisitCompilationUnit(partialCompilationUnit); //Walk IR inferring types and resolving overloads Resolver resolver = new Resolver(errorHandler, new TypeSystem(errorHandler)); resolver.currentAssembly = (resolver.currentModule = this.currentSymbolTable) as AssemblyNode; resolver.Visit(partialCompilationUnit); }
public override Cci.AuthoringScope GetAuthoringScopeForMethodBody(string text, Compilation/*!*/ compilation, Method/*!*/ method, AuthoringSink asink) { this.parsingStatement = true; if (text == null || compilation == null || method == null || method.Body == null || method.Body.SourceContext.Document == null) throw new ArgumentNullException(); if (compilation != null && compilation.CompilerParameters is SpecSharpCompilerOptions) this.allowSpecSharpExtensions = !((SpecSharpCompilerOptions)compilation.CompilerParameters).Compatibility; this.currentSymbolTable = compilation.TargetModule; SourceContext sctx = method.Body.SourceContext; DocumentText docText = new DocumentText(text); Document doc = Compiler.CreateSpecSharpDocument(sctx.Document.Name, 1, docText); ErrorNodeList errors = new ErrorNodeList(0); Parser p = new Parser(doc, errors, compilation.TargetModule, compilation.CompilerParameters as SpecSharpCompilerOptions); p.ParseMethodBody(method, sctx.StartPos, asink); ErrorHandler errorHandler = new ErrorHandler(errors); TrivialHashtable ambiguousTypes = new TrivialHashtable(); TrivialHashtable referencedLabels = new TrivialHashtable(); Looker looker = new Looker(null, errorHandler, this.scopeFor, ambiguousTypes, referencedLabels); looker.currentAssembly = (looker.currentModule = compilation.TargetModule) as AssemblyNode; TypeNode currentType = method.DeclaringType; looker.currentType = currentType; looker.scope = method.Scope; if (looker.scope != null) looker.scope = looker.scope.OuterScope; looker.identifierInfos = this.identifierInfos = new NodeList(); looker.identifierPositions = this.identifierPositions = new Int32List(); looker.identifierLengths = this.identifierLengths = new Int32List(); looker.identifierContexts = this.identifierContexts = new Int32List(); looker.identifierScopes = this.identifierScopes = new ScopeList(); looker.allScopes = this.allScopes = new ScopeList(); looker.Visit(method); Resolver resolver = new Resolver(errorHandler, new TypeSystem(errorHandler)); resolver.currentAssembly = (resolver.currentModule = this.currentSymbolTable) as AssemblyNode; resolver.currentType = currentType; if (currentType != null) { if (resolver.currentType.Template == null && resolver.currentType.ConsolidatedTemplateParameters != null && resolver.currentType.ConsolidatedTemplateParameters.Count > 0) resolver.currentTypeInstance = resolver.GetDummyInstance(resolver.currentType); else resolver.currentTypeInstance = resolver.currentType; } resolver.Visit(method); method.Body.Statements = null; return this.GetAuthoringScope(); }