public override void Do(ICommandContext context)
 {
     //if (dimension == 1)
     //{
         if (initFromStack)
         {
             if (type.TypeEnum == TypeEnum.Array && readSizesFromStack)
             {
                 type.Dimensions = context.RunStack.Pop(dimension).Select(value => value.ToInt32()).ToList();
             }
             var list = new Types.List();
             for (int i = 0; i < size; i++)
                 list.Insert(context.RunStack.Pop());
             context.RunStack.Push(list.ConvertTo(type));
         }
         else
         {
             // ???
             context.RunStack.Push(new Types.Array(type, context.RunStack.Pop().ToInt32()));
         }
     //}
     //else
     //{
     //    throw new Psimulex.Core.Exceptions.PsimulexException("More than one dimensional array is not implemented yet!");
     //}
 }
Example #2
0
 public Array(TypeIdentifier initializatorType, int size)
 {
     this.InitializatorType = initializatorType;
     this.size = size;
     rep = new List<BaseType>(size);
     this._type = new TypeIdentifier { TypeEnum = TypeEnum.Array, GenericType = initializatorType };
     InitializeArray();
 }
Example #3
0
 public static List<string> GetValues(string pattern, string text)
 {
     List<string> lst = new List<string>();
     Regex regex = new Regex(pattern);
     foreach (Match m in regex.Matches(text))
         lst.Add(m.Groups[1].Value);
     return lst;
 }
Example #4
0
 public Program()
 {
     Name = "";
     CommandList = new CommandList();
     Functions = new List<UserDefinedFunction>();
     UserDefinedTypes = new TypeDescriptors();
     //EntryPoints = new Dictionary<UserDefinedFunction, int>();
 }
Example #5
0
 public Member()
 {
     Type = TypeEnum.Undefined;
     TypeName = "";
     DimensionCount = 0;
     DimensionList = new List<int>();
     Name = "";
     Value = null;
     IsInitialised = false;
     IsReference = false;
 }
Example #6
0
 /*
 public double ChildrenWidth
 {
     get
     {
         double cw = 0;
         double sep = 0;
         foreach (TreeNodeGraphics tg in Children)
         {
             cw += tg.ActualWidth + sep;
             sep = 10;
         }
         return cw;
     }
 }
 */
 public TreeNodeGraphics(Core.Types.TreeBase t)
     : base(GraphicsElementFactory.Produce(t.Value))
 {
     tree = t;
     tree.ValueInitialized += treeValueInitialized;
     _children = new List<TreeNodeGraphics>();
     isWidthInvalidated = true;
     //			if (tree.Value != null)
     //				tree.Value.Changed += tree_ValueChanged;
     //			tree.Changed += tree_ValueChanged;
 }
Example #7
0
        public void DepthChanged(object sender, DepthChangedEventArgs e)
        {
            List<Selector> removables = new List<Selector>();
            foreach (Selector sel in selectors.Values)
            {
                if (sel.Depth > e.Depth)
                {
                    graphics[sel.Index].Deselect(sel);
                    removables.Add(sel);
                }
            }

            foreach (Selector sel in removables)
                selectors.Remove(sel.Id);
        }
Example #8
0
        public CompilerDTO()
        {
            Program = ProgramBuilder.Create();

            CompilationUnitList = new List<CompilationUnit>();

            UserDefinedTypeInfoList = new List<UserDefinedTypeInfo>();
            UserDefinedFunctionInfoList = new List<UserDefinedFunctionInfo>();
            GlobalVariableInfoList = new List<GlobalVariableInfo>();

            CommandPositionChanges = new CommandPositionChanges();

            CompilerMessages = new MessageList();

            ProgramPath = "";
        }
Example #9
0
        public static List<string> GetList(string str)
        {
            List<string> tokens = new List<string>();

            string current = "";
            bool isInStrLiteral = false;
            for (int i = 0; i < str.Length; i++)
            {
                if (str[i] != ',' && !isInStrLiteral)
                {
                    current += str[i];
                }
                else if (str[i] == ',' && !isInStrLiteral)
                {
                    tokens.Add(current.Trim());
                }
                else if (isInStrLiteral)
                {
                    current += str[i];
                }
            }

            return tokens;
        }
Example #10
0
 protected override IEnumerable<TreeBase> GetChildren()
 {
     var children = new List<TreeBase>(2);
     if (Left != null)
         children.Add(Left);
     if (Right != null)
         children.Add(Right);
     return children;
 }
