Skip to content

Commit

Permalink
Fixed formatting (#48)
Browse files Browse the repository at this point in the history
  • Loading branch information
JKRT committed Apr 15, 2020
1 parent ddd6654 commit 5669855
Show file tree
Hide file tree
Showing 16 changed files with 420 additions and 406 deletions.
15 changes: 8 additions & 7 deletions src/dangerous.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,16 @@ import ExportAll
using ..MetaModelica

""" O(1) """
function arrayGetNoBoundsChecking(arr::Array{A}, index::ModelicaInteger)::A where {A <: Any}
function arrayGetNoBoundsChecking(arr::Array{A}, index::ModelicaInteger)::A where {A<:Any}
if index < 0
println("arrayGetNoBoundsChecking: index < 0!")
end
@inbounds arr[index]
end

""" O(1) """
function arrayUpdateNoBoundsChecking(arr::Array{A}, index::ModelicaInteger, newValue::A)::Array{A} where {A <: Any}
function arrayUpdateNoBoundsChecking(arr::Array{A}, index::ModelicaInteger,
newValue::A)::Array{A} where {A<:Any}
local newArray::Array{A} = arr
if index < 0
println("arrayUpdateNoBoundsChecking: index < 0!")
Expand All @@ -31,7 +32,7 @@ access an uninitialized elements may cause segmentation faults if you're
lucky, and pretty much anything else if you're not. Do not use unless you will
immediately fill the whole array with data. The dummy variable is used to fix
the type of the array. """
function arrayCreateNoInit(size::ModelicaInteger, dummy::A)::Array{A} where {A <: Any}
function arrayCreateNoInit(size::ModelicaInteger, dummy::A)::Array{A} where {A<:Any}
local arr::Array{A} = fill(dummy, size)
arr
end
Expand All @@ -46,23 +47,23 @@ function stringGetNoBoundsChecking(str::String, index::ModelicaInteger)::Modelic
end

""" Not possible unless we write a C list impl for Julia """
function listReverseInPlace(inList::List{T})::List{T} where {T <: Any}
function listReverseInPlace(inList::List{T})::List{T} where {T<:Any}
MetaModelica.listReverse(inList)
end

""" O(1). A destructive operation changing the \"first\" part of a cons-cell. """
function listSetFirst(inConsCell #= A non-empty list =#::List{A}, inNewContent::A) where {A <: Any}
function listSetFirst(inConsCell::List{A}, inNewContent::A) where {A<:Any} #= A non-empty list =#
#= Defined in the runtime =#
end

""" O(1). A destructive operation changing the rest part of a cons-cell """
#= NOTE: Make sure you do NOT create cycles as infinite lists are not handled well in the compiler. =#
function listSetRest(inConsCell #= A non-empty list =#::List{A}, inNewRest::List{A}) where {A <: Any}
function listSetRest(inConsCell::List{A}, inNewRest::List{A}) where {A<:Any} #= A non-empty list =#
#= Defined in the runtime =#
end

""" O(n) """
function listArrayLiteral(lst::List{A})::Array{A} where {A <: Any}
function listArrayLiteral(lst::List{A})::Array{A} where {A<:Any}
local arr::Array{A}
#= Defined in the runtime =#
arr
Expand Down
3 changes: 1 addition & 2 deletions src/fixLines.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,4 @@ function replaceLineNum(a::Expr, file::String, lines::LineNumberNode)
replaceLineNum(n, file, lines)
end
end
function replaceLineNum(a::Any, file::String, lines::LineNumberNode)
end
function replaceLineNum(a::Any, file::String, lines::LineNumberNode) end
23 changes: 12 additions & 11 deletions src/functionInheritance.jl
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ function getSignatureAsArrayFor(func::Function)::Array
local signatureArray::Array = []
local nDefaultValues::Integer = size(defaultValues, 1)
local nArgumentSymbols::Integer = size(argumentSymbols, 1)
for i in 1:nArgumentSymbols
for i = 1:nArgumentSymbols
#=
If no default value is present. We add nothing instead place.
This case occurs if i is larger then the ammount of default values.
Expand All @@ -65,18 +65,18 @@ function getNewFunctionArgs(functionToExtend, func::Function)::Array{Tuple}
pair = Tuple(t.args)
@assert(size(pair, 1) >= 2, "Incorrect parameter passed to @ExtendFunction")
push!(functionToExtendArgsAsTuples, (first(pair), last(pair)))
end
end
local numberOfArguments::Integer = size(functionToExtendArgsAsTuples, 1)
#= Create arguments for the new function.
Generally the new functions have more symbols then the old =#
newArgsAsString::Array = []
for i in 1:numberOfArguments
symToFind = first(functionToExtendArgsAsTuples[i])
findFunc(x) = first(x) == symToFind
#= We will get an array with one index! Functions must have unique symbols as arguments=#
indexOfSym = first(findall(findFunc, oldFunctionSig))
oldFunctionSig[indexOfSym] = functionToExtendArgsAsTuples[i]
end
for i = 1:numberOfArguments
symToFind = first(functionToExtendArgsAsTuples[i])
findFunc(x) = first(x) == symToFind
#= We will get an array with one index! Functions must have unique symbols as arguments=#
indexOfSym = first(findall(findFunc, oldFunctionSig))
oldFunctionSig[indexOfSym] = functionToExtendArgsAsTuples[i]
end
newFuncSig = oldFunctionSig
end

Expand Down Expand Up @@ -108,7 +108,8 @@ function makeFunctionHelper(functionToExtend::Expr, __module__::Module)::Tuple
(func, newFuncArgs, argSymArr)
end

function makeExtendedFunction(nameOfNewFunc::Symbol, functionToExtend::Expr, __module__::Module)
function makeExtendedFunction(nameOfNewFunc::Symbol, functionToExtend::Expr,
__module__::Module)
(func, newFuncArgs, argSymArr) = makeFunctionHelper(functionToExtend, __module__)
quote
function $nameOfNewFunc($(newFuncArgs...))
Expand All @@ -120,7 +121,7 @@ end
#= Creates a lambda that extends an existing function =#
function makeExtendedLambdaFunction(functionToExtend::Expr, __module__::Module)
(func, newFuncArgs, argSymArr) = makeFunctionHelper(functionToExtend, __module__)
if size(newFuncArgs,1) == 0
if size(newFuncArgs, 1) == 0
:(() -> $func($(argSymArr...))) |> esc
else
quote
Expand Down
Loading

0 comments on commit 5669855

Please sign in to comment.