Beispiel #1
0
        public TryStatement(
            Token tryToken,
            Executable[] tryCode,
            IList <Token> catchTokens,
            IList <CSharpType> catchBlockTypes,
            IList <Token> catchBlockVariables,
            IList <Executable[]> catchBlockCode,
            Token finallyToken,
            Executable[] finallyCode,
            TopLevelEntity parent)
            : base(tryToken, parent)
        {
            this.TryCode = tryCode;
            List <CatchBlock> catches = new List <CatchBlock>();

            for (int i = 0; i < catchBlockCode.Count; ++i)
            {
                catches.Add(new CatchBlock()
                {
                    CatchToken        = catchTokens[i],
                    ExceptionType     = catchBlockTypes[i],
                    ExceptionVariable = catchBlockVariables[i],
                    Code = catchBlockCode[i],
                });
            }
            this.CatchBlocks  = catches.ToArray();
            this.FinallyToken = finallyToken;
            this.FinallyCode  = finallyCode;
        }
Beispiel #2
0
        internal static Expression AttemptToResolveDotFieldChainIntoDirectReference(IList <Token> chain, ParserContext context, Expression scope)
        {
            CSharpType   cst           = CSharpType.Fabricate(chain);
            ResolvedType existingThing = scope.DoTypeLookupFailSilently(cst, context);

            if (existingThing != null)
            {
                if (existingThing.IsEnum)
                {
                    return(new EnumDefinitionReference(scope.FirstToken, scope.Parent, existingThing));
                }
                else if (existingThing.CustomType != null)
                {
                    TopLevelEntity tle = existingThing.CustomType;
                    if (tle is ClassLikeDefinition)
                    {
                        return(new StaticClassReference(scope.FirstToken, scope.Parent, (ClassLikeDefinition)tle));
                    }
                    else
                    {
                        throw new System.NotImplementedException();
                    }
                }
                else if (existingThing.FrameworkClass != null)
                {
                    return(new StaticFrameworkClassReference(scope.FirstToken, scope.Parent, existingThing));
                }
                else
                {
                    throw new System.NotImplementedException();
                }
            }
            return(null);
        }
Beispiel #3
0
 public InterfaceDefinition(
     Token firstToken,
     Dictionary <string, Token> modifiers,
     Token classToken,
     Token classNameToken,
     List <CSharpType> subClassesAndSuch,
     TopLevelEntity parent)
     : base(firstToken, modifiers, classToken, classNameToken, subClassesAndSuch, parent)
 {
 }
Beispiel #4
0
 public EnumDefinition(
     Token firstToken,
     Dictionary <string, Token> modifiers,
     Token name,
     TopLevelEntity parent)
     : base(firstToken, parent)
 {
     this.ApplyModifiers(modifiers);
     this.Name = name;
 }
 public ConstDefinition(
     Token firstToken,
     Dictionary <string, Token> modifiers,
     CSharpType constType,
     Token name,
     TopLevelEntity parent)
     : base(firstToken, parent)
 {
     this.ApplyModifiers(modifiers);
     this.Name = name;
     this.Type = constType;
 }
Beispiel #6
0
 public PropertyDefinition(
     Token firstToken,
     Dictionary <string, Token> topLevelModifiers,
     CSharpType type,
     Token name,
     TopLevelEntity parent)
     : base(firstToken, parent)
 {
     this.ApplyModifiers(topLevelModifiers);
     this.Type = type;
     this.Name = name;
 }
 public ArrayInitialization(
     Token firstToken,
     CSharpType itemType,
     Expression arrayLength,
     IList <Expression> arrayElements,
     TopLevelEntity parent)
     : base(firstToken, parent)
 {
     this.ItemType = itemType;
     this.ArrayLengthExpression = arrayLength;
     this.ArrayItems            = arrayElements == null ? null : arrayElements.ToArray();
 }
Beispiel #8
0
 public VerifiedFieldReference(
     Token firstToken,
     TopLevelEntity parent,
     Token methodName,
     Expression root,
     ResolvedType staticMethodSource)
     : base(firstToken, parent)
 {
     this.Name               = methodName;
     this.RootValue          = root;
     this.StaticMethodSource = staticMethodSource;
     this.Type               = MethodRefType.UNKNOWN;
 }
 public FunctionInvocation(
     Token firstToken,
     Expression root,
     Token openParen,
     IList <Expression> args,
     IList <Token> outTokens,
     TopLevelEntity parent)
     : base(firstToken, parent)
 {
     this.Root      = root;
     this.OpenParen = openParen;
     this.Args      = args.ToArray();
     this.OutTokens = outTokens.ToArray();
 }