Example #11
0
 public IndexedEventArgs()
 {
     IndexDimensions = new List<int>();
 }
Example #12
0
 public Function()
 {
     Parameters = new List<VariableDescriptor>();
 }
Example #13
0
        public virtual void Visit(DataTypeNode node)
        {
            lastCompiledDataType = TypeEnumFactory.CreateTypeEnum(node.Left.Value);
            lastCompiledDataTypeName = node.Left.Value;

            // Set back to Defaults
            lastCompiledDimensionCount = 0;
            lastCompiledDimensionList = new List<int>();
        }
Example #14
0
 public override void Assign(BaseType value)
 {
     this.rep = value.ToPriorityQueue().rep.Select(pair => pair.Clone()).ToList();
     OnChanged();
 }
        public override void Visit(StructDeclarationNode node)
        {
            // User Defined Struct Name
            string structName = node.StructName.Value;
            List<Member> structMembers = new List<Member>();

            foreach (IPsiNode member in node.StructMemberList)
            {
                member.Accept(this);
                structMembers.Add(lastCompiledMember);
            }

            // Message
            string msg = "Struct Found : " + structName + " { ";
            foreach (Member member in structMembers)
            {
                msg += member.ToString();

                if (member != structMembers[structMembers.Count - 1])
                    msg += ", ";
            }
            msg += " }";
            AddInformation(msg, node.NodeValueInfo);

            // Check Existance
            if (IsUserDefinedTypeFounded(structName))
            {
                AddError(CompilerErrorCode.TypeCollision,
                    string.Format("User defined type \"{0}\" is already used, this will be skipped!", structName),
                    node.NodeValueInfo);
            }
            else
            {
                // Create a Struct Descriptor
                var desc = new StructDescriptor { Name = structName };

                foreach (var member in structMembers)
                {
                    if (member.Type == TypeEnum.Undefined)
                    {
                        AddWarning(CompilerErrorCode.NotSupported,
                            "User defined types in records is not supported, member will be skipped!",
                            node.NodeValueInfo);
                    }
                    else
                    {
                        // Check Existance
                        if (IsAttributeFounded(desc.Attributes, member.Name))
                        {
                            AddError(CompilerErrorCode.StructAttributeNameCollision, string.Format(
                                "Struct \"{0}\" has already a member \"{1}\", member will be skipped!", desc.Name, member.Name),
                                node.NodeValueInfo);
                        }
                        else
                        {
                            desc.Attributes.Add(
                                new AttributeDescriptor
                                {
                                    Value = member.Value,
                                    Descriptor = new VariableDescriptor
                                    {
                                        IsReference = member.IsReference,
                                        Name = member.Name,
                                        Type = new TypeIdentifier
                                        {
                                            TypeEnum = member.Type,
                                            TypeName = member.TypeName,
                                            Dimensions = new List<int>(member.DimensionCount)
                                        }
                                    }
                                });
                        }
                    }
                }

                // Add to UserDefinedTypeInfoList
                UserDefinedTypeInfoList.Add(
                    new UserDefinedTypeInfo(
                        new TypeIdentifier
                        {
                            UserDefinedType = desc,
                            TypeEnum = TypeEnum.UserDefinedType,
                            TypeName = desc.Name
                        },
                        SourceFileName,
                        node.NodeValueInfo));
            }
        }
        private void InitHelpers()
        {
            addToProgram = true;
            lastCompiledAssign = null;

            isOperatorUnaryPrefix = false;
            isCompilingAssignmentTarget = false;
            isSelectorsFirstCompile = true;
            isCurrentCompiledTheMainProgram = true;

            lazyEvaluationJumpStack = new System.Collections.Generic.Stack<Jump>();
            jumpStack = new System.Collections.Generic.Stack<Jump>();

            conditionCount = 0;
            lineLengthList = SourceInfoUtils.FindLineLengths(Source);

            currentGlobalVariableInfo = null;
            currentUserDefinedFunctionInfo = null;
        }
