Пример #1
0
    // OnStateEnter is called when a transition starts and the state machine starts to evaluate this state
    override public void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
    {
        gV            = animator.GetComponent <globalVars>();
        looker        = gV.interactionCanvas.GetComponent <Looker>();
        roboBehaviour = animator.GetComponent <RoboBehaviour>();

        gV.feedback = true;

        animator.ResetTrigger("originReached");
        animator.ResetTrigger("statesCorrect");
        animator.ResetTrigger("targetReached");
        animator.ResetTrigger("noHelpNeeded");
        animator.ResetTrigger("finished");
        animator.ResetTrigger("feedback");
        animator.ResetTrigger("unhappy");
        animator.ResetTrigger("findObject");

        looker.StartFeedbackDialog();

        float      happyValue = 1f;
        SeeEmotion seeEmotion = roboBehaviour.GetGazedBy().GetComponentInParent <SeeEmotion>();

        if (seeEmotion != null)
        {
            seeEmotion.emotions.TryGetValue(Emotion.Happy, out happyValue);
            if (happyValue < gV.happyThreshold)
            {
                gV.asked    = false;
                gV.feedback = false;
            }
        }
        animator.SetTrigger("finished");
    }
Пример #2
0
 public void Initialize(Controls controls)
 {
     // Set controls
     Controls = controls;
     // Set state
     State = controls.State;
     // Set transform
     Transform = controls.Transform;
     // Set animator
     Animator = controls.Animator;
     // Set owner
     Owner = controls.Owner;
     // Set looker
     Looker = controls.Looker;
     // Execute intialize
     Initialize();
 }
Пример #3
0
        public override void OnInitialized()
        {
            character = worlditem.Get <Character> ();
            character.OnCollectiveThoughtStart += OnCollectiveThoughtStart;
            character.State.GlobalReputation    = 1;

            damageable = worlditem.Get <Damageable> ();
            damageable.OnTakeDamage += OnTakeDamage;
            damageable.OnDie        += OnDie;

            //this script won't get added by default
            looker = worlditem.GetOrAdd <Looker> ();
            looker.State.ItemsOfInterest.SafeAdd("Creature");
            looker.State.ItemsOfInterest.SafeAdd("Character");
            looker.State.VisibleTypesOfInterest |= ItemOfInterestType.WorldItem;
            looker.State.VisibleTypesOfInterest |= ItemOfInterestType.Player;
            Listener listener = worlditem.GetOrAdd <Listener> ();
        }
Пример #4
0
    // Update is called once per frame
    void Update()
    {
        Looker.LookAt(UnRe);
        if (Looker.localEulerAngles.y >= Minus && Looker.localEulerAngles.y <= Plus)
        {
            Door.localEulerAngles = new Vector3(0, Looker.localEulerAngles.y, 0);
        }
        else
        {
            if (Looker.localEulerAngles.y < Minus)
            {
                Door.localEulerAngles = new Vector3(0, Minus, 0);
            }
            if (Looker.localEulerAngles.y > Plus)
            {
                Door.localEulerAngles = new Vector3(0, Plus, 0);
            }
        }



        if (B_l)
        {
        }
        else    //здесь мы шевелим ручку
        //lastBool = true;
        {
            if (lastB_l)
            {
                t = Time.time;
                curvaX.MoveKey(0, new Keyframe(0, UnRe.localPosition.x));
                curvaY.MoveKey(0, new Keyframe(0, UnRe.localPosition.y));
                curvaZ.MoveKey(0, new Keyframe(0, UnRe.localPosition.z));
                //curvaX.keys[0].value = UnRu4ka.localPosition.x;
                //curvaY.keys[0].value = UnRu4ka.localPosition.y;
                //curvaZ.keys[0].value = UnRu4ka.localPosition.z;
                lastB_l = false;
            }
            UnRe.localPosition = new Vector3(curvaX.Evaluate(Time.time - t), curvaY.Evaluate(Time.time - t), curvaZ.Evaluate(Time.time - t));
        }
        B_l = false;
    }
Пример #5
0
    // OnStateEnter is called when a transition starts and the state machine starts to evaluate this state
    override public void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
    {
        gV     = animator.GetComponent <globalVars>();
        agent  = animator.GetComponent <NavMeshAgent>();
        looker = gV.interactionCanvas.GetComponent <Looker>();

        animator.ResetTrigger("originReached");
        animator.ResetTrigger("statesCorrect");
        animator.ResetTrigger("targetReached");
        animator.ResetTrigger("noHelpNeeded");
        animator.ResetTrigger("finished");
        animator.ResetTrigger("feedback");
        animator.ResetTrigger("unhappy");
        animator.ResetTrigger("findObject");

        gV.helpPanel.SetActive(true);
        gV.feedbackPanel.SetActive(false);
        gV.searchingObjPanel.SetActive(false);

        waitingForSecs = 0f;

        looker.StartHelpDialog();
    }