Beispiel #10
0
 public ClassLikeDefinition(
     Token firstToken,
     Dictionary <string, Token> modifiers,
     Token classToken,
     Token classNameToken,
     List <CSharpType> parentClassesAndSuch,
     TopLevelEntity parent)
     : base(firstToken, parent)
 {
     this.ClassToken = classToken;
     this.Name       = classNameToken;
     this.ApplyModifiers(modifiers);
     this.RawParentClassInfoTokens = parentClassesAndSuch.ToArray();
 }
 public ConstructorDefinition(
     Token firstToken,
     Dictionary <string, Token> modifiers,
     IList <CSharpType> argTypes,
     IList <Token> argNames,
     IList <Token> argModifiers,
     TopLevelEntity parent)
     : base(firstToken, parent)
 {
     this.ApplyModifiers(modifiers);
     this.ArgTypes     = argTypes.ToArray();
     this.ArgNames     = argNames.ToArray();
     this.ArgModifiers = argModifiers.ToArray();
     this.BaseConstructorInvocation = null;
     this.BaseConstructorArgs       = null;
 }
 public VariableDeclaration(
     Token firstToken,
     CSharpType variableType,
     Token variableName,
     Token assignmentToken,
     Expression value,
     TopLevelEntity parent)
     : base(firstToken, parent)
 {
     if (this.FirstToken.File.Contains("AssemblyDependencyResolver.cs") && this.FirstToken.Line == 53)
     {
     }
     this.VariableName    = variableName;
     this.Type            = variableType;
     this.AssignmentToken = assignmentToken;
     this.InitialValue    = value;
 }
        public SwitchStatement(
            Token firstToken,
            Expression condition,
            IList <Token> caseTokens,
            IList <Expression> caseConstants,
            IList <Executable[]> codeForCases,
            TopLevelEntity parent)
            : base(firstToken, parent)
        {
            this.Condition = condition;

            List <SwitchStatementChunk> chunks             = new List <SwitchStatementChunk>();
            List <Token>      caseTokensForCurrentChunk    = new List <Token>();
            List <Expression> caseConstantsForCurrentChunk = new List <Expression>();

            for (int i = 0; i < codeForCases.Count; ++i)
            {
                caseTokensForCurrentChunk.Add(caseTokens[i]);
                caseConstantsForCurrentChunk.Add(caseConstants[i]);
                if (codeForCases[i] == null || codeForCases[i].Length == 0)
                {
                    // carry it over to the next chunk
                }
                else
                {
                    chunks.Add(new SwitchStatementChunk()
                    {
                        Cases      = caseConstantsForCurrentChunk.ToArray(),
                        CaseTokens = caseTokensForCurrentChunk.ToArray(),
                        Code       = codeForCases[i],
                    });
                    caseConstantsForCurrentChunk.Clear();
                    caseTokensForCurrentChunk.Clear();
                }
            }

            if (caseConstantsForCurrentChunk.Count > 0)
            {
                throw new ParserException(caseTokens[0], "This case does not have any code and falls through to the bottom of the switch statement.");
            }

            this.Chunks = chunks.ToArray();
        }
Beispiel #14
0
        private void ResolveCustomFieldReference()
        {
            string fieldName = this.Name.Value;

            if (this.RootValue.ResolvedType.IsEnum)
            {
                if (!this.RootValue.ResolvedType.HasEnumField(fieldName))
                {
                    throw new ParserException(this.Name, this.RootValue.ResolvedType.ToString() + " doesn't have a field called " + fieldName + ".");
                }
                this.ResolvedType = ResolvedType.CreateEnumField(this.RootValue.ResolvedType);
            }
            else
            {
                ClassLikeDefinition rootType = (ClassLikeDefinition)this.RootValue.ResolvedType.CustomType;
                TopLevelEntity      member   = rootType.GetMember(fieldName).FirstOrDefault();
                if (member == null)
                {
                    throw new ParserException(this.Name, "Not implemented or not found.");                 // could be a framework field.
                }
                if (member is PropertyDefinition)
                {
                    this.Property     = (PropertyDefinition)member;
                    this.ResolvedType = this.Property.ResolvedType;
                }
                else if (member is FieldDefinition)
                {
                    this.Field        = (FieldDefinition)member;
                    this.ResolvedType = this.Field.ResolvedType;
                }
                else
                {
                    throw new ParserException(this.FirstToken, "Not implemented");
                }
            }
        }
