Esempio n. 1
0
 public Block(Cursor cursor, Statement[] statements)
     : base(NodeKind.Block, cursor)
 {
     _statements = statements;
     foreach (Statement statement in _statements)
         statement.Above = this;
 }
Esempio n. 2
0
        public TextLiteral(Cursor cursor, Type type, string value)
            : base(NodeKind.TextLiteral, cursor)
        {
            _type = type;
            _type.Above = this;

            _value = value;
        }
Esempio n. 3
0
        public CardinalLiteral(Cursor cursor, Type type, uint value)
            : base(NodeKind.CardinalLiteral, cursor)
        {
            _type = type;
            _type.Above = this;

            _value = value;
        }
Esempio n. 4
0
        public Parameter(Cursor cursor, SymbolDefinition name, DirectionKind direction, Type type)
            : base(NodeKind.Parameter, cursor, name)
        {
            _direction = direction;

            _type = type;
            _type.Above = this;
        }
Esempio n. 5
0
        public CallExpression(Cursor cursor, Expression callee, Expression[] arguments)
            : base(NodeKind.CallExpression, cursor)
        {
            _callee = callee;
            _callee.Above = this;

            _arguments = arguments;
            foreach (Expression argument in _arguments)
                argument.Above = this;
        }
Esempio n. 6
0
        public Profile(Cursor cursor, Type type, Parameter[] parameters)
            : base(NodeKind.Profile, cursor)
        {
            _type = type;
            _type.Above = this;

            _parameters = parameters;
            foreach (Parameter parameter in _parameters)
                parameter.Above = this;
        }
Esempio n. 7
0
        public Node(NodeKind kind, Cursor cursor)
        {
            /** \note The node ids are 1-based to make it easier to detect errors. */
            _id = _nodes.Count + 1;
            _nodes[_id] = this;

            _kind = kind;
            // Make a deep copy of the position so as to protect it from unwanted side-effects.
            _cursor = new Cursor(cursor);
        }
Esempio n. 8
0
        public Routine(
            NodeKind kind,
            Cursor cursor,
            SymbolDefinition name,
            Profile profile,
            Block block
        )
            : base(kind, cursor, name)
        {
            _profile = profile;
            _profile.Above = this;

            _block = block;
            _block.Above = this;
        }
Esempio n. 9
0
        /** Creates a default getter for use in a field or a guard. */
        private GetStatement CreateDefaultGetter(Cursor cursor, string value)
        {
            // Create profile of the default getter.
            Profile profile = new Profile(
                position,
                new NamedType(position, new SymbolReference(position, PathKind.Instance, value)),
                new Parameter[0]
            );

            // Create sole embedded statement; a return statement that returns the value of the data member.
            Statement statement = new ReturnExpressionStatement(
                position,
                new NamedExpression(position, new SymbolReference(position, PathKind.Instance, value))
            );
            Statement[] statements = new Statement[1]{ statement };
            Block block = new Block(position, statements);

            return new GetStatement(
                position,
                new SymbolDefinition(position, "get", SymbolKind.Getter),
                profile,
                block
            );
        }
Esempio n. 10
0
 public Token(Cursor cursor)
 {
     _cursor = new Cursor(cursor);
 }
Esempio n. 11
0
 public Token()
 {
     _cursor = new Cursor();
 }
Esempio n. 12
0
 public PrefixReference(Cursor cursor, Expression prefix, string symbol)
     : base(NodeKind.PrefixReference, cursor, symbol)
 {
     _prefix = prefix;
     _prefix.Above = this;
 }
Esempio n. 13
0
 public GlobalReference(Cursor cursor, string symbol)
     : base(NodeKind.GlobalReference, cursor, symbol)
 {
 }
Esempio n. 14
0
 public SymbolErrorExists(Cursor cursor, string name)
     : base(cursor, name)
 {
 }
Esempio n. 15
0
 public SymbolErrorUnknown(Cursor cursor, string name)
     : base(cursor, name)
 {
 }
Esempio n. 16
0
 public BlockStatement(Cursor cursor, Block block)
     : base(NodeKind.BlockStatement, cursor)
 {
     _block = block;
     _block.Above = this;
 }
Esempio n. 17
0
 /** Constructor for the \c Error class. */
 public Error(ErrorKind level, Cursor cursor, int code, string text)
     : base(cursor, text)
 {
     _level = level;
     _code = code;
 }
 public ReturnExpressionStatement(Cursor cursor, Expression expression)
     : base(NodeKind.ReturnExpressionStatement, cursor)
 {
     _expression = expression;
     _expression.Above = this;
 }