Пример #6
0
    // OnStateEnter is called when a transition starts and the state machine starts to evaluate this state
    override public void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
    {
        gV     = animator.GetComponent <globalVars>();
        looker = gV.interactionCanvas.GetComponent <Looker>();;

        animator.ResetTrigger("originReached");
        animator.ResetTrigger("statesCorrect");
        animator.ResetTrigger("targetReached");
        animator.ResetTrigger("noHelpNeeded");
        animator.ResetTrigger("finished");
        animator.ResetTrigger("feedback");
        animator.ResetTrigger("unhappy");
        animator.ResetTrigger("findObject");

        gV.interactionCanvas.gameObject.SetActive(true);

        gV.helpPanel.SetActive(false);
        gV.searchingObjPanel.SetActive(false);
        gV.feedbackPanel.SetActive(false);

        //Emotion Check fehlt noch
        if (!gV.asked)
        {
            animator.SetTrigger("unhappy");
        }
        else if (gV.asked && !gV.feedback)
        {
            looker.StartArrivalDialog();
            animator.SetTrigger("feedback");
        }
        else if (gV.asked && gV.feedback)
        {
            animator.SetTrigger("noHelpNeeded");
            gV.destination = gV.roboOrigin;
        }
    }
Пример #7
0
 public override MemberList GetTypesNamespacesAndPrefixes(Scope scope, bool constructorMustBeVisible, bool listAllUnderRootNamespace) {
   MemberList result = new MemberList();
   while (scope != null && !(scope is TypeScope || scope is NamespaceScope)) scope = scope.OuterScope;
   if (scope == null) return result;
   TypeNode currentType = scope is TypeScope ? ((TypeScope)scope).Type : null;
   if (!(scope is NamespaceScope) && (currentType == null || currentType.DeclaringModule == null)) return result;
   ErrorHandler errorHandler = new ErrorHandler(new ErrorNodeList(0));
   TrivialHashtable ambiguousTypes = new TrivialHashtable();
   TrivialHashtable referencedLabels = new TrivialHashtable();
   Looker looker = new Looker(null, errorHandler, null, ambiguousTypes, referencedLabels);
   looker.currentType = currentType;
   looker.currentModule = this.currentSymbolTable;
   looker.currentAssembly = looker.currentModule as AssemblyNode;
   result = looker.GetVisibleTypesNamespacesAndPrefixes(scope, constructorMustBeVisible, listAllUnderRootNamespace);
   return result;
 }
Пример #8
0
 void Start()
 {
     looker = GetComponentInChildren <Looker>();
 }
Пример #9
0
    public virtual void ConstructSymbolTable(Compilation compilation, ErrorNodeList errors, TrivialHashtable scopeFor){
      if (compilation == null || scopeFor == null){Debug.Assert(false); return;}
      this.CurrentCompilation = compilation;
      Module symbolTable = compilation.TargetModule = this.CreateModule(compilation.CompilerParameters, errors, compilation);
      Scoper scoper = new Scoper(scopeFor);
      scoper.currentModule = symbolTable;
      ErrorHandler errorHandler = new ErrorHandler(errors);
      Looker looker = new Looker(this.GetGlobalScope(symbolTable), errorHandler, scopeFor);
      // begin change by drunje
      SpecSharpCompilerOptions options = compilation.CompilerParameters as SpecSharpCompilerOptions;
      if (options != null)
        looker.AllowPointersToManagedStructures = options.AllowPointersToManagedStructures;
      // end change by drunje
      looker.currentAssembly = (looker.currentModule = symbolTable) as AssemblyNode;
      looker.ignoreMethodBodies = true;
      Scope globalScope = compilation.GlobalScope = this.GetGlobalScope(symbolTable);

      CompilationUnitList sources = compilation.CompilationUnits;
      if (sources == null) return;
      int n = sources.Count;
      for (int i = 0; i < n; i++){
        CompilationUnitSnippet compilationUnitSnippet = sources[i] as CompilationUnitSnippet;
        if (compilationUnitSnippet == null){Debug.Assert(false); continue;}
        compilationUnitSnippet.ChangedMethod = null;
        Document doc = compilationUnitSnippet.SourceContext.Document;
        if (doc == null || doc.Text == null){Debug.Assert(false); continue;}
        IParserFactory factory = compilationUnitSnippet.ParserFactory;
        if (factory == null){Debug.Assert(false); return;}
        IParser p = factory.CreateParser(doc.Name, doc.LineNumber, doc.Text, symbolTable, errors, compilation.CompilerParameters);
        if (p is ResgenCompilerStub) continue;
        if (p == null){Debug.Assert(false); continue;}
        Parser specSharpParser = p as Parser;
        if (specSharpParser == null)
          p.ParseCompilationUnit(compilationUnitSnippet);
        else
          specSharpParser.ParseCompilationUnit(compilationUnitSnippet, true, false);
        //TODO: this following is a good idea only if the files will not be frequently reparsed from source
        //StringSourceText stringSourceText = doc.Text.TextProvider as StringSourceText;
        //if (stringSourceText != null && stringSourceText.IsSameAsFileContents)
        //  doc.Text.TextProvider = new CollectibleSourceText(doc.Name, doc.Text.Length);
        //else if (doc.Text.TextProvider != null)
        //  doc.Text.TextProvider.MakeCollectible();
      }
      CompilationUnitList compilationUnits = new CompilationUnitList();
      for (int i = 0; i < n; i++){
        CompilationUnit cUnit = sources[i];
        compilationUnits.Add(scoper.VisitCompilationUnit(cUnit));
      }
      for (int i = 0; i < n; i++){
        CompilationUnit cUnit = compilationUnits[i];
        if (cUnit == null) continue;
        looker.VisitCompilationUnit(cUnit);
      }
      //Run resolver over symbol table so that custom attributes on member signatures are known and can be used
      //to error check the the given file.
      TypeSystem typeSystem = new TypeSystem(errorHandler);
      Resolver resolver = new Resolver(errorHandler, typeSystem);
      resolver.currentAssembly = (resolver.currentModule = symbolTable) as AssemblyNode;
      for (int i = 0; i < n; i++) {
        CompilationUnit cUnit = compilationUnits[i];
        if (cUnit == null) continue;
        resolver.VisitCompilationUnit(cUnit);
      }
      this.CurrentCompilation = null;
    }