Example #17
0
        private void CallByName(ICommandContext context)
        {
            // It has to look up the availabe function names
            Function function = null;
            if (parametersCount >= 0)
            {
                function = context.FunctionLookup.GetFunctionByNameAndParameterCount(functionName, parametersCount);
                if (function == null)
                {
                    throw new PsimulexCoreException(string.Format("Call to an undefined function: {0} with {1} parameters.", functionName, parametersCount));
                }
            }
            else
            {
                function = context.FunctionLookup.GetFunctionByName(functionName);
                if (function == null)
                {
                    throw new PsimulexCoreException("Call to an undefined function: " + functionName);
                }
            }

            if (function.IsUserDefined)
            {
                UserDefinedFunction udf = function as UserDefinedFunction;

                Stack<BaseType> parameters = new Stack<BaseType>();

                foreach (var param in udf.Parameters)
                {
                    var value = context.RunStack.Pop();
                    if (param.IsReference)
                    {
                        value = value.ToReference();
                    }
                    parameters.Push(value.Clone());
                }

                parameters = parameters.Reverse();

                context.PushState();

                foreach (var param in udf.Parameters)
                {
                    context.AddVariable(param.Name, parameters[udf.Parameters.IndexOf(param)]);
                }

                // Just jump to its entry point.
                context.PC = udf.EntryPoint;
            }
            else
            {
                // Pack each parameter, and Invoke.

                Stack<BaseType> poppedValues = new Stack<BaseType>();
                var parameters = new List<BaseType>(function.ParameterCount);
                for (int i = 0; i < function.ParameterCount; ++i)
                {
                    var param = context.RunStack.Pop();
                    if (function.Parameters[i].IsReference)
                    {
                        param = param.ToReference();
                    }
                    poppedValues.Push(param.Clone());
                }

                parameters.AddRange(poppedValues.AsEnumerable());

                // Make the call
                var returnValue = context.System.SystemCall(function, parameters);

                // Push the returned value
                if (function.HasReturnValue)
                {
                    context.RunStack.Push(returnValue);
                }

                foreach (var param in parameters)
                {
                    param.Delete();
                }
            }
        }
Example #18
0
 private void InitHelpers()
 {
     lastCompiledConstantValue = null;
     lastCompiledDataType = TypeEnum.Undefined;
     lastCompiledDataTypeName = "";
     lastCompiledDimensionCount = 0;
     lastCompiledDimensionList = new List<int>();
     lastCompiledUserDefinedFunction = new UserDefinedFunction();
 }
Example #19
0
        public override void Do(ICommandContext context)
        {
            // It has to look up the availabe function names
            // IFunctionLookup

            BaseType value = context.RunStack.Pop().Dereference();

            var method = value.GetType().GetMethod(methodName,
                System.Reflection.BindingFlags.IgnoreCase |
                System.Reflection.BindingFlags.Instance |
                System.Reflection.BindingFlags.Public |
                System.Reflection.BindingFlags.IgnoreCase);

            if (method != null)
            {
                var methodParameterInfos = method.GetParameters();

                var poppedValues = new List<BaseType>(methodParameterInfos.Length);

                object returnValue = null;

                using (new Memory.AutoCleanup())
                {
                    for (int i = 0; i < methodParameterInfos.Length; ++i)
                    {
                        poppedValues.Add(context.RunStack.Pop().Clone());
                    }

                    poppedValues.Reverse();

                    object[] convertedParameters =
                        ValueFactory.TransformBaseTypeArrayToDotnetType(poppedValues, methodParameterInfos.Select(pi => pi.ParameterType).ToArray());

                    // Make the call
                    try
                    {
                        returnValue = method.Invoke(value, convertedParameters);
                    }
                    catch (Exception ex)
                    {
                        throw new Exceptions.PsimulexCoreException(string.Format("The invocation of method {0} of type {1} has thrown an exception.",
                            methodName, value.GetTypeName()), ex.InnerException);
                    }
                }

                if (returnValue is BaseType)
                {
                    Memory.Instance.Allocate(returnValue as BaseType);
                }

                // Push the returned value
                if (returnValue != null)
                {
                    context.RunStack.Push(ValueFactory.Create(returnValue));
                }
            }
            else
            {
                throw new PsimulexCoreException(string.Format("The type {0} has no such method: {1}.", value.GetTypeName(),  methodName));
            }
        }
        public override void Visit(MemberDeclarationNode node)
        {
            // MemberType
            node.MemberType.Accept(this);
            TypeEnum memberType = lastCompiledDataType;
            string memberTypeName = node.MemberTypeName.Value;

            int memberDimensionCount = lastCompiledDimensionCount;
            List<int> memberDimensionList = lastCompiledDimensionList;

            // MemberName
            string memberName = node.MemberName.Value;
            bool memberIsInitialized = false;

            // MemberInitialValue
            BaseType memberValue = null;
            if (node.MemberInitialValue != null)
            {
                if (node.MemberInitialValue.Children.Count > 1)
                {
                    AddWarning(CompilerErrorCode.NotSupported,
                        "Initializers in struct default values not supported yet! Initial value will be skipped!",
                        node.NodeValueInfo);
                }
                else
                {
                    node.MemberInitialValue.Accept(this);
                    memberValue = lastCompiledConstantValue;
                    memberIsInitialized = true;
                }
            }

            // Last compiled Member
            lastCompiledMember = new Member
            {
                Type = memberType,
                TypeName = memberTypeName,
                DimensionCount = memberDimensionCount,
                DimensionList = memberDimensionList,
                Name = memberName,
                Value = memberValue,
                IsInitialised = memberIsInitialized,
                IsReference = false
            };

            // Set back to Defaults
            lastCompiledDimensionList = new List<int>();
            lastCompiledDimensionCount = 0;
            lastCompiledDataType = TypeEnum.Undefined;
            lastCompiledDataTypeName = "";
        }