Esempio n. 19
0
 public TextType(Cursor cursor)
     : base(NodeKind.TextType, cursor)
 {
 }
Esempio n. 20
0
 public Module(Cursor cursor, Block block)
     : base(NodeKind.Module, cursor)
 {
     _block = block;
     _block.Above = this;
 }
Esempio n. 21
0
 public EntryStatement(Cursor cursor, SymbolDefinition name, Profile profile, Block block)
     : base(NodeKind.EntryStatement, cursor, name, profile, block)
 {
 }
Esempio n. 22
0
        /** Looks up an absolute encoded (mangled) symbol. */
        public Symbol LookupEncoded(Cursor cursor, string name)
        {
            if (name.Substring(0, 4) != "$b0$")
                throw new Toolbox.Error(Toolbox.ErrorKind.Fatal, cursor, 0, "Invalid symbol: " + name);

            Folder<Symbol> folder = _volume;
            int first = 4;
            int other = first;
            do
            {
                string symbol;

                other = name.IndexOf('!', first);
                if (other == -1)
                    symbol = "$b0$" + name.Substring(first);
                else
                    symbol = name.Substring(first, other - first);
                first = other + 1;

                folder = (Folder<Symbol>) folder.Resolve(symbol);
                if (folder == null)
                    throw new Toolbox.Error(Toolbox.ErrorKind.Fatal, cursor, 0, "Unknown symbol: " + name);
            } while (other != -1);

            return folder.Data;
        }
 public ReturnNothingStatement(Cursor cursor)
     : base(NodeKind.ReturnNothingStatement, cursor)
 {
 }
Esempio n. 24
0
 public InternalError(Cursor cursor, string message)
     : base(message)
 {
     _cursor = new Cursor(cursor);       // Make deep copy to avoid problems with cursors that change afterwards.
 }
Esempio n. 25
0
 public CallStatement(Cursor cursor, Expression expression)
     : base(NodeKind.CallStatement, cursor)
 {
     _expression = expression;
     _expression.Above = this;
 }
Esempio n. 26
0
 public Definition(NodeKind kind, Cursor cursor, SymbolDefinition name)
     : base(kind, cursor)
 {
     _name = name;
     _name.Above = this;
 }
Esempio n. 27
0
 public MemberReference(Cursor cursor, string symbol)
     : base(NodeKind.MemberReference, cursor, symbol)
 {
 }
Esempio n. 28
0
 public void Report(ErrorKind level, Cursor cursor, string text)
 {
     Report(level, cursor, 0, text);
 }
Esempio n. 29
0
 public ScopeStatement(Cursor cursor, SymbolDefinition name, Block block)
     : base(NodeKind.ScopeStatement, cursor, name)
 {
     _block = block;
     _block.Above = this;
 }
Esempio n. 30
0
        public void Report(ErrorKind level, Cursor cursor, int code, string text)
        {
            Error error = new Error(level, cursor, code, text);

            _lock.Acquire();
            _errors.Add(error);
            _lock.Release();

            // update Failed property that indicates whether one or more errors have occured
            switch (level)
            {
                case ErrorKind.Debug    : break;
                case ErrorKind.Error    : _failed = true; break;
                case ErrorKind.Fatal    : _failed = true; break;
                case ErrorKind.Internal : _failed = true; break;
                case ErrorKind.Notice   : break;
                case ErrorKind.Unhandled: _failed = true; break;
                case ErrorKind.Warning  : break;
                default:
                    throw new InternalError("Unknown ErrorKind value encountered: " + level.ToString());
            }

            // don't report the event if the trace level does not allow it
            if (level > _level)
                return;

            System.Text.StringBuilder result = new System.Text.StringBuilder();
            if (cursor != null)
                result.Append(cursor.ToString());
            if (result.Length > 0)
                result.Append(' ');

            string name = null;
            switch (level)
            {
                case ErrorKind.Debug    : name = "DEBUG";           break;
                case ErrorKind.Error    : name = "Error";           break;
                case ErrorKind.Fatal    : name = "Fatal error";     break;
                case ErrorKind.Internal : name = "Internal error";  break;
                case ErrorKind.Notice   : name = null;              break;
                case ErrorKind.Unhandled: name = "Unhandled error"; break;
                case ErrorKind.Warning  : name = "Warning";         break;
                default:
                    throw new InternalError("Unknown ErrorKind value encountered: " + level.ToString());
            }
            if (name != null)
                result.Append(name);
            if (code != 0)
                result.Append(" " + code.ToString());
            if (name != null)
                result.Append(": ");

            result.Append(text);

            _writer.WriteLine(result.ToString());
        }