Пример #10
0
 public override MemberList GetNamespacesAndAttributeTypes(Scope scope){
   MemberList result = new MemberList();
   while (scope != null && !(scope is TypeScope) && !(scope is NamespaceScope)) scope = scope.OuterScope;
   if (scope == null) return result;
   TypeNode currentType = scope is TypeScope ? ((TypeScope)scope).Type : null;
   ErrorHandler errorHandler = new ErrorHandler(new ErrorNodeList(0));
   TrivialHashtable ambiguousTypes = new TrivialHashtable();
   TrivialHashtable referencedLabels = new TrivialHashtable();
   Looker looker = new Looker(null, errorHandler, null, ambiguousTypes, referencedLabels);
   looker.currentType = currentType;
   looker.currentModule = this.currentSymbolTable;
   if (looker.currentModule == null) return result;
   return looker.GetNamespacesAndAttributeTypes(scope);
 }
Пример #11
0
        public void ResolveIR(Compilation compilation, ErrorNodeList errorNodes)
        {
            TrivialHashtable ambiguousTypes = new TrivialHashtable();
            TrivialHashtable scopeFor = new TrivialHashtable();
            TrivialHashtable referencedLabels = new TrivialHashtable();
            Hashtable exceptionNames = new Hashtable();
            ErrorHandler errorHandler = new ErrorHandler(errorNodes);
            string target = "";
            ZingCompilerOptions zoptions = compilation.CompilerParameters as ZingCompilerOptions;
            if (zoptions != null && zoptions.DumpSource)
            {
                target = compilation.CompilerParameters.OutputAssembly;
                if (string.IsNullOrEmpty(target))
                {
                    target = Directory.GetCurrentDirectory() + Path.DirectorySeparatorChar;
                }
                string output = Path.GetDirectoryName(target);
                if (string.IsNullOrEmpty(output)) output = Directory.GetCurrentDirectory();
                target = Path.GetFileNameWithoutExtension(target);
            }

            if (this.Options == null)
                this.Options = compilation.CompilerParameters;

            //Attach scopes to namespaces and types so that forward references to base types can be looked up in the appropriate namespace scope
            Scoper scoper = new Scoper(scopeFor);
            scoper.VisitCompilation(compilation);

            //Walk IR looking up names
            TypeSystem typeSystem = new TypeSystem(errorHandler);
            Looker looker = new Looker(compilation.GlobalScope, errorHandler, scopeFor, typeSystem, // LJW: added typeSystem
                ambiguousTypes, referencedLabels, exceptionNames);
            looker.VisitCompilation(compilation);

            //Walk IR inferring types and resolving overloads
            Resolver resolver = new Resolver(errorHandler, typeSystem);
            resolver.VisitCompilation(compilation);

            Checker checker = new Checker(errorHandler, typeSystem, scopeFor, ambiguousTypes, referencedLabels); // LJW: added scopeFor
            checker.VisitCompilation(compilation);
        }
Пример #12
0
        /// <summary>
        /// Parses all of the CompilationUnitSnippets in the given compilation, ignoring method bodies. Then resolves all type expressions.
        /// The resulting types can be retrieved from the module in compilation.TargetModule. The base types, interfaces and
        /// member signatures will all be resolved and on an equal footing with imported, already compiled modules and assemblies.
        /// </summary>
        public override void ConstructSymbolTable(Compilation compilation, ErrorNodeList errors)
        {
            if (compilation == null) { Debug.Assert(false); return; }
            Module symbolTable = compilation.TargetModule = this.CreateModule(compilation.CompilerParameters, errors, compilation);
            TrivialHashtable scopeFor = new TrivialHashtable();
            Scoper scoper = new Scoper(scopeFor);
            scoper.currentModule = symbolTable;
            ErrorHandler errorHandler = new ErrorHandler(errors);
            TypeSystem typeSystem = new TypeSystem(errorHandler); // LJW: added typeSystem
            Looker looker = new Looker(this.GetGlobalScope(symbolTable), errorHandler, scopeFor, typeSystem);
            looker.currentAssembly = (looker.currentModule = symbolTable) as AssemblyNode;
            looker.ignoreMethodBodies = true;
            compilation.GlobalScope = this.GetGlobalScope(symbolTable);

            CompilationUnitList sources = compilation.CompilationUnits;
            if (sources == null) { Debug.Assert(false); return; }
            int n = sources.Count;
            for (int i = 0; i < n; i++)
            {
                CompilationUnitSnippet compilationUnitSnippet = sources[i] as CompilationUnitSnippet;
                if (compilationUnitSnippet == null) { Debug.Assert(false); continue; }
                compilationUnitSnippet.ChangedMethod = null;
                Document doc = compilationUnitSnippet.SourceContext.Document;
                if (doc == null || doc.Text == null) { Debug.Assert(false); continue; }
                IParserFactory factory = compilationUnitSnippet.ParserFactory;
                if (factory == null) { Debug.Assert(false); return; }
                IParser p = factory.CreateParser(doc.Name, doc.LineNumber, doc.Text, symbolTable, errors, compilation.CompilerParameters);
                if (p is ResgenCompilerStub) continue;
                if (p == null) { Debug.Assert(false); continue; }
                Parser zingParser = p as Parser;
                if (zingParser == null)
                    p.ParseCompilationUnit(compilationUnitSnippet);
                else
                    zingParser.ParseCompilationUnit(compilationUnitSnippet, true, true, null);
                StringSourceText stringSourceText = doc.Text.TextProvider as StringSourceText;
                if (stringSourceText != null && stringSourceText.IsSameAsFileContents)
                    doc.Text.TextProvider = new CollectibleSourceText(doc.Name, doc.Text.Length);
                else if (doc.Text.TextProvider != null)
                    doc.Text.TextProvider.MakeCollectible();
            }
            CompilationUnitList compilationUnits = new CompilationUnitList();
            for (int i = 0; i < n; i++)
            {
                CompilationUnit cUnit = sources[i];
                compilationUnits.Add(scoper.VisitCompilationUnit(cUnit));
            }
            for (int i = 0; i < n; i++)
            {
                CompilationUnit cUnit = compilationUnits[i];
                if (cUnit == null) continue;
                looker.VisitCompilationUnit(cUnit);
            }
        }