Example #21
0
 public virtual void Visit(DimensionMarkerNode node)
 {
     lastCompiledDimensionCount = node.ChildrenCount - 1;
     lastCompiledDimensionList = new List<int>();
 }
Example #22
0
 public void AddFunctions(List<UserDefinedFunction> functionList)
 {
     EnsureNotJoined();
     foreach (var func in functionList)
         AddFunction(func);
 }
        public override void Visit(FormalParameterNode node)
        {
            // Parameter Type
            node.ParameterType.Accept(this);

            TypeEnum parameterType = lastCompiledDataType;
            string parameterTypeName = lastCompiledDataTypeName;

            int parameterDimensionCount = lastCompiledDimensionCount;
            List<int> parameterDimensionList = lastCompiledDimensionList;

            // Parameter Reference
            bool parameterIsReference = false;
            if (node.ParameterReference != null)
                parameterIsReference = true;

            // Parameter Name
            string parameterName = node.ParameterName.Value;

            // Check Function Parameter existance
            if (IsFunctionParameterFounded(parameterName))
            {
                AddError(CompilerErrorCode.FormalParameterNameCollision,
                    string.Format("Function \"{0}\" has already a parameter named \"{1}\"! Parameter will be skipped!",
                    lastCompiledUserDefinedFunction.Name, parameterName), node.NodeValueInfo);
            }
            else
            {
                lastCompiledUserDefinedFunction.Parameters.Add(
                    new VariableDescriptor
                    {
                        Type = new TypeIdentifier
                        {
                            TypeEnum = parameterType,
                            TypeName = parameterTypeName,
                            Dimensions = new List<int>(parameterDimensionCount)
                        },
                        Name = parameterName,
                        IsReference = parameterIsReference,
                    });

                lastCompiledDataType = TypeEnum.Undefined;
                lastCompiledDataTypeName = "";
                lastCompiledDimensionCount = 0;
                lastCompiledDimensionList = new List<int>();
            }
        }
 private bool IsAttributeFounded(List<AttributeDescriptor> attrList, string name)
 {
     if (attrList.Find(attr => attr.Descriptor.Name == name) == null)
         return false;
     return true;
 }
Example #25
0
 public override void Assign(BaseType value)
 {
     rep = value.ToList().rep.Select(v => v.Clone()).ToList();
     OnChanged();
 }
Example #26
0
        private List<PsiFunctionsVariablesNode> GenerateFuncVarTree(List<CompilationUnit> compilationUnitList)
        {
            List<PsiFunctionsVariablesNode> list = new List<PsiFunctionsVariablesNode>();

            foreach (var item in compilationUnitList)
            {
                if (item.PsiNodeSyntaxTree != null)
                {
                    var q = new PsiFunctionsVariablesQueryVisitor(item.Source, item.FileName);
                    q.Visit(item.PsiNodeSyntaxTree as CompilationUnitNode);
                    list.AddRange(q.PsiNodeList);
                }
            }

            return list;
        }
 private void InitHelpers()
 {
     currentLocalVariableList = new List<List<VariableInfo>>();
 }