示例#1
0
文件: VarBlock.cs 项目: strunberg/TEA
 public VariableDeclaration(
     Token start, 
     IEnumerable<string> variableNames, 
     TypeReference type,
     Expression initExpression)
     : base(start)
 {
     this.type = type;
     this.variableNames.AddRange(variableNames);
     this.InitExpression = initExpression;
 }
示例#2
0
文件: Parser.cs 项目: strunberg/TEA
        private bool ParseTypeReference(TokenReader reader, out TypeReference type)
        {
            Token tok = reader.Peek();
            Token start = tok;
            type = null;

            if (tok.Is(Keyword.Pointer))
            {
                reader.Read();
                TypeReference elementType = null;
                if (!this.ParseTypeReference(reader, out elementType))
                {
                    return false;
                }

                type = new PointerTypeReference(start, elementType);
                return true;
            }
            else if (tok.Is(Keyword.Array))
            {
                reader.Read();
                tok = reader.Peek();
                Expression elementCount = null;
                if (tok.Is(Keyword.LeftBracket))
                {
                    reader.Read();
                    if (!this.ParseExpression(reader, out elementCount))
                    {
                        return false;
                    }

                    if (!this.Expect(reader, Keyword.RightBracket))
                    {
                        return false;
                    }

                    tok = reader.Peek();
                }

                if (!this.Expect(reader, Keyword.Of))
                {
                    return false;
                }

                TypeReference elementType = null;
                if (!this.ParseTypeReference(reader, out elementType))
                {
                    return false;
                }

                type = new ArrayTypeReference(start, elementCount, elementType);
                return true;
            }
            else
            {
                string typeName = null;
                if (!this.ParseFullNameDeclaration(reader, out typeName))
                {
                    return false;
                }

                type = new NamedTypeReference(start, typeName);
                return true;
            }
        }
示例#3
0
 public PointerTypeReference(Token start, TypeReference elementType)
     : base(start)
 {
     this.ElementType = elementType;
 }
示例#4
0
 public ArrayTypeReference(Token start, Expression elementCount, TypeReference elementType)
     : base(start)
 {
     this.ElementCount = elementCount;
     this.ElementType = elementType;
 }
示例#5
0
        private bool TryResolveTypeReference(
            CompilerContext context, 
            TypeReference typeRef, 
            out TypeDefinition typeDef)
        {
            NamedTypeReference namedType = typeRef as NamedTypeReference;
            if (namedType != null)
            {
                if (!context.TryFindTypeByName(namedType.TypeName, out typeDef))
                {
                    string message = string.Format(
                        Properties.Resources.CodeGenerator_UndefinedType,
                        namedType.TypeName);
                    this.log.Write(new Message(
                        namedType.Start.Path,
                        namedType.Start.Line,
                        namedType.Start.Column,
                        Severity.Error,
                        message));
                    return false;
                }

                return true;
            }

            PointerTypeReference pointerType = typeRef as PointerTypeReference;
            if (pointerType != null)
            {
                TypeDefinition innerType = null;
                if (!this.TryResolveTypeReference(context, pointerType.ElementType, out innerType))
                {
                    typeDef = null;
                    return false;
                }

                typeDef = context.GetPointerType(innerType);
                return true;
            }

            ArrayTypeReference arrayType = typeRef as ArrayTypeReference;
            if (arrayType != null)
            {
                TypeDefinition innerType = null;
                if (!this.TryResolveTypeReference(context, arrayType.ElementType, out innerType))
                {
                    typeDef = null;
                    return false;
                }

                int elementCount = 0;
                if (arrayType.ElementCount != null)
                {
                    LiteralExpression litElementCount = arrayType.ElementCount as LiteralExpression;
                    if (litElementCount == null || !(litElementCount.Value is int))
                    {
                        log.Write(new Message(
                            arrayType.ElementCount.Start.Path,
                            arrayType.ElementCount.Start.Line,
                            arrayType.ElementCount.Start.Column,
                            Severity.Error,
                            Properties.Resources.CodeGenerator_ArrayTypeIntElementExpected));
                        typeDef = null;
                        return false;
                    }

                    elementCount = (int)(litElementCount.Value);
                }

                typeDef = context.GetArrayType(innerType, elementCount);
                return true;
            }

            typeDef = null;
            return false;
        }
示例#6
0
 public NewExpression(Token start, TypeReference typeReference, IEnumerable<Expression> constructorArguments)
     : base(start)
 {
     this.typeReference = typeReference;
     this.constructorArguments.AddRange(constructorArguments);
 }
示例#7
0
 public ParameterDeclaration(Token start, IEnumerable<string> parameterNames, TypeReference type)
     : base(start)
 {
     this.type = type;
     this.parameterNames.AddRange(parameterNames);
 }