Пример #13
0
        public override void CompileParseTree(Compilation compilation, ErrorNodeList errorNodes)
        {
            TrivialHashtable ambiguousTypes = new TrivialHashtable();
            TrivialHashtable scopeFor = new TrivialHashtable();
            TrivialHashtable referencedLabels = new TrivialHashtable();
            Hashtable exceptionNames = new Hashtable();
            ErrorHandler errorHandler = new ErrorHandler(errorNodes);
            string target = "";
            ZingCompilerOptions zoptions = compilation.CompilerParameters as ZingCompilerOptions;
            if (zoptions != null && zoptions.DumpSource)
            {
                target = compilation.CompilerParameters.OutputAssembly;
                if (string.IsNullOrEmpty(target))
                {
                    target = Directory.GetCurrentDirectory() + Path.DirectorySeparatorChar;
                }
                string output = Path.GetDirectoryName(target);
                if (string.IsNullOrEmpty(output)) output = Directory.GetCurrentDirectory();
                target = Path.GetFileNameWithoutExtension(target);
            }

            if (this.Options == null)
                this.Options = compilation.CompilerParameters;

            //Attach scopes to namespaces and types so that forward references to base types can be looked up in the appropriate namespace scope
            Scoper scoper = new Scoper(scopeFor);
            scoper.VisitCompilation(compilation);

            //Walk IR looking up names
            TypeSystem typeSystem = new TypeSystem(errorHandler);
            Looker looker = new Looker(compilation.GlobalScope, errorHandler, scopeFor, typeSystem, // LJW: added typeSystem
                ambiguousTypes, referencedLabels, exceptionNames);
            looker.VisitCompilation(compilation);

            //Walk IR inferring types and resolving overloads
            Resolver resolver = new Resolver(errorHandler, typeSystem);
            resolver.VisitCompilation(compilation);

            Checker checker = new Checker(errorHandler, typeSystem, scopeFor, ambiguousTypes, referencedLabels); // LJW: added scopeFor
            checker.VisitCompilation(compilation);

            // Walk the Zing IR splicing it into our code-gen templates
            Splicer splicer = new Splicer(this.Options, referencedLabels, exceptionNames);
            CompilationUnit cuMerged = splicer.CodeGen(compilation);

            //
            // If the 'dumpSource' option is given, then we decompile the IR to C# and write this
            // to a file.
            //
            if (zoptions != null && zoptions.DumpSource)
            {
                // Once the codegen is done and we have the IR for the generated code, we use the
                // decompiler to get C# back out, and hand this to the standard compiler. Later,
                // we'll replace this with the X# normalizer and avoid going in and out of source
                // code (except for compiler debugging).
                string tempSrc;
                string tempName = compilation.CompilerParameters.OutputAssembly + ".cs";
                Decompiler decompiler = new Decompiler();
                tempSrc = decompiler.Decompile(cuMerged);

                StreamWriter sw = File.CreateText(tempName);
                sw.Write(tempSrc);
                sw.Close();
            }

            if (zoptions != null && zoptions.DumpLabels)
            {
                string tempName = compilation.CompilerParameters.OutputAssembly + ".labels";
                StreamWriter sw = File.CreateText(tempName);
                sw.Write(splicer.LabelString);
                sw.Close();
            }

            for (int i = 0; i < RequiredTypes.Length; i++)
            {
                R.Assembly asm = R.Assembly.GetAssembly(RequiredTypes[i]);
                if (!compilation.CompilerParameters.ReferencedAssemblies.Contains(asm.Location))
                    compilation.CompilerParameters.ReferencedAssemblies.Add(asm.Location);
            }

            // The if-statement added by Jiri Adamek
            // It loads a native ZOM assembly if used
            if (zoptions != null && zoptions.ZomAssemblyName != null)
            {
                compilation.CompilerParameters.ReferencedAssemblies.Add(zoptions.ZomAssemblyName);
            }

            CS.Compiler csCompiler = new CS.Compiler();

            // We have to create a new module to pull in references from the
            // assemblies we just added above.
            compilation.TargetModule = this.targetModule =
                csCompiler.CreateModule(compilation.CompilerParameters, errorNodes);

            // Our one top-level type must be added to the module's type list
            compilation.TargetModule.Types.Add(((Namespace)cuMerged.Nodes[0]).NestedNamespaces[0].Types[0]);

            // The restorer patches the DeclaringModule field of our types
            Restorer restorer = new Restorer(compilation.TargetModule);
            restorer.VisitCompilationUnit(cuMerged);

            // Replace the Zing compilation unit with our generated code before invoking
            // the Spec# back end.
            compilation.CompilationUnits = new CompilationUnitList(cuMerged);

            foreach (CompilationUnit cunit in compilation.CompilationUnits)
                cunit.Compilation = compilation;

            // For retail builds, disable the time-consuming definite-assignment checks
            // in the Spec# compiler.
            if (!this.Options.IncludeDebugInformation)
                compilation.CompilationUnits[0].PreprocessorDefinedSymbols["NODEFASSIGN"] = "true";

            // Let the Spec# back end process the IR from here
            csCompiler.CompileParseTree(compilation, errorNodes);
        }
