Ejemplo n.º 1
0
        public SceneSymbol?ResolveCallSceneTarget(CallSceneStatement callSceneStmt)
        {
            if (callSceneStmt.TargetModule is null)
            {
                return(LookupScene(callSceneStmt.TargetScene));
            }

            Spanned <string> targetModule = callSceneStmt.TargetModule.Value;
            string           modulePath   = targetModule.Value;

            try
            {
                SourceModuleSymbol targetSourceModule = _compilation.GetSourceModule(modulePath);
                SceneSymbol?       scene = targetSourceModule.LookupScene(callSceneStmt.TargetScene.Value);
                if (scene is null)
                {
                    ReportUnresolvedIdentifier(callSceneStmt.TargetScene);
                }

                return(scene);
            }
            catch (FileNotFoundException)
            {
                string moduleName = targetModule.Value;
                Report(targetModule, DiagnosticId.ExternalModuleNotFound, moduleName);
                return(null);
            }
        }
Ejemplo n.º 2
0
 private void ResolveTy(Spanned<TyRef> spTy)
 {
     var ty = spTy.value as PathTyRef;
     if (ty != null && !ty.Resolved)
     {
         if (!ty.Resolved)
         {
             // TODO(kai): eventually this will all be qualified, we'll have to deal with that.
             var name = ty.name;
             var sym = walker.Current.Lookup(name);
             if (sym == null)
             {
                 // TODO(kai): use spanned types
                 log.Error(spTy.span, "Could not locate symbol \"{0}\", failed to resolve type.", name);
                 return;
             }
             var symTy = sym.Ty;
             if (symTy is PathTyRef)
             {
                 if ((symTy as PathTyRef).Resolved)
                     ty.Resolve(symTy);
                 else hasResolved = false;
             }
             else ty.Resolve(symTy);
         }
     }
 }
Ejemplo n.º 3
0
        // TODO(kai): default values

        public Parameter(Spanned<string> name, Spanned<TyRef> spTy)
        {
            if (spTy == null)
                throw new System.ArgumentNullException("spTy");
            this.spTy = spTy;
            this.name = name;
        }
Ejemplo n.º 4
0
 internal UnaryExpression(
     Expression operand,
     Spanned <UnaryOperatorKind> operatorKind,
     TextSpan span) : base(span)
 {
     Operand      = operand;
     OperatorKind = operatorKind;
 }
Ejemplo n.º 5
0
 internal FunctionCallExpression(
     Spanned <string> targetName,
     ImmutableArray <Expression> arguments,
     TextSpan span) : base(span)
 {
     TargetName = targetName;
     Arguments  = arguments;
 }
Ejemplo n.º 6
0
 internal AssignmentExpression(
     Expression target,
     Spanned <AssignmentOperatorKind> operatorKind,
     Expression value,
     TextSpan span) : base(span)
 {
     Target       = target;
     OperatorKind = operatorKind;
     Value        = value;
 }
Ejemplo n.º 7
0
 internal BinaryExpression(
     Expression left,
     Spanned <BinaryOperatorKind> operatorKind,
     Expression right,
     TextSpan span) : base(span)
 {
     Left         = left;
     OperatorKind = operatorKind;
     Right        = right;
 }
Ejemplo n.º 8
0
        public SceneSymbol?LookupScene(Spanned <string> identifier)
        {
            SceneSymbol?scene = _module.LookupScene(identifier.Value);

            if (scene is not null)
            {
                return(scene);
            }

            ReportUnresolvedIdentifier(identifier);
            return(null);
        }
Ejemplo n.º 9
0
        public ChapterSymbol?LookupChapter(Spanned <string> identifier)
        {
            ChapterSymbol?chapter = _module.LookupChapter(identifier.Value);

            if (chapter is not null)
            {
                return(chapter);
            }

            ReportUnresolvedIdentifier(identifier);
            return(null);
        }
Ejemplo n.º 10
0
 public PrefixOperation(int nodeId, Token @operator, IExpression operand)
 {
     NodeId   = nodeId;
     Span     = SourceSpan.Merge(@operator.Span, operand.Span);
     Operator = new Spanned <PrefixOperator>(
         @operator.Kind switch
     {
         TokenKind.Bang => PrefixOperator.Not,
         TokenKind.Plus => PrefixOperator.Identity,
         TokenKind.Minus => PrefixOperator.Negate,
         TokenKind.Tilde => PrefixOperator.BinaryNot,
         _ => throw new ArgumentException(nameof(@operator)),
     },
Ejemplo n.º 11
0
        private void ErrNoSuchFunction(Spanned<string> spName, TyRef[] args)
        {
            var builder = new StringBuilder().Append('|');

            for (int i = 0; i < args.Length; i++)
            {
                if (i > 0)
                    builder.Append(", ");
                builder.Append(args[i]);
            }

            builder.Append('|');

            log.Error(spName.span, "No method \"{0}\" with parameter types {1} exists.", spName.value, builder.ToString());
        }
Ejemplo n.º 12
0
        public LookupResult LookupFunction(Spanned <string> identifier)
        {
            string          name            = identifier.Value;
            BuiltInFunction?builtInFunction = WellKnownSymbols.LookupBuiltInFunction(name);

            if (builtInFunction.HasValue)
            {
                return(new LookupResult(builtInFunction.Value));
            }

            FunctionSymbol?function = _module.LookupFunction(name);

            if (function is not null)
            {
                return(new LookupResult(function));
            }

            ReportUnresolvedIdentifier(identifier);
            return(LookupResult.Empty);
        }
Ejemplo n.º 13
0
 public NodeInvoke(Spanned<string> spName, List<NodeExpr> args)
 {
     this.spName = spName;
     this.args = args;
 }
Ejemplo n.º 14
0
 public NodeLet(Spanned<string> spName, Spanned<TyRef> spTy, NodeExpr value)
 {
     this.spName = spName;
     this.spTy = spTy;
     this.value = value;
 }
Ejemplo n.º 15
0
 public static void AssertSpannedText(string text, string substring, Spanned <string> spannedSubstring)
 {
     Assert.Equal(substring, spannedSubstring.Value);
     Assert.Equal(SpanOf(text, substring), spannedSubstring.Span);
 }