Beispiel #1
0
        public override void Visit(FunctionProtoAST functionProto)
        {
            var functionType = functionProto.GetFunctionType();

            var identInfo = new IdentifierInfo
            {
                name           = functionProto.Name,
                position       = _currentNodePosition,
                typeAST        = functionType,
                scopeId        = _currentScope.id,
                isFunctionType = true
            };

            var identLocation = new IdentifierLocation
            {
                identifierName = identInfo.name,
                scopeId        = identInfo.scopeId
            };

            if (_symTable.IdentInfoDictionary.ContainsKey(identLocation))
            {
                throw new Exception(string.Format("Identifier {0} already declared in file {1} line {2}",
                                                  identInfo.name, _symTable.FilePath, _currentNodePosition));
            }

            _symTable.IdentInfoDictionary.Add(identLocation, identInfo);

            if (_currentScope.id == 0)
            {
                GlobalIdentifiers.Add(functionProto.Name);
            }

            if (functionProto.Args == null)
            {
                return;
            }

            for (var i = 0; i < functionProto.Args.Count; i++)
            {
                var functionArgument = functionProto.Args[i];

                identInfo = new IdentifierInfo
                {
                    name           = functionArgument.Name,
                    typeAST        = functionArgument.Type,
                    position       = _currentNodePosition,
                    scopeId        = _scopeIdGen + 1,
                    isFunctionType = functionArgument.Type is FunctionTypeAST,
                    isFnParam      = true,
                    paramIndex     = i
                };

                AddIdentInfoToSymTable(identInfo);
            }
        }
Beispiel #2
0
        public override void Visit(FunctionProtoAST functionProto)
        {
            var functionIden = _symTableManager.LookupFunctionInfo(_currentFileName, functionProto.Name, _currentScopeId, functionProto.GetFunctionType().ArgumentTypes);

            if (functionIden.valueRef.Pointer == IntPtr.Zero)
            {
                var fnType = IRTypesConverter.GetFunctionType(functionProto.GetFunctionType());

                functionIden.valueRef = LLVM.AddFunction(_module, functionProto.Name, fnType);
            }

            _currentFunction = functionIden.valueRef;
        }