Пример #14
0
 private void Start()
 {
     _walker             = GetComponent <Walker>();
     _looker             = GetComponent <Looker>();
     _pathRequestManager = FindObjectOfType <GameManager>().GetPathRequestManager();
 }
Пример #15
0
    public override void CompileParseTree(Compilation compilation, ErrorNodeList errorNodes){
      if (compilation == null || compilation.CompilationUnits == null || compilation.TargetModule == null){Debug.Assert(false); return;}
      if (compilation.CompilationUnits.Count == 0) return;
      TrivialHashtable ambiguousTypes = new TrivialHashtable();
      TrivialHashtable referencedLabels = new TrivialHashtable();
      TrivialHashtable scopeFor = new TrivialHashtable(64);
      ErrorHandler errorHandler = new ErrorHandler(errorNodes);
      SpecSharpCompilation ssCompilation = new SpecSharpCompilation();
      SpecSharpCompilerOptions options = (SpecSharpCompilerOptions)compilation.CompilerParameters;

      //Attach scopes to namespaces and types so that forward references to base types can be looked up in the appropriate namespace scope
      Scoper scoper = new Scoper(scopeFor);
      scoper.VisitCompilation(compilation);
      scoper = null;

      if (options.NoStandardLibrary && compilation.TargetModule is AssemblyNode) {
        if (compilation.TargetModule.IsValidTypeName(StandardIds.System, StandardIds.CapitalObject)) {
          SystemAssemblyLocation.ParsedAssembly = (AssemblyNode)compilation.TargetModule;
          SystemCompilerRuntimeAssemblyLocation.ParsedAssembly = (AssemblyNode)compilation.TargetModule; //So that mscorlib can have contracts but no reference to another assembly
        } else if (compilation.TargetModule.IsValidTypeName(Identifier.For("System.Compiler"), Identifier.For("ComposerAttribute")))
          SystemCompilerRuntimeAssemblyLocation.ParsedAssembly = (AssemblyNode)compilation.TargetModule;
        else if (compilation.TargetModule.IsValidTypeName(Identifier.For("Microsoft.SpecSharp"), Identifier.For("dummy")))
          RuntimeAssemblyLocation.ParsedAssembly = (AssemblyNode)compilation.TargetModule;
      }
      object ObjectType = SystemTypes.Object;
      if (ObjectType == null) return; //system types did not initialize

      //Walk IR looking up names
      Looker looker = new Looker(compilation.GlobalScope, errorHandler, scopeFor, ambiguousTypes, referencedLabels);
      if (options != null && options.EmitSourceContextsOnly)
      {
        looker.DontInjectDefaultConstructors = true;
      }

      // begin change by drunje
      looker.AllowPointersToManagedStructures = options.AllowPointersToManagedStructures;
      // end change by drunje
      looker.VisitCompilation(compilation);
      looker = null;

      if (options != null && options.EmitSourceContextsOnly) return; // stop after looker to have resolved types

      //Walk IR inferring types and resolving overloads
      TypeSystem typeSystem = new TypeSystem(errorHandler);
      Resolver resolver = new Resolver(errorHandler, typeSystem);
      resolver.VisitCompilation(compilation);
      resolver = null;

      //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);
      checker.VisitCompilation(compilation);
      checker = null;
      scopeFor = null;
      ambiguousTypes = null;
      referencedLabels = null;

      if (!options.IsContractAssembly) {
        if (options.RunProgramVerifier)
          ssCompilation.AddProgramVerifierPlugin(typeSystem, compilation);

        //Allow third party extensions to analyze AST IR for further errors
        ssCompilation.RunPlugins(compilation, errorHandler);
      }

      //Walk IR reducing it to nodes that have predefined mappings to MD+IL
      Normalizer normalizer = new Normalizer(typeSystem);
      normalizer.VisitCompilation(compilation);
      normalizer = null;

      if (options.IsContractAssembly) return;
      //Walk normalized IR instrumenting accesses of fields of guarded classes with checks
      CompilationUnit cu = compilation.CompilationUnits[0];
      if (cu != null && cu.PreprocessorDefinedSymbols != null && cu.PreprocessorDefinedSymbols.ContainsKey("GuardedFieldAccessChecks")){
        if (errorNodes.Count == 0){
          GuardedFieldAccessInstrumenter instrumenter = new GuardedFieldAccessInstrumenter();
          instrumenter.VisitCompilation(compilation);
          instrumenter = null;
        }
      }

      //Walk normalized IR doing code analysis
      Analyzer analyzer = new Analyzer(typeSystem, compilation);
      analyzer.Visit(compilation);

      //Allow third party extensions to analyze normalized IR for further errors
      ssCompilation.analyzer = analyzer; // make the analyzer available to plugins for access to method CFGs
      ssCompilation.RunPlugins(compilation, errorHandler);
      ssCompilation.analyzer = null;
      ssCompilation = null;
      analyzer = null;
      errorHandler = null;

      //Walk IR to optimize code further after analyses were performed, eg. to remove debug only code
      Optimizer optimizer = new Optimizer();
      optimizer.Visit(compilation);
      optimizer = null;
    }