Beispiel #15
0
 public ForLoop(Token forToken, IList <Executable> initCode, Expression condition, IList <Executable> stepCode, IList <Executable> loopBody, TopLevelEntity parent)
     : base(forToken, parent)
 {
     this.InitCode  = initCode.ToArray();
     this.Condition = condition;
     this.StepCode  = stepCode.ToArray();
     this.Code      = loopBody.ToArray();
 }
Beispiel #16
0
 public Lambda(Token firstToken, IList <Token> args, Token arrowToken, IList <Executable> code, TopLevelEntity parent)
     : base(firstToken, parent)
 {
     this.Args       = args.ToArray();
     this.ArrowToken = arrowToken;
     this.Code       = code.ToArray();
 }
Beispiel #17
0
 public ForEachLoop(Token foreachToken, CSharpType type, Token variableToken, Expression listExpression, IList <Executable> loopBody, TopLevelEntity parent)
     : base(foreachToken, parent)
 {
     this.VariableType   = type;
     this.VariableToken  = variableToken;
     this.ListExpression = listExpression;
     this.Code           = loopBody.ToArray();
 }
Beispiel #18
0
 public void AddMember(TopLevelEntity tle)
 {
     // TODO: check types
     this.members = null;
     this.membersBuilder.Add(tle);
 }
Beispiel #19
0
 public OpChain(IList <Expression> expressions, IList <Token> ops, TopLevelEntity parent)
     : base(expressions[0].FirstToken, parent)
 {
     this.Expressions = expressions.ToArray();
     this.Ops         = ops.ToArray();
 }
Beispiel #20
0
 public FieldDefinition(Token firstToken, Dictionary <string, Token> modifiers, CSharpType type, Token name, Expression nullableInitialValue, TopLevelEntity parent)
     : base(firstToken, parent)
 {
     this.ApplyModifiers(modifiers);
     this.Type         = type;
     this.Name         = name;
     this.InitialValue = nullableInitialValue;
 }
Beispiel #21
0
 public DoWhileLoop(Token doToken, Executable[] code, Expression condition, TopLevelEntity parent)
     : base(doToken, parent)
 {
     this.Code      = code;
     this.Condition = condition;
 }
Beispiel #22
0
 public ThisKeyword(Token firstToken, TopLevelEntity parent)
     : base(firstToken, parent)
 {
 }
Beispiel #23
0
 public void AddMember(TopLevelEntity entity)
 {
     this.Members.Add(entity);
 }
Beispiel #24
0
 public Namespace(Token firstToken, IList <Token> nameParts, TopLevelEntity parent)
     : base(firstToken, parent)
 {
     this.NameParts = nameParts.ToArray();
     this.Members   = new List <TopLevelEntity>();
 }
 public ReturnStatement(Token firstToken, Expression nullableExpression, TopLevelEntity parent)
     : base(firstToken, parent)
 {
     this.Value = nullableExpression;
 }
Beispiel #26
0
        }                                                            // TODO: get rid of the field and just use this.

        public Executable(Token firstToken, TopLevelEntity parent)
            : base(firstToken)
        {
            this.parent = parent;
        }
Beispiel #27
0
 public UsingStatement(Token firstToken, CSharpType variableType, Token variableName, Expression expression, IList <Executable> code, TopLevelEntity parent)
     : base(firstToken, parent)
 {
     this.Type         = variableType;
     this.VariableName = variableName;
     this.Expression   = expression;
     this.Code         = code.ToArray();
 }
 public ThrowStatement(Token throwToken, Expression expr, TopLevelEntity parent)
     : base(throwToken, parent)
 {
     this.Expression = expr;
 }
 public MultiVariableDeclaration(Token firstToken, CSharpType type, IList <Token> names, TopLevelEntity parent)
     : base(firstToken, parent)
 {
     this.Type  = type;
     this.Names = names.ToArray();
 }
Beispiel #30
0
 public WhileLoop(Token whileToken, Expression condition, Executable[] code, TopLevelEntity parent)
     : base(whileToken, parent)
 {
     this.Condition = condition;
     this.Code      = code;
 }