Пример #16
0
    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;
    }
Пример #17
0
 public override MemberList GetVisibleNames(Scope scope){
   MemberList result = new MemberList();
   if (scope == null) return result;
   Scope sc = scope;
   if (sc is MethodScope) return this.GetTypesNamespacesAndPrefixes(scope, false, false); //inside a parameter list.
   while (sc is BlockScope) sc = sc.OuterScope;
   MethodScope mscope = sc as MethodScope;
   while (sc != null && !(sc is TypeScope || sc is NamespaceScope)) sc = sc.OuterScope;
   TypeNode currentType = sc is TypeScope ? ((TypeScope)sc).Type : null;
   ErrorHandler errorHandler = new ErrorHandler(new ErrorNodeList(0));
   TrivialHashtable ambiguousTypes = new TrivialHashtable();
   TrivialHashtable referencedLabels = new TrivialHashtable();
   Looker looker = new Looker(null, errorHandler, null, ambiguousTypes, referencedLabels);
   if (mscope != null) looker.currentMethod = mscope.DeclaringMethod;
   looker.currentType = currentType;
   looker.currentModule = this.currentSymbolTable;
   looker.currentAssembly = looker.currentModule as AssemblyNode;
   return looker.GetVisibleNames(scope);
 }
Пример #18
0
 public virtual void ResolveSymbolTable(Compilation/*!*/ parsedCompilation, ErrorNodeList/*!*/ errors, out TrivialHashtable scopeFor){
   scopeFor = new TrivialHashtable();
   if (parsedCompilation == null) { Debug.Assert(false); return; }
   if (errors == null){Debug.Assert(false); return;}
   Scoper scoper = new Scoper(scopeFor);
   scoper.currentModule = parsedCompilation.TargetModule;
   scoper.VisitCompilation(parsedCompilation);
   ErrorHandler errorHandler = new ErrorHandler(errors);
   TrivialHashtable ambiguousTypes = new TrivialHashtable();
   TrivialHashtable referencedLabels = new TrivialHashtable();
   Looker looker = new Looker(null, errorHandler, scopeFor, ambiguousTypes, referencedLabels);
   // begin change by drunje
   SpecSharpCompilerOptions options = parsedCompilation.CompilerParameters as SpecSharpCompilerOptions;
   if (options != null)
     looker.AllowPointersToManagedStructures = options.AllowPointersToManagedStructures;
   // end change by drunje
   looker.currentAssembly = (looker.currentModule = parsedCompilation.TargetModule) as AssemblyNode;
   looker.VisitCompilation(parsedCompilation);
 }
Пример #19
0
 public override MemberList GetNestedNamespacesAndTypes(Identifier name, Scope scope, AssemblyReferenceList assembliesToSearch){
   MemberList result = new MemberList();
   ErrorHandler errorHandler = new ErrorHandler(new ErrorNodeList(0));
   TrivialHashtable scopeFor = new TrivialHashtable();
   TrivialHashtable factoryMap = new TrivialHashtable();
   TrivialHashtable ambiguousTypes = new TrivialHashtable();
   TrivialHashtable referencedLabels = new TrivialHashtable();
   Looker looker = new Looker(null, errorHandler, null, ambiguousTypes, referencedLabels);
   looker.currentModule = this.currentSymbolTable;
   return looker.GetNestedNamespacesAndTypes(name, scope, assembliesToSearch);
 }
Пример #20
0
 private void Awake()
 {
     _steer  = new Steer(_directions_count);
     _walker = GetComponent <Walker>();
     _looker = GetComponent <Looker>();
 }
Пример #21
0
    public override void ParseAndAnalyzeCompilationUnit(string fname, string text, int line, int col, ErrorNodeList errors, Compilation compilation, AuthoringSink sink) {
      if (fname == null || text == null || errors == null || compilation == null){Debug.Assert(false); return;}
      if (compilation != null && compilation.CompilerParameters is SpecSharpCompilerOptions)
        this.allowSpecSharpExtensions = !((SpecSharpCompilerOptions)compilation.CompilerParameters).Compatibility;
      CompilationUnitList compilationUnitSnippets = compilation.CompilationUnits;
      if (compilationUnitSnippets == null){Debug.Assert(false); return;}
      //Fix up the CompilationUnitSnippet corresponding to fname with the new source text
      CompilationUnitSnippet cuSnippet = this.GetCompilationUnitSnippet(compilation, fname);
      if (cuSnippet == null) return;
      Compiler compiler = new Compiler();
      compiler.CurrentCompilation = compilation;
      cuSnippet.SourceContext.Document = compiler.CreateDocument(fname, 1, new DocumentText(text));
      cuSnippet.SourceContext.EndPos = text.Length;
      //Parse all of the compilation unit snippets
      Module symbolTable = compilation.TargetModule = compiler.CreateModule(compilation.CompilerParameters, errors);
      AttributeList assemblyAttributes = symbolTable is AssemblyNode ? symbolTable.Attributes : null;
      AttributeList moduleAttributes = symbolTable is AssemblyNode ? ((AssemblyNode)symbolTable).ModuleAttributes : symbolTable.Attributes;
      int n = compilationUnitSnippets.Count;
      for (int i = 0; i < n; i++){
        CompilationUnitSnippet compilationUnitSnippet = compilationUnitSnippets[i] as CompilationUnitSnippet;
        if (compilationUnitSnippet == null){Debug.Assert(false); continue;}
        Document doc = compilationUnitSnippet.SourceContext.Document;
        doc = compilationUnitSnippet.SourceContext.Document;
        if (doc == null || doc.Text == null){Debug.Assert(false); continue;}
        IParserFactory factory = compilationUnitSnippet.ParserFactory;
        if (factory == null) continue;
        compilationUnitSnippet.Nodes = null;
        compilationUnitSnippet.PreprocessorDefinedSymbols = null;
        IParser p = factory.CreateParser(doc.Name, doc.LineNumber, doc.Text, symbolTable, compilationUnitSnippet == cuSnippet ? errors : new ErrorNodeList(), compilation.CompilerParameters);
        if (p == null){Debug.Assert(false); continue;}
        if (p is ResgenCompilerStub) continue;
        Parser specSharpParser = p as Parser;
        if (specSharpParser == null)
          p.ParseCompilationUnit(compilationUnitSnippet);
        else
          specSharpParser.ParseCompilationUnit(compilationUnitSnippet, compilationUnitSnippet != cuSnippet, false);
        //TODO: this following is a good idea only if the files will not be frequently reparsed from source
        //StringSourceText stringSourceText = doc.Text.TextProvider as StringSourceText;
        //if (stringSourceText != null && stringSourceText.IsSameAsFileContents)
        //  doc.Text.TextProvider = new CollectibleSourceText(doc.Name, doc.Text.Length);
      }
      //Construct symbol table for entire project
      ErrorHandler errorHandler = new ErrorHandler(errors);
      SpecSharpCompilation ssCompilation = new SpecSharpCompilation();
      TrivialHashtable ambiguousTypes = new TrivialHashtable();
      TrivialHashtable referencedLabels = new TrivialHashtable();
      TrivialHashtable scopeFor = this.scopeFor = new TrivialHashtable();
      Scoper scoper = new Scoper(scopeFor);
      scoper.currentModule = symbolTable;
      Looker symLooker = new Looker(null, new ErrorHandler(new ErrorNodeList(0)), scopeFor, ambiguousTypes, referencedLabels);
      symLooker.currentAssembly = (symLooker.currentModule = symbolTable) as AssemblyNode;
      Looker looker = new Looker(null, errorHandler, scopeFor, ambiguousTypes, referencedLabels);
      looker.currentAssembly = (looker.currentModule = symbolTable) as AssemblyNode;
      looker.VisitAttributeList(assemblyAttributes);
      bool dummyCompilation = compilation.CompilerParameters is SpecSharpCompilerOptions && ((SpecSharpCompilerOptions)compilation.CompilerParameters).DummyCompilation;
      if (dummyCompilation){
        //This happens when there is no project. In this case, semantic errors should be ignored since the references and options are unknown.
        //But proceed with the full analysis anyway so that some measure of Intellisense can still be provided.
        errorHandler.Errors = new ErrorNodeList(0);
      }
      for (int i = 0; i < n; i++){
        CompilationUnit cUnit = compilationUnitSnippets[i];
        scoper.VisitCompilationUnit(cUnit);
      }
      for (int i = 0; i < n; i++){
        CompilationUnit cUnit = compilationUnitSnippets[i];
        if (cUnit == cuSnippet)
          looker.VisitCompilationUnit(cUnit); //Uses real error message list and populate the identifier info lists
        else
          symLooker.VisitCompilationUnit(cUnit); //Errors are discarded
      }
      //Run resolver over symbol table so that custom attributes on member signatures are known and can be used
      //to error check the the given file.
      TypeSystem typeSystem = new TypeSystem(errorHandler);
      Resolver resolver = new Resolver(errorHandler, typeSystem);
      resolver.currentAssembly = (resolver.currentModule = symbolTable) as AssemblyNode;
      Resolver symResolver = new Resolver(new ErrorHandler(new ErrorNodeList(0)), typeSystem);
      symResolver.currentAssembly = resolver.currentAssembly;
      symResolver.VisitAttributeList(assemblyAttributes);
      for (int i = 0; i < n; i++) {
        CompilationUnit cUnit = compilationUnitSnippets[i];
        if (cUnit == cuSnippet)
          resolver.VisitCompilationUnit(cUnit); //Uses real error message list and populate the identifier info lists
        else
          symResolver.VisitCompilationUnit(cUnit); //Errors are discarded
      }
      if (dummyCompilation) return;
      //Now analyze the given file for errors
      Checker checker = new Checker(ssCompilation, errorHandler, typeSystem, scopeFor, ambiguousTypes, referencedLabels);
      checker.currentAssembly = (checker.currentModule = symbolTable) as AssemblyNode;
      checker.VisitAttributeList(assemblyAttributes, checker.currentAssembly);
      checker.VisitModuleAttributes(moduleAttributes);
      checker.VisitCompilationUnit(cuSnippet);
       
      MemberFinder finder = new MemberFinder(line, col);
      finder.VisitCompilationUnit(cuSnippet);
      Node node = finder.Member;
      if (node == null){
        if (line == 0 && col == 0) 
          node = cuSnippet;
        else
          return;
      }

      SpecSharpCompilerOptions options = (SpecSharpCompilerOptions) compilation.CompilerParameters;
      if (options.IsContractAssembly) return;
      ssCompilation.RunPlugins(node, errorHandler);
      Normalizer normalizer = new Normalizer(typeSystem);
      normalizer.Visit(node);
      Analyzer analyzer = new Analyzer(typeSystem, compilation);
      analyzer.Visit(node);

      if (options.RunProgramVerifierWhileEditing)
        ssCompilation.AddProgramVerifierPlugin(typeSystem, compilation);
      ssCompilation.analyzer = analyzer; // make the analyzer available to plugins for access to method CFGs
      ssCompilation.RunPlugins(node, errorHandler);
      ssCompilation.analyzer = null;
      analyzer = null;
    }
Пример #22
0
 private void Awake()
 {
     objectTransform = GetComponent <Transform>();
     animator        = GetComponent <Animator>();
     looker          = GetComponent <Looker>();
 }
Пример #23
0
 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();
 }
Пример #24
0
 protected new void Start()
 {
     base.Start();
     _shooter = GetComponent <Shooter>();
     _looker  = GetComponent <Looker>();
 }
Пример #25
0
 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);
 }
Пример #26
0
        public override void CompileParseTree(Compilation compilation, ErrorNodeList errorNodes)
        {
            if (compilation == null)
            {
                Debug.Assert(false, "wrong compilation"); return;
            }
            CONTEXT.useComputeMath = ((ZonnonCompilerParameters)compilation.CompilerParameters).UseComputeMath;
            // Before the actual back-end compilation takes place,
            // we perform the Zonnon-tree to CCI-tree conversion.
            // Notice that we do that for the overall tree (i.e., for all sources)
            // and store the resulting CCI tree to CompilationUnits[0],
            // but do not spread subtrees to corresponding CompilationUnits.
            ERROR.errCount = 0;
            Parser.ConvertTree(compilation.CompilationUnits[0]);
            bool mainCompilationFailed = ERROR.errCount > 0;

            //    ERROR.EndOfMessages();

            //  Module symbolTable = compilation.TargetModule;
            //  compilation.GlobalScope = this.GetGlobalScope(symbolTable);

            ZonnonCompilerParameters options = compilation.CompilerParameters as ZonnonCompilerParameters;

            if (options == null)
            {
                options = new ZonnonCompilerParameters();
            }
            // Walk IR looking up names
#if DEBUG
            if (options.Debug)
            {
                System.Console.Write("Scoper is working...");
            }
#endif
            ErrorHandler     eh               = new ErrorHandler(errorNodes);
            TrivialHashtable ambiguousTypes   = new TrivialHashtable();
            TrivialHashtable referencedLabels = new TrivialHashtable();
            TrivialHashtable scopeFor         = new TrivialHashtable();
            TypeSystem       typeSystem       = new TypeSystem(eh);

            Scoper scoper = new Scoper(scopeFor);
            scoper.VisitCompilation(compilation);
#if DEBUG
            if (options.Debug)
            {
                System.Console.WriteLine("Done.");
                System.Console.Write("Looker is working... ");
            }
#endif
            Looker looker = new Looker(compilation.GlobalScope, eh, scopeFor, typeSystem, ambiguousTypes, referencedLabels);
            looker.VisitCompilation(compilation);

            // Walk IR inferring types and resolving overloads
            if (!mainCompilationFailed) // Resolve only if no errors
            {
                Resolver resolver = new Resolver(eh, typeSystem);
                resolver.VisitCompilation(compilation);

                // Walk IR checking for semantic errors and repairing it so that it the next walk will work
                Checker checker = new Checker(eh, typeSystem, ambiguousTypes, referencedLabels);
                checker.VisitCompilation(compilation);

                // Walk IR reducing it to nodes that have predefined mappings to MD+IL
                Normalizer normalizer = new Normalizer(typeSystem);
                normalizer.VisitCompilation(compilation);

                Analyzer analyzer = new Analyzer(typeSystem, compilation);
                analyzer.VisitCompilation(compilation);
            }
#if DEBUG
            if (options.Debug)
            {
                System.Console.WriteLine("Done.");
            }
#endif
        }
Пример #27
0
    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);
    }